Here is my fragment shader program which runs on iOS 5.1.1 on iPhone 3g.
#ifdef GL_ES
precision lowp float;
#endif
varying vec2 v_texCoord;
void main()
{
float offset = sin(v_texCoord.x * 10.0);
// offset = offset * 1.0; // (!!!)
gl_FragColor = vec4(offset, 0.0, 0.0, 1.0);
}
Which produces nice sin:
Note the line marked by (!!!). I suppose, multiplying float value by 1.0 must change nothing. (The same shader being run under Windows OS works exactly as expected.) So, I uncomment the line and receive this:
WTF?!
How to reproduce:
- Create iOS Game project from standard template in xcode. If you run the project then you will see two floating cubes. One red and one blue.
Change contents of Shader.vsh to the following. (I've just added one varying parameter v_pos).
attribute vec4 position; attribute vec3 normal; varying lowp vec4 colorVarying; varying lowp vec4 v_pos; uniform mat4 modelViewProjectionMatrix; uniform mat3 normalMatrix; void main() { vec3 eyeNormal = normalize(normalMatrix * normal); vec3 lightPosition = vec3(0.0, 0.0, 1.0); vec4 diffuseColor = vec4(0.4, 0.4, 1.0, 1.0); float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition))); colorVarying = diffuseColor * nDotVP; gl_Position = modelViewProjectionMatrix * position; v_pos = gl_Position; }
Chnge Shader.fsh to the following.
varying lowp vec4 colorVarying; varying lowp vec4 v_pos; void main() { gl_FragColor = colorVarying; lowp float a = sin(v_pos.x * 10.0); // a = a * 1.0; // (!!!) gl_FragColor = vec4(a, 0.0, 0.0, 1.0); }
Run program on a device and see cool bars on blue cube:
Uncomment the line (
a = a * 1.0;
) marked by (!!!) and run again: