# Shaders, when to flip why and y?

For developers using the Construct 2 Javascript SDK

### » Sun May 01, 2016 4:59 pm

Hello,

I am curious, I am blundering around writing shaders and currently I do silly things and I don't know why.

Sometimes I have to flip a texture coordinate: texpos.y = 1.0 - texpos.y;

I haven't figured out why I need to sometimes, all I know is that the effect is upside down and I am fixing it. I thought 0,0 is top left and 1.1 is bottom right as far as tex coordinates go?
B
34
S
12
G
2
Posts: 566
Reputation: 5,282

### » Mon Jul 25, 2016 8:06 am

Actually, top left is (0,1) and bottom right is (1,0) - you can check it by visualizing the UV coords - something like:

output = vec4(vTex.x,vTex.y, 0.,1.);

I was confused about that as well - most sources say (0,0) and (1,1).
B
8
S
2
G
2
Posts: 86
Reputation: 1,220

### » Mon Jul 25, 2016 2:55 pm

here is a little circle code ;

Code: Select all
`void main(){          vec2 uv = vTex;    uv.y =1.-uv.y;     // flip uv screen ;        vec2 cpos=vec2(0.0,0.0); /// position of our circle        float distance = distance(cpos, uv);        if (distance > 0.05)      gl_FragColor = vec4(0, 0, 0, 1.0);    else        gl_FragColor = vec4(1, 1, 1, 1.0);        }`

The position of vectors change depending of the screen if it's flipped or not;
if you comment : uv.y =1.-uv.y; the bottom left is (0,0) if not flipped
the top left is (0,0).. try to change the position of circle : vec2 cpos = vec2(0.2,0.2) ... etc
when flip is used it's not flip texture but it's flip the screen , and the reason of inversed vectors are here .

Hope this help
B
72
S
25
G
29
Posts: 844
Reputation: 22,976