Skip to main content
Light Attenuation Shortcut        

Table of contents

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 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:

Copy to clipboard
void setLightRange( Ogre::Light *L, Ogre::Real Range ) { L->setAttenuation( Range, 1.0f, 4.5/Range, 75.0f/(Range*Range) ); }


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