2
votes

I am trying to convert some opengl glsl to opengl es (2.0) glsl. I am passing a byte value into the fragment shader by casting it to a float in my code and then casting it back in the shader. I then need to split the result into two values between 0-15. For opengl glsl I am using

int x = int(a_otherdata);
int a = (x >> 4) & 0xF;
int b = x & 0xF;

However, I since opengl es does not support bitwise operations I tried doing the following, but it doesn't work.

int x = int(a_otherdata);
int a = x / 16;
int b = x - (a * 16);
1

1 Answers

5
votes

The problem is that in OpenGL ES 2.0 GLSL, ints might not actually be integers; they might be implemented as floats -- the only guarantee you have is the range of integer values that can be held, based on the precision. So the divide might be a float divide, which means you need to stick a floor call in there if you want to round it down:

int a = int(floor(a_otherdata / 16));
int b = int(mod(a_otherdata, 16));