I modified light sources to have a range instead of a falloff. Previously I calculated the attenuation of light with the formula

Where d is the distance to the surface and I is the light intensity. This formula has a quadratic falloff of light just as in the real world however this formula never reaches zero so it is almost impossible to determine when an object is not lit by a light. The first thing I tried was to calculate a range based on the above formula and a predefined value that determines when the amount of light is no longer noticeable. The problem is that the light formula converges very slowly to zero
so either the range got very large or the light cuttoff value got larger. To combat this problem I devised another attenuation formula based on the range of the light itself instead of a falloff and came up with this:

Where R is the light range. The HLSH code also makes sure it is saturated. It looks very good but could definitely be optimized more, for now however I will just use this code. Before I can really use this though I need to clean the octree code because there are some bugs with dynamic lights.











