Jump to content
  • Advertisement
Sign in to follow this  
Tsumuji

GLSL: Get position of current pixel?

This topic is 4440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

There's a way to get the current pixel location in a GLSL shader? I'm needing this to calculate my point light...

Share this post


Link to post
Share on other sites
Advertisement
http://www.lighthouse3d.com/opengl/glsl/index.php?lights

Here is a tutorial on GLSL. There is plenty info on lights of different types

Share this post


Link to post
Share on other sites
I saw this one. But I'm needing this for a globe of light. I'm trying to calculate a point light in that way. So I'm sure that I need to calculate the current pixel location, like is done in the vertex shader with gl_Vertex...

Share this post


Link to post
Share on other sites
Put non-transformed vertex location as return argument of your vertex shader. That way you`ll get location in pixel shader for every pixel.

Share this post


Link to post
Share on other sites
Here is a link to the lighthouse3d again, but now about per pixel lightning.

http://www.lighthouse3d.com/opengl/glsl/index.php?dirlightpix

All in all i don'T uderstand your problem at all. But this seems the most possible solution for you.

Share this post


Link to post
Share on other sites
For point lights, the standard approach is the compute the distance from the light per-vertex, then pass it on to the PS, letting it get interpolated along the way.

You can do more or less the same thing with the entire position rather than just a radial distance, but computing the distance per pixel is a complete waste of time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Also keep in mind that for big traingles the difference will be noticeable because distance doesn't vary linearly, and you should really be computing the distance per pixel.But for most well tessellated model it should be fine.

Share this post


Link to post
Share on other sites
So I'm trying to do somthing like this:

void main()
{
vec4 Idiff;
if ( distance(gl_FragCoord, gl_LightSource[0].position) < 300.0 )
Idiff = vec4(1.0, 1.0, 0.0, 1.0);
else
Idiff = vec4(0.0, 0.0, 1.0, 1.0);

vec4 pixelFinalColor = Idiff;
gl_FragColor = pixelFinalColor;
}


Result: [ http://geocities.yahoo.com.br/megaspeedlinux/und/screens/sp9.jpg ]
-Not worried about ambient and specular for now. Just trying to get things to work.
And this is. Just trying to calculate the actual distance from the current pixel and the light position. If minor than 300.0(this must br fixed to 3.0, since this calculation is getting the distance in pixels...) the area is "lighted", if not, take the other color. Is possible?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!