Question

This is a strange problem. If I try to pass a uniform color to the fragment shader, i get a compile error

uniform vec4 uniformColor;

void main(){
   gl_FragColor = uniformColor;
}

But if I pass the same uniform color to the vertex shader then pass it to the fragment shader via a varying, then it works fine..

    attribute vec4 position;
    uniform mat4 matrix;
    uniform vec4 uniformColor;
    varying vec4 fragmentColor; 
    void main()
    {
        gl_Position = matrix * position;
        fragmentColor = uniformColor;
    }

and

varying lowp vec4 fragmentColor;
void main()
{
  gl_FragColor = fragmentColor;
}

this is on an iOS.

I'm a little confused as copying and pasting examples from online gives me errors.

No correct solution

OTHER TIPS

There is no default float precision qualifier for fragment shaders in OpenGL ES. A precision qualifier is required to use any floating pointer variable - it doesn't matter if it's a uniform, varying, or just a local variable. There is a default precision for vertex shaders, so you don't need to add any qualifiers there.

In OpenGL the precision qualifier is not required, which is why the example you're pointing to does not include them.

Try adding this to the top of your shader and you should be fine:

precision mediump float;

I had the same issue and it was indeed related to the missing precision, but the issue is that if a uniform is shared between the vertex and fragment shaders, it must be of the same precision (at least in ES 2.0). This makes sense I suppose, because they are shared between the shaders.

And since the default precision for vertex shaders is highp, the precision for this uniform in the fragment shader needs to be highp too, as in:

precision mediump float;
uniform highp vec4 uniformColor;

Alternatively you can change the precision to mediump in the vertex shader.

The error message was very informative, when I finally noticed it: Symbol uEcLightPos defined with different precision in vertex and fragment shaders.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top