Closed tommadams closed 4 years ago
comment imported from WordPress David said on 2011-01-31 15:05:12:
I remember first learning about this in my electro magnetism class.
You can also prove analytically that a infinitely small point light has a falloff of d^2 and a infinite plane will have a 1/d falloff.
-= Dave
comment imported from WordPress Dominic Hamon said on 2011-02-04 18:07:52:
Not quite. A point light has a falloff of 1/d^2, an infinite linear-source (an approximation of an infinite fluorescent tube) has a falloff of 1/d, and an infinite planar-source will have a falloff of 1/1.
To be clear, the term attenuation usually applies to the absorption and scattering of photons as they pass through some medium, and is often exponential based on the length of the path through that medium. The decrease in intensity that you're describing here is purely a geometric factor due to the constant flux of a light source propagating as a spherical wavefront.
I haven't worked through the maths to figure out why f_att isn't a pure inverse quadratic which is what I would expect.
comment imported from WordPress Tom Madams said on 2011-02-04 19:30:08:
Hey Dom, it's good to hear from you. In times like this I miss being able to pick your physics brain :)
If you're interested in the proof, Miles pointed out over email that Iñigo Quilez worked through something very similar for analytic sphere occlusion:
http://www.iquilezles.org/www/articles/sphereao/sphereao.htm
I got lost somewhere around the forth double integral.
comment imported from WordPress David said on 2011-02-10 15:12:07:
Yes, sorry infinite rod is 1/d. It's been a while.
I do also remember when I first started studying this I was talking to my friend who has his PhD in physics and asking him to explain to me the attenuation equation. We had quite the confusing conversation because in my mind attenuation was the spreading of flux and he thought of it as absorption in participating media. It would be interesting to find the origin of the term attenuation for graphics to see the authors reasoning.
comment imported from WordPress Tom Madams said on 2011-02-11 11:22:39:
Dominic is correct when he describes the usual meaning of attenuation, but correctly calculating scattering and absorption is non-trivial. In games we normally just place our world in a vacuum and hope nobody suffocates.
The effects of participating media can be approximated using a simple exponential (or even linear!) fog model, or a scattering model such as Preetham's or Bruneton & Neyrett's for outdoor scenes.
Glows around light sources can be approximated with a post process bloom, a simple view-aligned sprite, or a combination of both.
Unfortunately, these approaches don't capture effects such as the softening of specular lobes due to scattering.
You have just reminded me of an interesting paper from SIGGRAPH 2005 though, which does approximate these effects for the single-scattering case.
comment imported from WordPress Chris Jurney said on 2013-02-12 12:18:25:
Thanks for this article. Super helpful.
Just thought I'd mention that I used this model, although I changed the definition of d from being light surface to point to light center to point. The reason being that to build natural looking lighting, artists were using large radii with moderate intensity, but that resulted in lots of area being inside the light's radius. That makes for a discontinuity in lighting that shows up as a circle on the ground at the edge of the light. Using the center distance makes the "radius" term somewhat inaccurate, but it still does what content creators expect in relative terms.
comment imported from WordPress Irbis said on 2013-03-19 11:35:16:
How do you define Li in dmax equation ? max(r,g,b) ? luminance = dot(rgb, vec3(0.2126, 0.7152, 0.0722)) ?
comment imported from WordPress Tom Madams said on 2013-03-19 12:26:48:
I think I used max(r, g, b) at the time, but there was no justification for that choice. Really you should just define it in whatever way works best for you and your artists.
comment imported from WordPress Irbis said on 2013-03-19 17:08:07:
Let's assume that r = 1, Li = 10 (HDR), cutoff = 0.01. Then dmax = ~30.6. Theoretically the attenuation for d = 20 should be greater than 0, but scaling and biasing attenuation give us 0. Maybe better solution is: attenuation = (attenuation - (cutoff / Li)) / (1 - (cutoff / Li)) ?
comment imported from WordPress John Hughes said on 2013-03-21 19:47:29:
First. I appreciate your feeling sorry for Feiner and Hughes, but I'm pretty sure Steve and I have never felt all that bad -- working on the second edition was, for me, a great opportunity right near the start of my career in graphics.
Second, this is a nice bit of work, but it won't appear in the new edition -- not because I don't like it, but because we're now at the copyediting phase of production, and if I tell my editor I want to add a few pages, I'll probably have to pay the hospital bills. :)
As a small compensation, in the chapter about light and its measurement, we do an exact computation of the radiance leaving a spherical source, and I believe there's an exercise in which the student gets to analytically integrate the cosine-weighted arriving radiance at a plane beneath that spherical source, so if you do this exercise, you sort of get a shot at learning the falloff rule (and being able to generalize, at least if you like integrating!). A key lesson is to realize that unless the ratio d/r is quite small (glowing bubbles above a tablecloth?) the attenuation term looks a LOT like 1/d^2. For the room I'm sitting in, d/r is approximately 20, for instance. Not small enough to make a significant difference.
Keep up the good work!
comment imported from WordPress Tom Madams said on 2013-03-21 22:26:16:
Thanks for the comment John, just knowing that you've read my post is more than enough compensation.
I wasn't aware that a third edition of Computer Graphics was on the way, I look forward to its publication. My second edition copy is a valued possession, and one of the few books I took with me when I moved across the Atlantic from England to the US a few years ago.
My maths skills have never been more than mediocre, so if the new book does have an exercise that leads the way towards a mathematical understanding of the falloff (more than my 'hey, these graph plots look alike'), I will give it my best shot. I shall have to brush up on my surface integrals in preparation :)
comment imported from WordPress Pink Bobsledder said on 2014-08-15 13:19:54:
"Unfortunately this attenuation model is still problematic for real-time rendering, since a light’s influence is essentially unbounded."
I'm wondering if you could expand on why this is an undesirable effect? Sure you're cutting off below a threshold, but aren't you still running the pixel shader for those pixels? Why not just let the little fraction of light shine through as it will hardly contribute to the result (and be more physically plausible)?
I could see if you optimized your light loop to not include lights over a cutoff distance however...
comment imported from WordPress Tom Madams said on 2014-08-16 19:50:02:
This was a toy example so yes, I was running the fragment shader for all pixels.
Like you say, in more complex scenes you would want to avoid performing shading computation for as many pixels as possible.
comment imported from WordPress Paul Houx said on 2016-07-30 03:40:47:
Hi,
it took me a while to figure out a proper value for the cutoff. At first, my value was too high and as a result I could not see any light contribution (attenuation was close to zero).
I finally came up with the following formula, based on the light's radius and maximum range:
float denom = range + radius;
float cutoff = ( radius * radius ) / ( denom * denom );
This is derived from your formula's and therefor fully compatible.
-Paul
comment imported from WordPress gerryraptis said on 2018-09-19 10:13:16:
Hi, Just thought I would mention a very simplifying change of terms (similar to Paul Houx).
If we define D being the distance from the center of the spherical light (instead of the surface of the light), then the equations become:
Then D=r+d => d = D-r
fatt = 1 / (d/r + 1)^2 = 1/ ((D-r)/r + 1)^2 = 1/(D/r - r/r + 1)^2 =>
fatt = r^2 / D^2
This is simpler for games as you usually have the translation of the light, and of course the lighter math might help with shader performance.
I would recommend though to clamp the value to a minimum of r, in case objects can be within the area light radius to avoid oversaturation and/or infinitely bright lights (i.e. touching the surface of the light you are getting as much light from it as possible)
comment imported from WordPress seblagarde said on 2018-12-27 09:02:55:
Hi, As I see several people referring to this blog post in a wrong way, I would like to bring a clarification.
What you present is the attenuation of a disc light, not a sphere light.
You can found detail in https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf 4.7.2.2 Sphere area lights 4.7.2.3 Disk area lights
attenuation of sphere is R^2 / D^2
Comments for blog post 2011-01-31-light-attenuation