Firefox 仅GLSL ES 3.00及以上版本支持位运算符
我正在尝试创建一个函数,该函数在GLSL中为一种颜色获得一点位置Firefox 仅GLSL ES 3.00及以上版本支持位运算符,firefox,glsl,bitwise-operators,Firefox,Glsl,Bitwise Operators,我正在尝试创建一个函数,该函数在GLSL中为一种颜色获得一点位置 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 m
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运算符启用哪些设置
谢谢你的回复
纪尧姆我在编写自己的和移位函数时找到了一个解决方案
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的新手,所以它肯定会更好,但它很有效
Ps:我只需要1字节十进制
纪尧姆我在编写自己的和移位函数时找到了一个解决方案
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的新手,所以它肯定会更好,但它很有效
Ps:我只需要1字节十进制
Guillaume我认为您需要声明您正在着色器顶部使用es3:
#300版es
这还需要您更改着色器其余部分的语法(不再是
变化
,而是输入
和输出
,等等)。我想您需要声明您正在着色器顶部使用es3:
#300版es
这还需要更改着色器其余部分的语法(不再是变化
,而是输入
和输出
,等等)