Sign in to follow this  
rampster

Point light shader question

Recommended Posts

Hey guys,

I am trying to implement a simple point light shader in glsl and not sure which equation calculates the right attenuation from the below two links:

1. XNA shader programming tutorials says attenuation = 1 - dot (L/r , L/r). I like this one because of the point light radius parameter we could pass in.
2. Now Lighthouse3d tutorials (and most text books) says: attenuation = 1 / (KC + (kL * D) + (KQ * D * D)).

Now which one do you guys think gives the right attenuation? If both are right what is the relation between them?

Thanks in advance!

Share this post


Link to post
Share on other sites
Physically, lights will fall off based on the inverse of distance squared (similar to a magnetic field or a gravitational field). Of course games and other forms of computer graphics aren't usually physically-correct, and lighting attenuation is no exception. That second equation you listed is what all OpenGL/DirectX GPU's used in their fixed-function lighting pipelines, which is why you probably see it everywhere. With that it's possible to be physically-correct if you want to, or you can customize it to have a more linear or constant falloff. Falloffs like the first one you listed have become a lot more common now that people are using shaders for everything, and can therefore implement whatever attenuation function they like. Something simple that one can be nice because A) they're cheap, and B) they allow you to define a distance at which the light's influence reaches zero (which doesn't happen if you use an inverse square falloff, or the GL/DX falloff). This can be particularly important for determining which which lights affect a mesh, or for using bounding volumes for a light in a deferred renderer.

Share this post


Link to post
Share on other sites
Thanks for your Reply MJP .. that helped!
I found some explanations here : [url="http://developer.download.nvidia.com/assets/gamedev/docs/GDC2K_PerPixel_Lighting.pdf"]http://developer.dow...el_Lighting.pdf[/url] that was great as well!
I am going for the solution 1 because that meets all my needs for the application!
Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this