2014-12-05 79 views
1

我试图检查纹理中给定的像素是白色,黑色还是两者都不是。我决定使用equal function described in the OpenGL 4 Reference Pages。我相信我只是有一个问题得到正确的语法。GLSL分量平等比较

我使用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'返回一个布尔向量(这就是'bvec'代表的),但你想要一个布尔值。所以只需使用if(textureColor3 == whiteColor)'。 – 2014-12-05 18:17:45

回答

4

bvecequal函数的返回类型。你得到一个布尔值的矢量来告诉你哪些组件​​是平等的。如果您只想比较整个颜色,请使用等号运算符==