Luple
Luple

Reputation: 491

gles glsl bit wise operations problems

I am trying to create a shader that uses bitwise commands for a mobile application. I am using glsl version 320 es. To demonstrate the problem I have created a shadertoy example: https://www.shadertoy.com/view/MsVyRw Which should show a red screen. The screen appears red when opened from my galaxy s8 as well. When running my application with the following fragment shader:

#version 320 es
precision highp float;
out vec4 fragColor;
void main()
{
    uint x = uint(0xec140e57);
    uint tmp0 = x >> uint(4);
    uint tmp1 = uint(0xec140e57) >> uint(4);
    if(tmp0 == tmp1){
        fragColor = vec4(1.0, 0.0, 0.0,1.0);
    }
    else{
        fragColor = vec4(0.0, 0.0, 1.0,1.0);
    }
};

The screen appears blue. However if I change

uint x = uint(0xec140e57);
uint tmp0 = x >> uint(4);
uint tmp1 = uint(0xec140e57) >> uint(4);

to

uint tmp0 = uint(0xec140e57) >> uint(4);
uint tmp1 = uint(0xec140e57) >> uint(4);

the screen appears red.

It is definitely not a problem with the gpu ALUs since it works with shadertoy. Is there something that I am missing with the preprocessor flags that would allow this sort of operation?

Upvotes: 1

Views: 2781

Answers (1)

solidpixel
solidpixel

Reputation: 12069

Fragment shaders have a default int precision of mediump, so I suspect you have precision problems (literals at 32-bit precision, and variables at 16-bit precision). See Shader Language Spec section 4.7.4.

Try adding precision highp int; to the start of the shader along with the other default precision statements.

Upvotes: 1

Related Questions