Skip to main content

History: Light Attenuation Shortcut

Source of version: 1 (current)

Copy to clipboard
            {maketoc}

!!Description
This is a basic shortcut for calculating light attenuation based on the specified range. The attenuation is calculated so that you will have full light at 0% of the range which will diminish into nothing at 100% of the range.

For more information, read this great tutorial on [http://www.ogre3d.org/tikiwiki/tiki-index.php?page=-Point+Light+Attenuation|Point Light Attenuation].

!!Code
Using the logic based on the calculations made on the wiki page linked above:

^ __''Range   Constant   Linear     Quadratic''__
 3250,     1.0,     0.0014,    0.000007
 600,      1.0,     0.007,     0.0002
 325,      1.0,     0.014,     0.0007
 200,      1.0,     0.022,     0.0019
 160,      1.0,     0.027,     0.0028
 100,      1.0,     0.045,     0.0075
 65,       1.0,     0.07,      0.017
 50,       1.0,     0.09,      0.032
 32,       1.0,     0.14,      0.07
 20,       1.0,     0.22,      0.20
 13,       1.0,     0.35,      0.44
 7,        1.0,     0.7,       1.8
^

You can determine the linear and quadratic values (or what is visually close enough) for any range you wish to use:
* Linear = 4.5 / LightRange
* Quadratic = 75.0 / LightRange^2

Here is a function to calculate attenuation based on the Light Range:

{CODE(wrap="1", colors="c++")}void setLightRange( Ogre::Light *L, Ogre::Real Range )
{
	L->setAttenuation( Range, 1.0f, 4.5/Range, 75.0f/(Range*Range) );
}{CODE}

Note: Like in the page mentioned above, you won't get visual light much further than 20% of the specified range.