vaw*_*165 2 bit-manipulation opengl-es glsl glsles
我正在尝试将一些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;
Run Code Online (Sandbox Code Playgroud)
但是,由于opengl es不支持按位操作,因此我尝试执行以下操作,但是它不起作用。
int x = int(a_otherdata);
int a = x / 16;
int b = x - (a * 16);
Run Code Online (Sandbox Code Playgroud)
问题在于,在OpenGL ES 2.0 GLSL中,ints可能实际上不是整数。它们可能实现为浮点数-唯一的保证就是根据精度可以保留的整数值范围。因此,该分频可能是浮动分频,这意味着floor如果要四舍五入,则需要在其中保留呼叫:
int a = int(floor(a_otherdata / 16));
int b = int(mod(a_otherdata, 16));
Run Code Online (Sandbox Code Playgroud)