PDA

View Full Version : Some things about the standard lighting system.



Sanctus
03-07-2010, 03:35 AM
Hey guys.
Right now I'm trying to implement a forward renderer in my engine (the other being deferred).
Since I've pretty much always worked with shaders and lighting systems done by me I'm not very good at standard lights.

First of all I'm not sure how to set up the attenuation.
I put the constant attenuation to 0 and the linear one to 1/lightRange. This seems to be okay but if my object is very close to the light the backfacing triangles still seem to get iluminated and I see no difference between one face and another.
This has nothing to do with normals since if the light is further away or the range is smaller it shows up correctly (at least I think correctly).
Do you think my implementation of the attenuation is good?

Rosario Leonardi
03-07-2010, 05:55 PM
attenuation work like this

attenuationFactor=1/(GL_CONSTANT_ATTENUATION+GL_LINEAR_ATTENUATION*d+G L_QUADRATIC_ATTENUATION*dē)
So, if constantAttenuation is 0 and linear is 1/lightRange you get attenuationFactor = (lightRange)/d that is always bigger than 1 for d < lightRange and go to infinity for d = 0
I think you want the maximum light for d=0 and attenuation=smallNumber for d = lightRange.
GL_LINEAR_ATTENUATION=(1/smallNumber-1)/lightRange
or you can use also the quadratic factor for a more realistic behaviour.

Dark Photon
03-07-2010, 06:01 PM
Sorry, Sanctus. There's just nothing to grab onto here.

The OpenGL Red Book contains the exact formulas for point light source falloff with distance (and angle), so you can check your shader code against that.

Further, the fixed-function pipeline in your OpenGL implementation has this implemented by default, so you can just flip over and use that to verify that your results match the FFP.

Also, 3DLabs ShaderGen (available on the Orange Book web site) contain the exact shader code for implementing falloff.

And this is not an Advanced question. Better asked in the GLSL or Beginners forums next time.