Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question about spherical spreading of light.

Started by Grasshopper Dec 15, 2010 at 10:44 AM 30 replies 5.3k views
Original Post
Grasshopper
Grasshopper
A light source at distance d1 from a object attenuates at 1/(d1*d1). If the point at which the light hits a object is at distance d2 from the camera shouldn't the light also attenuate by 1/(d2*d2) as it travels from the reflection point back to the camera? I know sonars works this way but I don't really see lighting calculations done like this. Anyone know why?
Palidine
Palidine
I'm sure other people have much more informed responses, this is just what I've picked up here over the last few years [smile]

Well it's attenuated from the point of reflection but it's a lot more complicatated then that. Surfaces don't have perfect reflectance and are often colored. So if you shine a white light at a red object you will get some red reflection off of that object (it's red because it's absorbing all the other wavelengths and partially reflecting the red). Ray tracing engines do all of these things

The way that modern graphics cards are set up you need to consider each light source separately (they don't do ray tracing). You start by looking at a point of an object and saying "how many lights are affecting me" and then sum up all the lights' effects. This model doesn't work well for down the line reflectance where every point of every object in the scene is basically a light source. Ray tracing engines work basically in the opposite direction. You bounce around rays originating from the lights and add onto surfaces you contact. It's basically lighting from the perspective of the lights rather than lighting from the perspective of the objects, if that makes sense. so with ray tracing you get this kind of stuff "for free". Ray tracing is orders of magnitude slower so you don't see it in many real-time applications; hardware graphics cards are still fairly optimized for the non ray tracing way of doing things.

-me
DarkChris
DarkChris
1/(d1*d1) isn't even true... The light just has less influence on the integral over the hemisphere the farer away it is... Just look at specularity... Your formula doesn't work there either...
Sneftel
Sneftel
Quote:
Original post by Grasshopper
A light source at distance d1 from a object attenuates at 1/(d1*d1). If the point at which the light hits a object is at distance d2 from the camera shouldn't the light also attenuate by 1/(d2*d2) as it travels from the reflection point back to the camera?
Sure. Try this: In a dark room with walls painted black, put a camera, a white ball, and a spotlight shining on the white ball. Sure enough, as the white ball gets further from the light, it gets dimmer. Moreover, if you look at the camera -- the body camera itself, not the image from the viewfinder -- it'll get dimmer as it moves away from the ball, because less light reflected off the ball hits the camera.

But that's not how the camera works. The way the camera works is by measuring the light hitting a particular pixel, which is to say, the light entering the camera from a direction within a particular (very very thin) cone. Those cones put together make up the entire viewing cone.

As an object gets further from the camera, the amount of light emanating from a given point within the pixel's viewing cone and hitting the camera decreases as 1/r^2. HOWEVER, as the object gets further from the camera, more and more of the object is visible within that cone, so the area contributing to that pixel grows as r^2, cancelling it out. So less power is received by the camera, because fewer of the pixels are white, but the same intensity is recorded by the pixels that remain white.
DarkChris
DarkChris
Quote:
Original post by Sneftel
Quote:
Original post by Grasshopper
A light source at distance d1 from a object attenuates at 1/(d1*d1). If the point at which the light hits a object is at distance d2 from the camera shouldn't the light also attenuate by 1/(d2*d2) as it travels from the reflection point back to the camera?
Sure. Try this: In a dark room with walls painted black, put a camera, a white ball, and a spotlight shining on the white ball. Sure enough, as the white ball gets further from the light, it gets dimmer. Moreover, if you look at the camera -- the body camera itself, not the image from the viewfinder -- it'll get dimmer as it moves away from the ball, because less light reflected off the ball hits the camera.

But that's not how the camera works. The way the camera works is by measuring the light hitting a particular pixel, which is to say, the light entering the camera from a direction within a particular (very very thin) cone. Those cones put together make up the entire viewing cone.

As an object gets further from the camera, the amount of light emanating from a given point within the pixel's viewing cone and hitting the camera decreases as 1/r^2. HOWEVER, as the object gets further from the camera, more and more of the object is visible within that cone, so the area contributing to that pixel grows as r^2, cancelling it out. So less power is received by the camera, because fewer of the pixels are white, but the same intensity is recorded by the pixels that remain white.


1/r^2 doesn't even make any sense at all... Is that measured in Millimeters, Centimeters, Miles, Meters or what? And what happens if r is below 1...

1/(0.01)² = 10,000

Wow that makes sense...
Sneftel
Sneftel
Quote:
Original post by DarkChris
1/r^2 doesn't even make any sense at all... Is that measured in Millimeters, Centimeters, Miles, Meters or what?

Whatever units you like, since it's being used as a ratio. As the distance is doubled, the illuminance is quartered. Note, however, that the equivalence I mentioned is for objects whose distance from each other is much greater than their size, and depends on the approximation sin(x)=x for small x.

For more information on attenuation of this form, see this article. The inverse square law comes up in a lot of different situations.
DarkChris
DarkChris
Quote:
Original post by Sneftel
Quote:
Original post by DarkChris
1/r^2 doesn't even make any sense at all... Is that measured in Millimeters, Centimeters, Miles, Meters or what?

Whatever units you like, since it's being used as a ratio. As the distance is doubled, the illuminance is quartered. Note, however, that this is for objects whose distance from each other is much greater than their size, and depends on the approximation sin(x)=x for small x.


Yes but it's still doesn't make any sense for lights being less than 1 unit away...

That's how it works from a physical perspective...



In both my explanation and the real world the lighting will never be multiplied by infinity... which is the case in lim x->infinity 1/(0+1/x)²
Pragma
Pragma
So where then does the inverse square law fail? You said one "unit", is that one millimeter or one meter or one kilometer?
"Math is hard" -Barbie
Sneftel
Sneftel
Of course it works for distances less than one unit. Consider an object 0.01 units away from an object, and an object 0.005 units away. For some X, the illuminance of the first object will be X/0.01^2, and that of the second will be X/0.005^2. That is, the second object will be four times as illuminated. The fact that the numbers are below 1 has no bearing.
DarkChris
DarkChris
Quote:
Original post by Pragma
So where then does the inverse square law fail? You said one "unit", is that one millimeter or one meter or one kilometer?


It's the unit I use when I would implement that in my engine... And that can absolutely be less than 1...

Quote:
Original post by Sneftel
Of course it works for distances less than one unit. Consider an object 0.01 units away from an object, and an object 0.005 units away. For some X, the illuminance of the first object will be X/0.01^2, and that of the second will be X/0.005^2. That is, the second object will be four times as illuminated. The fact that the numbers are below 1 has no bearing.


Yes... But the overall lighting will be infinity for a radius of 0... Which is impossible..

Update: I just noticed that my theoretical approach is almost the same as 1/d² - It just extends it a bit further by adding the radius of the light, thus being a bit more useful in an actual graphics engine...

So neither you or me is more correct... My version is just more practically orientated...

By the way thanks for voting me down... I really appreciate our discussion...
Sneftel
Sneftel
Quote:
Original post by DarkChris
Yes... But the overall lighting will be infinity for a radius of 0... Which is impossible..

Well, yes. r^2 * 1/r^2 is defined as 1 only if r != 0. So if you manage to cram a true, perfect point light source, an infinitely small diffuse reflector, and an ideal pinhole camera all onto the same point in space, you're going to have a real problem. For possible situations, it doesn't come up.
Sneftel
Sneftel
Quote:
By the way thanks for voting me down... I really appreciate our discussion...
I haven't voted you either way.
0xffffffff
0xffffffff
The inverse square law is based on the projected area of the light source as seen from the point being lit. As the light moves away from the lit point, it occupies a smaller portion of the lit point's visible hemisphere, hence the lit point receives less total light to scatter. (For a pure specular/mirror, there is no scattering at all, and no distance attenuation.)

A true point light (if it could exist) would have no distance attenuation because its projected area would be zero at any distance.
Grasshopper
Grasshopper
This has been enlightening so far. I'm guessing that with exponential attenuation (e^-a*dis) for say fog this would be applied to the distance from light to object(d1) and the distance from object to camera (d2). So the final attenuation would be (e^-a*(d1+d2)) due to the absorption/scattering of light?
Sneftel
Sneftel
Quote:
Original post by 0xffffffff
A true point light (if it could exist) would have no distance attenuation because its projected area would be zero at any distance.
You should think of the incoming irradiance as a Dirac delta function -- the width is 0 and the height is infinite, but it integrates out to a reasonable number.
DarkChris
DarkChris
But I have to say that I was wrong... I'm sorry... How could I possibly deny a formula that is proven to be correct xD
I actually have to thank you even though the discussion resulted in a huge vote down... It made me think about it and I actually realized that I might have implemented it wrong... Thanks guys...
Sneftel
Sneftel
Quote:
Original post by Grasshopper
This has been enlightening so far. I'm guessing that with exponential attenuation (e^-a*dis) for say fog this would be applied to the distance from light to object(d1) and the distance from object to camera (d2). So the final attenuation would be (e^-a*(d1+d2)) due to the absorption/scattering of light?
For absorption, yes. For scattering it gets more complicated, since the object starts being lit by "ambient" as well as direct light, and you gotta decide just how much realism you want in there. But if your fog is black, then that formula is fine.

EDIT: Actually, hm.. now I'm not sure I believe myself about that.
Krypt0n
Krypt0n
Quote:
Original post by Grasshopper
This has been enlightening so far. I'm guessing that with exponential attenuation (e^-a*dis) for say fog this would be applied to the distance from light to object(d1) and the distance from object to camera (d2). So the final attenuation would be (e^-a*(d1+d2)) due to the absorption/scattering of light?


with fog you apply the usual distance attenuation for light<->object, on top you apply the fog formula for the eye<-object->light distance.
0xffffffff
0xffffffff
Quote:
Original post by Sneftel
You should think of the incoming irradiance as a Dirac delta function -- the width is 0 and the height is infinite, but it integrates out to a reasonable number.

That's right, but the inverse square attenuation formula will never arise in such an integral (using Dirac Delta) because it's an effect of projected area. (Sadly, none of the desirable BRDFs has a sane analytical formula for evaluating an area light source "properly".)
taby
taby
I feel the need to state some facts. I think that Sneftel's being treated unfairly, and that his correct opinions are not being respected.

It's called the inverse square law because Newton proved mathematically that when viewed from a distance, a point source of zero surface area is functionally equivalent to a spherically symmetric source of non-zero surface area. This proof, called Newton's Shell Theorem, is what gives substance to the inverse square law, and so it's utterly and irrevocably incorrect to ever imply that the inverse square law and point sources are incompatible concepts. It's like saying chickens and eggs are incompatible concepts.

Perhaps it's just clearer to some when the light is superficially quantized into a countable number of particles? Imagine a spherical wavefront of 1000 photons that originated at r = 0. It's utterly intuitive that for any r > 0, the energy density of this spherical wavefront is E/Area(r) = E/(4*pi*r*r), where E is the total energy of the wavefront's photons combined. This fact of Nature has nothing to do with the surface area of the source, but the surface area of the wavefront.

Once these things are clear, then it should be clear that the percentage of the Sun's output that reaches Earth is dependent on the apparent size of the Earth as seen from the Sun, not the other way around.

[Edited by - taby on December 17, 2010 12:51:23 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.