# Light Falloff through a grid

I'm playing with a grid-based lighting system, where light is transported and accumulated through a grid. I initially tried attenuation based on 1/(distance*distance), but that doesn't work when the distance between each node is 1.

I tried hacks like adding an epsilon or clamping the distance, but nothing looks right. I'm sure there's something obvious I'm missing. Any guidance?

• Perhaps I'm misunderstanding what you're doing, but why does the light increase from 1 to 4 at a distance of 0.5? Shouldn't it decrease everywhere that's not the center of the light? – user1118321 Mar 2 '18 at 3:13
• It increases because I am using 1/(distance*distance) as falloff, so 1/(0.5*0.5) = 4 – Anthony Mar 3 '18 at 13:43
• Are you like... propagating your light one grid cell at a time, without knowing where it originally came from? That's a bit what it looks like but I'm uncertain I understand what you're trying to do. – Olivier Mar 4 '18 at 15:13
• Yep. Each cell stores its light output in various directions. A shader runs for each grid cell, and is responsible for taking light from neighboring cells, casting it through the current cell (reflecting it if it hits something, in this case it doesn't), and writing the result to the current cell. So I always know the position and approx direction of the light, but I don't know where it came from (because all light in a particular direction is combined) – Anthony Mar 4 '18 at 16:21

It looks to me like you're resetting the distance calculation at each grid intersection? So every time you march another grid cell you're dividing the light intensity by $gridsize^2$ ? That would explain your observed results, since dividing by $1^2$ equals no change. It won't give you the correct result though, since to get the right attenuation you need to track the total distance back to the light source and square that.
Also note that the attenuation term used in rendering is usually a bit more complicated than just $1/D^2$ - generally it's a quadratic, $1/(aD^2 + bD + c)$. While not physically correct, it's more tunable and easier to get visually pleasing results. In your case, for example, using $1/(D^2 + 1)$ would prevent the edges immediately surrounding the light from being brighter than the light itself.