2014-12-05 84 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函數的返回類型。你得到一個布爾值的矢量來告訴你哪些組件​​是平等的。如果您只想比較整個顏色,請使用等號運算符==