# Light Attenuation

Inverse square law (0)

Inverse square law: the arrows represent the flux emanating from the source. The density of arrow per unit area (green square, density flux), is decreasing with squared distance.

$$Intensity = \frac{1}{{distance}^2}$$

The apparent intensity of the light from the source of constant luminosity decreases with the square of the distance from the object.

The main problem of this physically correct attenuation is:

• It takes forever to reach 0. Need to cull it somehow, in Unity this type gets culled at 1/256.
• We need a lot of time LARGE lights, (x < 1 above)
• In deffered lightning a lot of pixels getting processed for very little gain

Some variants with two good for us, RED and GREEN. PURPLE color curve have a huge falloff.

One approach to solve this is to window the falloff in such a way that most of the function is unaffected (1). For this we will use a basic linear interpolation to zero based on distance criteria (2). I use also photometric terms (PBR!!):

$$E= lerp(\frac{I}{{distance^2}}, 0, \frac{distance}{lightRadius})=(\frac{I}{distance^2})(1 – \frac{distance}{lightRadius})$$

go to

$$E_{v1}= (\frac{I}{distance^2})saturate(1 – (\frac{x^n}{lightRadius}))^2 – Frostbite 3$$

• n – tweak the transition smoothness (Frostbite = 4.0) from (1)

$$E_{v2}= \frac{saturate(1 – (distance/lightRadius)^4)^2}{distance^2 + 1} – Unreal 4$$

In real life there is no lightRadius but in games we may use it to prevent ingress of a large number of objects in the scene in the range of light (of course and their calculation) by reducing the radius.

The second one have the most acceptable variant with inverse square falloff we achieve more natural results, the first one is old style falloff.

Near light behaves more naturally, but still strong light on the side walls of the corridor, and now see the down variant.