Flip upside down vertex shader (GLES)

PerracoLabs picture PerracoLabs · Mar 25, 2012 · Viewed 13.2k times · Source

Given the next vertex shader, what is the simplest, most efficient and fastest way to flip the coordinates upside down, so the fragment shader will produce and upside down image?

attribute vec4 a_position;
attribute vec2 a_texcoord;                                                  
varying vec2 v_texcoord;

void main()
{
    v_texcoord = a_texcoord.st;
    gl_Position = a_position;
}

Answer

Tommy picture Tommy · Mar 25, 2012

Just flip v_texcoord. So e.g.

v_texcoord = a_texcoord.st * vec2(1.0, -1.0);

Or, I guess:

v_texcoord = vec2(a_texcoord.s, 1.0 - a_texcoord.t);

Depending on what exactly you want to happen to the range of .t.