Point Light Distance Attenuation
This is the commonly used formula to attenuate light by a constant, linear and quadric factor.
1 / (constantFactor + (linearFactor * disFactor) + (quadricFactor * disFactor * disFactor));
personally I dislike this formula as it is very difficult to isolate light to a particular area only.
Spherical Light Attenuation
This is something I use more frequently.
saturate(1.0 – smoothstep(lightAttMinRange, lightMaxRange, lightDis));
This will only start attenuate at a specific distance and will have a smooth fall off to the lightMaxRange. It really make lights placement in room simpler.
Spot Light Attenuation
float spot = dot(spotlightDir, lightDir);
float outerAngleFactor = cos(outerAngleFactor / 2);
float innerAngleFactor = cos(innerAngleFactor / 2);
float attenuation = (spot >= outerAngleFactor) * pow((spot – outerAngleFactor) / (innerAngleFactor – outerAngleFactor), falloff);
if you are using ogre, outerAngleFactor and attenuation is calculated for you. if you are using lightVec from NdotL, do remember to inverse the direction.