我有一个 vec2
包含 x 和 y 坐标。我需要确保它们都大于 16。我的第一次尝试:
if (gl_FragCoord.xy > 16.0) {
// do something..
}
它无法编译并出现“没有匹配的操作数”错误。
如果我分别比较向量的每个维度,它就会起作用。
if ((gl_FragCoord.x > 16.0) && (gl_FragCoord.y > 16.0))
// do something..
}
有没有更好的方法一次检查向量的所有元素?
最佳答案
有一个 function for component-wise comparison产生一个 bool 向量,然后 another one to check components of a boolean vector :
if (all(greaterThan(gl_FragColor.xy, vec2(16.0))) {
/* ... */
}
关于opengl - 确保所有矢量分量都大于某个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47035457/