GLSL: Get position of current pixel?
There's a way to get the current pixel location in a GLSL shader? I'm needing this to calculate my point light...
http://www.lighthouse3d.com/opengl/glsl/index.php?lights
Here is a tutorial on GLSL. There is plenty info on lights of different types
Here is a tutorial on GLSL. There is plenty info on lights of different types
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...
Put non-transformed vertex location as return argument of your vertex shader. That way you`ll get location in pixel shader for every pixel.
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.
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.
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.
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.
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.
So I'm trying to do somthing like this:
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement