Opengl GLSL分量相等比较

Opengl GLSL分量相等比较,opengl,vector,comparison,glsl,equals,Opengl,Vector,Comparison,Glsl,Equals,我试图检查纹理中的给定像素是白色、黑色还是两者都不是。我已经决定用这个。我想我只是在语法正确方面遇到了问题 我使用的是OpenGL版本4.0.0和OpenGL着色语言版本4.00 以下是我的片段着色器代码的相关部分: //texture 1 vec4 textureColor1 = texture(texUnit1, textureCoord); //texture 2 vec4 textureColor2 = texture(texUnit2, textureCoord

我试图检查纹理中的给定像素是白色、黑色还是两者都不是。我已经决定用这个。我想我只是在语法正确方面遇到了问题

我使用的是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=textureColor1
color=textureColor2
color=textureColor3
,所有这些都在3D对象上显示适当的纹理


谢谢你的帮助

bvec
equal
函数的返回类型。你得到一个布尔向量来告诉你哪些分量相等。如果您只想比较整个颜色,那么请使用相等运算符
=

我认为您不需要组件方面的
相等
equal
返回一个布尔向量(这就是
bvec
的意思),但您需要一个布尔向量。所以只要使用
if(textureColor3==whiteColor)