GLSL分量相等比较

5
我正在尝试检查纹理中给定像素点的颜色是否为白色、黑色或者其他。我决定使用OpenGL 4参考手册中描述的equal函数。我认为我只是在语法上遇到了问题。
我正在使用的是OpenGL版本4.0.0和OpenGL着色语言版本4.00。
以下是我的片段着色器代码的相关部分:
   //texture 1
   vec4 textureColor1 = texture(texUnit1, textureCoord);
   //texture 2
   vec4 textureColor2 = texture(texUnit2, textureCoord);
   //texture 3 (only contains black and white pixels)
   vec4 textureColor3 = texture(texUnit3, textureCoord);

   vec4 finalTextureColor;

   vec4 whiteColor = vec4(1.0, 1.0, 1.0, 0.0); //define white
   vec4 blackColor = vec4(0.0, 0.0, 0.0, 0.0); //define black

   if (bvec equal(textureColor3, whiteColor)){ //if texture 3 pixel is white
        finalTextureColor = textureColor1;
   } else if (bvec equal(textureColor3, blackColor)){  //if texture 3 pixel is black
        finalTextureColor = textureColor2;
   } else { //not black or white
        finalTextureColor = mix(textureColor1, textureColor2, 0.5);
   }

   color = finalTextureColor;

这里是我收到的错误信息:

ERROR: 0:101: 'bvec' : undeclared identifier
ERROR: 0:101: 'equal' : syntax error syntax error

我知道我的纹理数据已经正确传递到片段着色器,因为我可以使用color = textureColor1color = textureColor2color = textureColor3 来显示3D对象上对应的纹理。

感谢您的帮助!


2
我认为你不需要使用逐个元素的“equal”。equal返回一个布尔向量(bvec表示),但你只需要一个单一的布尔值。所以只需使用if(textureColor3 == whiteColor) - Nico Schertler
1个回答

5
equal函数的返回类型。你会得到一个布尔向量,告诉你哪些分量是相等的。如果你只想比较整个颜色,则使用等式运算符==

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接