Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: gl_FragCoords.y  (Read 1793 times)

0 Members and 1 Guest are viewing this topic.

ka0s420

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Email
gl_FragCoords.y
« on: March 15, 2016, 06:45:04 pm »
hello, I'm writing a simple fragment shader that multiplies the rgba of a fragment based on it's distance from my mouse position.

varying vec4 vColor;
varying vec2 vTexCoord;

uniform sampler2D uTexture;
uniform vec2 uLightPosition;


void main(){
       
        float  pixelDistFromLight = distance(uLightPosition, vec2(gl_FragCoord.x,  gl_FragCoord.y));
        vec4 modColor = vec4(vColor.r + -pixelDistFromLight/100.0, vColor.g + -pixelDistFromLight/100.0,
        vColor.b + -pixelDistFromLight/100.0, vColor.a );
        gl_FragColor = texture2D(uTexture, vTexCoord) * modColor ;
}
 

the 'light' follows the mouse from left to right, but it's movement is inverted on the y axis. I understand that this is because glsl uses the bottom left as it's origin, and have tried to invert it in various ways including  1.0 - gl_FragCoord.y, and although that makes the light move in the righ direction, the light is still not situated at the mouse positions. i.e it moves up when i move the mouse up, but is positioned at the bottom of the screen.

any idea what operation i could perform on gl_FragCoord.y to get it to match the y coordinate of my mouse?

thanks for your time.

ka0s420

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Email
Re: gl_FragCoords.y
« Reply #1 on: March 15, 2016, 08:06:50 pm »
Okay got it working. I inverted the mouses y position before sending it to the shader, and everything is all working now.

worldPos.y = mWindow.getSize().y - worldPos.y;
 

solved.