我正在尝试将一些 opengl glsl 转换为 opengl es (2.0) glsl。我将一个字节值传递到片段着色器中,方法是将其转换为代码中的 float ,然后将其转换回着色器中。然后我需要将结果拆分为 0-15 之间的两个值。对于 opengl glsl 我正在使用
int x = int(a_otherdata);
int a = (x >> 4) & 0xF;
int b = x & 0xF;
但是,由于opengl es不支持按位运算,我尝试执行以下操作,但它不起作用。
int x = int(a_otherdata);
int a = x / 16;
int b = x - (a * 16);
最佳答案
问题在于,在 OpenGL ES 2.0 GLSL 中,int
实际上可能不是整数;它们可能被实现为 float ——唯一的保证是可以根据精度保存的整数值的范围。因此,除法可能是 float 除法,这意味着如果您想将其向下舍入,则需要在其中插入 floor
调用:
int a = int(floor(a_otherdata / 16));
int b = int(mod(a_otherdata, 16));
关于opengl-es - Opengl es glsl 按位运算等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36575457/