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
我试图迫使版本在我的着色器的第一线,像这样:
#version 130
但控制台返回版本不受支持。
有没有办法为getBit函数创建子例程? 或者什么设置启用在sharder片段中实现bitwize运算符?
感谢您的回复。
纪尧姆