Friday, March 24, 2017

Does the linear attenuation component in lighting models have a physical counterpart?


In OpenGL (and other systems) the distance attenuation factor for point lights is something like 1/(c+kd+sd^2), where d is the distance from the light and c, k and s are constants.



I understand the sd^2 component which models the well known physically accurate "inverse square law" attenuation expected in reality.


I guess the constant c, usually one, is there to deal with very small values of d (and divide-by-zero defense perhaps?).


What role does the linear kd component have in the model, (by default k is zero in OpenGL). When would you use other values for k? I know that this is called the "linear attenuation" component, but what behavior does it simulate in the lighting model? It doesn't seem appear in any physical model of light that I'm aware of.


[EDIT]


It has been pointed out by David Gouveia that the linear factor might be used to help make the scene 'look' closer to what the developer/artist intended, or to better control the rate at which the light falls off. In which case my question becomes "does the linear attenuation factor have a physics counterpart or is it just used as a fudge factor to help control the quality of light in the scene?"



Answer



Light, from point-like sources, falls of with the square of the distance. That's physical reality.


Linear attenuation is often stated to appear superior. But this is only true when working in a non-linear colorspace. That is, if you don't have proper gamma correction active. The reason is quite simple.


If you're writing linear RGB values to a non-linear display without gamma correction, then your linear values will be mangled by the monitor's built-in gamma ramp. This effectively darkens the scene compared to what you actually intended.


Assuming a gamma of 2.2, your monitor will effectively raise all of the colors to the power of 2.2 when displaying them.



This is linear attenuation: 1/kd. This is linear attenuation with the monitor's gamma ramp applied: 1/(kd)^2.2. That's pretty close to a proper inverse-squared relationship.


But the actual inverse squared: 1/sd^2 becomes: 1/((s^2)(d^4.4)). This makes the light attenuation fall off much more sharply than expected.


In general, if you're using proper gamma correction (like rendering to an sRGB framebuffer), you shouldn't use linear attenuation. It won't look right. At all. And if you're not using gamma correction... what's wrong with you ;)


In any case, if you're trying to mimic reality, you want inverse-squared (and gamma correct). If you're not, then you can do whatever you need to for your scene.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...