Shaders, when to flip why and y?

0 favourites
  • 3 posts
From the Asset Store
Goodbye to sprite fonts, when you have something new on the anvil for your upcoming Games !
  • 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?

  • 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).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would like to help you a bit;

    here is a little circle code ;

    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);
            
    }
    [/code:1psl8odz]
    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
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)