I am loading a texture in a WebGL fragment shader (GLSL version 1.00).
This is my working code:
precision highp float;
uniform sampler2D u_texture;
varying float v_coord;
void main(void) {
float inv_coord;
gl_FragColor = texture2D(u_texture, vec2(v_coord, 0.5));
}
v_coord
holds the texture coordinates for each vertex. What I'm trying now, is to invert the texture coordinates. I thought about something like abs(v_coord - 1)
. However, whenever I try to substract - 1
from v_coord
, my shader fails to compile.
precision highp float;
uniform sampler2D u_texture;
varying float v_coord;
void main(void) {
float inv_coord = v_coord - 1; // fails here
inv_coord = abs(inv_coord);
gl_FragColor = texture2D(u_texture, vec2(inv_coord, 0.5));
}
Why does substracting minus one in fragment shader fail for a float data type? How to invert the texture coordinate value correctly?
shaderInfoLog
and/or theprogramInfoLog
after attempting the compile and link. $\endgroup$