Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip upside down vertex shader (GLES)

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;
}
like image 375
PerracoLabs Avatar asked Mar 25 '12 01:03

PerracoLabs


1 Answers

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.

like image 119
Tommy Avatar answered Nov 09 '22 00:11

Tommy