Jump to content

  • Log In with Google      Sign In   
  • Create Account


Distance squared light falloff


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Hodgman   Moderators   -  Reputation: 27585

Like
5Likes
Like

Posted 31 May 2013 - 09:27 AM

I've read in a thousand places "the falloff for a spherical or point emitter is 1/d^2" and I understand the geometrical reasons for the graph to have this shape.
If you have a sphere with radius=1m, then a section of it's surface with an area of 1m2 subtends 1 steradian.
Increase the radius by 10x, and this surface area becomes 100x bigger.
So, if a point is emitting 100 photons per second per solid angle, then at 1m from the point, a detector covering our 1m2 area will capture 100 photons per second, however at 10m away, it will only capture 1/100th as much, or 1 photon per second. Increasing distance by a factor of x caused a 1/x2 reduction in photons captured.
 
 
...but there's a few details I'm sketchy on.
Most sources simply state that the inverse square law is true, without much further discussion. Many photography sources I've read go much further into layman's terms: "if you move the light twice as far away, the illumination will be one quarter"...
 
To illustrate why I'm struggling with this fairly simple law, let's say we've got an American and an Australian doing the same test:
One measures the distance as being 2 feet, and calculates a falloff factor of 1/4.
The other measures the distance as being 0.6096m, and calculates a falloff factor of 2.69.
Obviously some detail is missing here wink.png Sure, if the American divides by 1-foot-in-metres2, he can convert his result over to match the scientific one... but to me, this indicates that the falloff factor isn't just a unit-less multiplier, it's measured in "energy" per "distance-unit" squared, which is why they can convert their final results -- one is in energy/ft2 and the other in energy/m2.
 
Is this right?
So does this mean that if you're working with lighting in units of lux, or lumens/m2, then this means that you should always use metres when calculating your distance-squared falloff factors? And likewise if you were working with foot-candles, you'd use feet in your distance-squared falloff calculations?


 

 


The other issue that I have is the pesky fact that 1/d2 goes to infinity as distance goes to zero.
This doesn't make any sense -- if I place a solar panel so that it's touching a light-bulb, I don't get limitless power for free!
 
Using this formula (4atan(ab/(2d*sqrt(4d^2 + a^2 + b^2)))), you can calculate the solid angle of a rectangle that is facing the centre of the sphere, with sides a&b and distance d from the centre of the sphere.
34c829c68c332bea104266d61649e975.png
 
Say you've got a sphere with radius 1, and it's enclosed by a cube. One cube-face has a&b=2 and d=1. If you plug this in above, you get Pi*4/6 (or 2.094sr), which makes perfect sense, as the sphere has Pi*4 steradians total, and there are 6 equal cube faces surrounding it.
 
If again we say that the light is outputting 100 photons per second per solid angle, then this cube-face will capture 209.4 photons/s.
If we move this square so that it's 10 units away instead of 1, it's solid angle becomes 0.0396sr and it captures 3.96 photons/s (not a 100x difference as before).
If we move it so that it's 0.0000001 units away (basically touching the light source), then the solid angle doesn't go towards infinity, it reaches a limit at Pi*4/2 (or 6.283sr) and captures 628.3 photons/s -- i.e. it captures virtually everything emitted by one hemisphere, but can never do more than that!
 
Here is a plot of the inverse square law vs the solid-angle of a rectangle function. There's also a normalized (0-1 range output) version of both (1/(1+x)^2 for inv-square-rule, and dividing by the maximum of 2pi for solid angle).
 
What's up with the differences here?
With the inverse square law, the receiver/detector is a spherical cap, whereas with the solid-angle function the receiver/detector is a bounded plane. Wouldn't the latter be a better representation for most computer graphics uses?
Isn't the purple line on that graph really what we want to be using for distance attenuation?


 

 


However, having been perplexed by the fact that attenuation could go to infinity, I stumbled upon this blog post, which explains that the correct formula should actually be:
atten = 1/(d/r+1)2
Where r is the radius of the emitter. This gives you the additional behaviour that you can tweak your light falloff values not just with arbitrary falloff multipliers or by tweaking the intensity -- you can use a larger emitter sphere to get more gradual falloff, which is something that seems to be missing from everything discussed above.

This formula is working pretty well for me, but it leads me to another problem: it only works for area lights (which I guess everything is in the real world); It hides the "naked singularity" of the basic version of the inv-square rule by ensuring that the distance is always greater or equal than the radius of the light.

 

...but I've read over and over that it's provable that a point light has 1/d2 falloff, and this formula doesn't work when the radius of the emitter is zero, so I'm still left puzzled about how to reconcile point emitters with spherical emitters. These two variants (1/d2 and 1/(d/r+1)2) give different answers, so... are they both right, but give answers in different units?


Edited by Hodgman, 31 May 2013 - 09:49 AM.


Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2355

Like
0Likes
Like

Posted 31 May 2013 - 09:42 AM

For the solar panel one, i guess at distance 0, the area of the solar panel there would be very close to 0 too, canceling it out.


Waterlimon (imagine this is handwritten please)


#3 japro   Members   -  Reputation: 887

Like
4Likes
Like

Posted 31 May 2013 - 09:45 AM

...but I've read over and over that it's provable that a point light has 1/d2 falloff, and this formula doesn't work when the radius of the emitter is zero, so I'm still left puzzled about how to reconcile point emitters with spherical emitters.

Yes, an actual 1/d^2 falloff for arbitrarily low d would be unphysical... but so is the concept of a point light source ;). Now if you have a spherical light source you can integrate the 1/d^2 over the sphere surface and will find that it is equivalent to having a point light source at the center of the sphere as long as you are observing from outside the sphere (edit: to clarify i think you have to integrate over the whole sphere surface, so this would be a "transparent" light emitter). Also notice that while moving arbitrarily close to a theoretical point light source the energy doesn't go to infinity, the energy density does...

Generally when we speak of point light sources we mean that the radius of the light source is a lot smaller than the distance we observe from. If for example you had a linear light source then you will find a 1/d falloff and and if you have a light emitting plane there is no falloff at all (assuming the plane/line is infinite, or we are so close to it that we can consider it infinite for practical purposes)

 

One measures the distance as being 2 feet, and calculates a falloff factor of 1/4.
The other measures the distance as being 0.6096m, and calculates a falloff factor of 2.69.

Here you are mixing up relative and absolute measurements. You quoted "doubling the distance cuts the intensity by four"... now how do you go from doubling the distance to "2 feet"? Or more specifically, which distance did you double?

Doubling the distance would mean to go from 1 foot to 2 or from 0.3m to 0.6m in both cases you doubled the distance and quartered the intensity...


Edited by japro, 31 May 2013 - 10:00 AM.


#4 mhagain   Crossbones+   -  Reputation: 7422

Like
1Likes
Like

Posted 31 May 2013 - 10:10 AM

Here you are mixing up relative and absolute measurements. You quoted "doubling the distance cuts the intensity by four"... now how do you go from doubling the distance to "2 feet"? Or more specifically, which distance did you double?

Doubling the distance would mean to go from 1 foot to 2 or from 0.3m to 0.6m in both cases you doubled the distance and quartered the intensity...

 

Yes, this.  Your falloff factors are relative to a distance of 1 in each of your respective units, so relative to 1 meter, a factor of 2.69 is correct - because the light at 0.6096 meters will be that much brighter than the light at 1 meter.  Important to keep your units consistent.

 

In this case, to do an equal comparison you need to use the falloff at 0.3048 meters (1 foot) and compare to the light at 0.6096 meters (2 feet) - that gives us 10.7639 and 2.6909, and what do we get if we divide the former by the latter - 4.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 Frenetic Pony   Members   -  Reputation: 1185

Like
0Likes
Like

Posted 31 May 2013 - 01:56 PM

Point emitters are just a theoretical non physical thing. It's just used because hey, it looks good and close enough to physical that who cares right? There is no real world analogue to an infinitely small point light of course, quantization as photons blah blah blah. It's a useful hack and that's that. And importantly its the fastest useful hack you can do, at least for getting close. And it should still be energy preserving, after all the closer you are the the infinitely small point source the smaller the area being affected. At zero, the point source, you've infinite energy and zero area to fall on so congratulations!

 

I guess if you really wanted to, and why wouldn't you? You'd use the blogs thing and estimate the actual area of the light source for everything. The area being the coil inside the lightbulb, or maybe the area of the reflector on a flashlight if you want to get all that light in there. I.E. choose your convenient light diffuser/reflector. More accurate light falloff for real cheap, sounds good to me; even if most light sources we actually have are extremely small (which is why point light sources work so well as an analogue) there's still other things that will reflect them in a static fashion/diffuse the light to the point that an area light source such as the blog's would be more correct.


Edited by Frenetic Pony, 31 May 2013 - 06:11 PM.


#6 kalle_h   Members   -  Reputation: 1276

Like
0Likes
Like

Posted 31 May 2013 - 06:06 PM

Even if it's not right I use 1 / (1 + d^2) it's cheaper than 1 / (1+d)^2 and nicely avoid infinite problem. For pc game I would use area lights for everything but it's just not feasible on mobiles yet.

Edited by kalle_h, 31 May 2013 - 06:07 PM.


#7 Vilem Otte   Crossbones+   -  Reputation: 1346

Like
0Likes
Like

Posted 31 May 2013 - 07:00 PM

Ad infinite problem, maybe this is absolutely obvious and I'm just spamming, but from what I remember, the number of photons is, by all means, finite (and can be computed). Therefore you can't recieve infinite energy near the light.

 

F.e. for 40W cool white fluorescent bulb it should be around 2.55 X 10^19 photons radiated per second (counting effectivity in - it can be derived from energy of single photon E=hf=h * c / lambda, average wavelength for light = 600 nm, energy = 40W ~ 40J (assuming we radiate the light for 1 s), with this value divide the actual energy radiated by the bulb (of course after application of efficiency which should be just several percent)).


My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com


#8 MJP   Moderators   -  Reputation: 10223

Like
0Likes
Like

Posted 31 May 2013 - 08:08 PM

It's just used because hey, it looks good and close enough to physical that who cares right?

 

It's used because it's trivial to analytically integrate a punctual light source with any BRDF, which isn't true of area lights.



#9 Hodgman   Moderators   -  Reputation: 27585

Like
2Likes
Like

Posted 31 May 2013 - 09:15 PM

One measures the distance as being 2 feet, and calculates a falloff factor of 1/4.
The other measures the distance as being 0.6096m, and calculates a falloff factor of 2.69.

Here you are mixing up relative and absolute measurements. You quoted "doubling the distance cuts the intensity by four"... now how do you go from doubling the distance to "2 feet"? Or more specifically, which distance did you double?
Doubling the distance would mean to go from 1 foot to 2 or from 0.3m to 0.6m in both cases you doubled the distance and quartered the intensity...

That example only contains absolute measurements. The "doubling the distance" bit was mentioned earlier, the way I've heard photographers explain 1/d2. This example only contains absolute d values being plugged into 1/d2.

Your falloff factors are relative to a distance of 1 in each of your respective units

Ah that makes sense! So when games use code like:

output = dot(n,l) * 1/(d*d) * intensity

then intensity is the value that you want the light to have at one unit from the centre... pretty obvious once I say it, since that's what happens.

And with the blog's formula, you're not setting intensity at 1 unit, you're setting intensity at the surface of the emitter. So the two formulas are give multipliers that should be used against different initial intensity values.
 
I guess seeing that the above code doesn't take steradians or areas into account anywhere, we're using some kind of assumption that all of our calculations are being done for some small-steradian-subtending small-area, which is the same for every one of our pixels? So if our game uses metres for everything, our light intensity value is in "light-units per small-area-at-1m-distance"?
 
 
If you bring the light 2x closer, it will get 4 times brighter, and with it being a point there's no limit to the number of times you can do this... so:

Also notice that while moving arbitrarily close to a theoretical point light source the energy doesn't go to infinity, the energy density does..

Thanks! So even if the light emits a quantifiable pulse of 100 photons, then at the moment of emission, there's always only 100 of them... but if your receiver was at the same point, with zero area, then we'd say there was 100 photons being received in zero area, which gives us a reading of infinity photons per m2!
 
In games, using the above code snippet as an example, we pretty much never take the receivers area into account (except for the N.L term). If we accounted for the actual world-size of the pixels that we're shading, and the solid angles that they subtend, would this cancel out the wackyness caused by the fact that the energy density approaches infinity? i.e. in order to measure that infinite energy density, our receiver have to have zero area, so you'd end up with something that's wacky in a different way, like x0Pwhwk.gif? Or we'd have a rectangular receiver area with most of it having zero energy and a single point on it's surface having infinite?
 

this formula doesn't work when the radius of the emitter is zero, so I'm still left puzzled about how to reconcile point emitters with spherical emitters. These two variants (1/d2 and 1/(d/r+1)2) give different answers

I figured this one out myself - it is possible to reconcile the two formulas:
In the formula from the linked blog, d is the distance from the outside of the emitting sphere to the receiver, and r is the sphere's radius. We can rearrange the blog's formula like so:
zQMzcUD.gif
Importantly, d+r is the distance from the centre to the receiver, which is what the typical 1/d2 formula uses. So if we let D=d+r, and try and find an equivalnce with the typical formula, we get:
EZhingb.gif
4gAaYuZ.gif
So, our typical 1/d2 formula is actually true for a sphere with radius of 1 unit (so again, your 'light intensity' game values are relative to 1 of your distance units). I guess this also implies you shouldn't trust it's answers for values of D that are smaller than 1, because such a situation should be unpossible, although the math does hold up until D hits zero smile.png

 

 

I'm still confused about the differences that occur depending on whether we treat our receiver as a spherical cap vs a rectangle though (with the 1/d^2 law being right for the spherical cap). Is this always the most appropriate geometrical approximation to be using?


Edited by Hodgman, 31 May 2013 - 09:27 PM.


#10 kalle_h   Members   -  Reputation: 1276

Like
0Likes
Like

Posted 01 June 2013 - 01:23 PM

How about r^2 / (max(d,0) + r)^2 to fix infinity problem?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS