2016-11-13 29 views
1

GLSLで色のビット位置を取得する関数を作成しようとしています。GLSL ES 3.00以降でサポートされているビット単位演算子

precision highp float; 
uniform sampler2D uTexture0; 
varying vec2 vTextureCoords; 

int getBit(float color, int bit){ 
     highp int colorInt = int(color); 
     return (colorInt >> bit) & 1; 
} 

void main(void) { 
    highp vec4 texelColour = texture2D(uTexture0, vec2(vTextureCoords.s, vTextureCoords.t)); 

if(getBit(texelColour.r * 255.0, 7) == 1){ 
     gl_FragColor = vec4(0.5, 0.8, 0.5, 0.8); 
}else{ 
     gl_FragColor = vec4(0.4, 0.1, 0.0, 0.0); 
} 

}

ChromeとFirefoxはこのエラーを返す

ERROR: 0:35: '>>' : bit-wise operator supported in GLSL ES 3.00 and above only 
ERROR: 0:35: '&' : bit-wise operator supported in GLSL ES 3.00 and above only 

私はこのように、私のシェーダの1行目にバージョンを強制しようとしている:

#version 130 

ですが、コンソールはバージョンがサポートされていないことを返します。

getBit関数のサブルーチンを作成する方法はありますか? またはsharderフラグメントでbitwize演算子を実装するために有効にする設定は?

お返事ありがとうございます。

ギヨーム

答えて

0

私は自分を書面で解決策を見つけるとシフト機能してい

int getBit(float num, float b){ 
     num = num * 255.0; 
     int bit = 0; 
     for(int i = 7; i >= 0; i--){ 
      if(num >= pow(2.0,float(i))){ 
       num = num - pow(2.0,float(i)); 
       if(b == float(i)){ 
        bit = 1; 
       } 
      } 
     } 
     return bit; 
    } 


if(getBit(texelColour.r , 3.0) != 0 && getBit(texelColour.g * 255.0, 0.0) == 0 && getBit(texelColour.b * 255.0, 0.0) == 0){ 
    gl_FragColor = vec4(0.5, 0.8, 0.5, 0.8); 
}else{ 
    gl_FragColor = vec4(0.4, 0.1, 0.0, 0.0); 
} 

それは確実に改善することができますので、私はGLSLで初心者くさいんだが、それは動作します。

シモンズ:私の必要があるだけ

ギヨーム

小数点以下1つのバイトについて
関連する問題