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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With