12

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;
}
Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
PerracoLabs
  • 12,362
  • 12
  • 57
  • 107
  • The vertex position coordinates or the texture coordinates? Also, wouldn't it make more sense to put this into the transform you use for those positions (assuming that you intend to do some transformation). – Nicol Bolas Mar 25 '12 at 01:38

1 Answers1

22

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.

Tommy
  • 97,164
  • 12
  • 174
  • 193