<p>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 <em>total distance</em> back to the light source and square that. </p>

<p>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.</p>

CC BY-SA 3.0
2018-03-03T05:21:11.770Z
At the first boundary, wouldn't D^2 + 1 be 1.25?
user1118321
CC BY-SA 3.0
2018-03-03T09:26:29.957Z
Yeah, so you'd have an intensity of 0.8
russ
CC BY-SA 3.0
2018-03-03T14:06:30.700Z
"to get the right attenuation you need to track the total distance back to the light source and square that"  

Why is that? What is the difference between a light source with intensity 1 at distance 2 and a light source with intensity 0.25 at distance 1?  

The +1 constant does get more reasonable results, but it still doesn't seem physically correct.  

I'll look at tracking individual rays/distances, but I was hoping to aggregate light at each point in the grid, so I don't "know" the original distance.
Anthony
CC BY-SA 3.0
2018-03-03T14:28:53.433Z
Because the distance to the original light is what matters for intensity. The ratios of the squares change as you move away from the light. Let's say you have a grid size of 2 - when moving from distance 2 to distance 4, the light should get 4x dimmer, but when moving from distance 10 to 12 it will only get 1.44x dimmer.
russ
CC BY-SA 3.0
2018-03-02T06:03:51.793Z
2018-03-03T16:43:57.903Z
2018-03-03T16:43:57.903Z
russ
<p>I'm playing with a grid-based lighting system, where light is transported and accumulated through a grid. I initially tried attenuation based on <code>1/(distance*distance)</code>, but that doesn't work when the distance between each node is 1.</p>

<p><a href="https://i.sstatic.net/pzbdi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pzbdi.png" alt="Here&#39;s a picture"></a></p>

<p>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?</p>

CC BY-SA 3.0
2018-03-02T03:13:31.550Z
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
CC BY-SA 3.0
2018-03-03T13:43:15.103Z
It increases because I am using 1/(distance*distance) as falloff, so 1/(0.5*0.5) = 4
Anthony
CC BY-SA 3.0
2018-03-04T15:13:23.077Z
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
CC BY-SA 3.0
2018-03-04T16:21:09.353Z
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
<raytracing><lighting><pathtracing><global-illumination><grid>
Light Falloff through a grid
Anthony
# Light Falloff through a grid

(Asked by: username_0 on 2018-03-01)

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.

[![Here's a picture](https://i.sstatic.net/pzbdi.png)](https://i.sstatic.net/pzbdi.png)

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?

**Tags:** raytracing, lighting, pathtracing, global-illumination, grid

> **Comments:**
> **username_1**: 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?  
> **username_0**: It increases because I am using 1/(distance*distance) as falloff, so 1/(0.5*0.5) = 4  
> **username_2**: 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.  
> **username_0**: 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)  

---

## 1 answers

### Answer by username_3 on 2018-03-02. Score: 1

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.

> **Comments:**
> **username_1**: At the first boundary, wouldn't D^2 + 1 be 1.25?  
> **username_3**: Yeah, so you'd have an intensity of 0.8  
> **username_0**: "to get the right attenuation you need to track the total distance back to the light source and square that"    Why is that? What is the difference between a light source with intensity 1 at distance 2 and a light source with intensity 0.25 at distance 1?    The +1 constant does get more reasonable results, but it still doesn't seem physically correct.    I'll look at tracking individual rays/distances, but I was hoping to aggregate light at each point in the grid, so I don't "know" the original distance.  
> **username_3**: Because the distance to the original light is what matters for intensity. The ratios of the squares change as you move away from the light. Let's say you have a grid size of 2 - when moving from distance 2 to distance 4, the light should get 4x dimmer, but when moving from distance 10 to 12 it will only get 1.44x dimmer.  

---

