for Lamp lights, if I press ‘Quad’ the ratio of decay of the energy is proportional to the inverse of the distance, square. This is correct and physically appealing.
But if I do NOT press quad, how does the light decay? Linearly?
for Lamp lights, if I press ‘Quad’ the ratio of decay of the energy is proportional to the inverse of the distance, square. This is correct and physically appealing.
But if I do NOT press quad, how does the light decay? Linearly?
I’ll check the source the next chance I get (if I remember to do so :-? ).
looking in the 2.0 guide in the Button section I found
the formulas D/(D+a) and D/(D+a^2) which make sense but
there is no hint on how the ‘Sphere’ button change this
Yes, sun & hemi are just directional lights with no falloff, hemi is like sun but uses the full normal/lightvector dotproduct result instead of ignoring the negative values as for regular lighting, it just does 0.5+(N.L)*0.5, a trick I used myself very long ago in my first landscape engine.
DIST is the distance to which the light will remain at full strength, beyond which it will attenuate.
Is there any way to visualize “dist?” On everything but “Lamp” I can see the effect on the dotted line that extends down from the lamp, but on just plain ol’ “Lamp” there is no apparent affect.
Did I miss someone say “on just ‘Lamp’ there is no attenuation, so DIST is meaningless?”
Well, it’s not really a “trick”. Rather, it’s the analytic solution to solving the integral of light coming in from a 180-degree range of directions (i.e. a huge hemisphere… hence why it is called “hemi”). Of course, the integral assumes a Lambertian surface material (i.e. cosine falloff).
I’ve looked at the code now, and I have figured out the following:
If the lamp is neither QUAD nor SPHERE, then the falloff uses the following function:
f(d) = n/(n+d)
where n is the “dist” setting of the lamp, and d is the distance from the lamp to the point being lit.
Note that this is the equivilant of a “1/x” falloff, except that it has been tweaked to make it customizable, and to make it so that whenever d=0, f(d)=1.
If the lamp is SPHERE, then it uses:
f(d) = (1-(d/n))^2
Where n is the “dist” setting, and d is the distance from the lamp to the point being lit. The intensity is clipped to zero if it goes below zero.
Note that this is the same as calculating a linear fall-off, and then squaring it (not the same as an inverse-square falloff).
If the lamp is QUAD, then it uses:
n n^2
f(d) = ---------- * --------------
n + (a*d) n^2 + (b*d^2)
where n is the “dist” setting, a is the “quad1” setting, b is the “quad2” setting, and d is the distance from the lamp to the point being lit.
The problem that I see with this equation, though, is that if you work with it a bit, you get:
which is inverse cubic rather than inverse quadratic. Of course, you can get inverse quadratic by having a=0, but then you can’t have the linear component of the quadratic equation.
The equation should be something like this (though perhaps a little different):
n^2
f(d) = ---------------
bnd^2 + a(n^2)d
I suspect that someone was very tired when they were working out the math for the quad-lamp falloff.
It was definitely a ‘trick’ when I used it at the time, I have no clue about integral’s (well, not back then anyway) or whatever, it was just a hack I came up with that I found to improve the lighting in that situation.
Anway, excellent and clear explanation, I knew you would do that…
I got the Linear and Quad decay now.What puzzles me is still the ‘sphere’ option.
From the code fragment eeshlo posted I got the (wrong ?) impression thet the Sphere light decay had just a multiplicative factor (n-r)/(n+r). If I got it right then there would still be difference between Linear and Quad Decay for a Sphere lamp, but if Cessen is right then there wouldbe no difference and Sphere would override any other setting.
Well, I really don’t want to contradict Cessen, but as far as I can see it was correct. The code flow is as follows, if the lamp is not quad, first the decay for a regular lamp is calculated:
Dist / (Dist + lampdistance)
then if ‘sphere’ mode is set, this is further multiplied by (unless the result is negative):
(Dist - lampdistance) / Dist
I just rewrote this as:
(Dist - lampdistance) / (Dist + lampdistance)
Don’t forget that it is also possible to use ‘Quad’ and ‘Sphere’ together in which case you get:
quad_intensity * (Dist - lampdistance) / Dist
I don’t really feel like expanding that to the full equation…
But again, since I have to get by with less than highschool maths, I certainly would trust Cessen to really know what he is talking about, so let’s just wait what The CG Theory Guru has to say about this.