I am using LibGDX and have a simple fragment shader:
#ifdef GL_ES
#define mediump lowp
precision mediump float;
#else
#define lowp
#endif
uniform sampler2D u_texture;
uniform vec2 iResolution;
uniform float iGlobalTime;
uniform float glow;
void main(void)
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
//uv.y = 1-uv.y; // THIS LINE EVOKES AN ERROR!!!
uv.y += (sin((uv.x + (iGlobalTime * 0.2)) * 10.0) * 0.02)+0.02;
vec4 color = vec4(glow,glow,glow,1);
vec4 texColor = texture2D(u_texture, uv)*color;
gl_FragColor = texColor;
}
It works well on PC, but on Android device this shader is not compiled. If I comment the line(commented one in the example), everything goes ok.
How I use it:
mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0));
mesh.setVertices(new float[]
{0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 1,
0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1,
-0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 0,
-0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0});
mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0});
this.texture = texture;
shader = new ShaderProgram(Gdx.files.internal("shaders/default.vertex"),
Gdx.files.internal("shaders/glowwave.fragment"));
Render method:
texture.bind();
shader.begin();
shader.setUniformMatrix("u_worldView", localCam.projection);
shader.setUniformi("u_texture", 0);
shader.setUniformf("iGlobalTime", time);
shader.setUniformf("iResolution", new Vector2(Gdx.graphics.getWidth(),Gdx.graphics.getHeight()+15));
shader.setUniformf("glow", glow);
mesh.render(shader, GL20.GL_TRIANGLES);
shader.end();
What the reason can it be? Seems to me the problem is in preprocessor, although I could be wrong.