Shaders, when to flip why and y?

For developers using the Construct 2 Javascript SDK

Post » 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?
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » 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: 85
Reputation: 1,218

Post » Mon Jul 25, 2016 2:55 pm

I would like to help you a bit;

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
http://gigatron3k.free.fr/Intro/

https://www.shadertoy.com/user/gigatron

https://twitter.com/realistquantum

Ezekiel 1-4 ; ufo landing explanation ..

CONSTRUCT 2 THE ONLY FAST WAY TO HTML5

Image
B
57
S
20
G
29
Posts: 804
Reputation: 21,969


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 2 guests