|
|
|
|
|
|
|
|
| Links |
|
|
|
Quadratic/Linear/Constant in Lights - By Raeven0 |
|
This tutorial was last updated on Dec 23, 2005.
[Valve have given us a new way of setting falloffs. Check your light entity properties. Also, this tutorial had to be updated to reflect the Wisdom of Master Rof 23 Dec 05. --Rae]
There's a bit of intermediate mathematics involved in this. And you wondered why you had to learn all that stuff?
Skip to the bottom of the tutorial for information on how you should set Quadratic, Linear, and Constant. Start here and read the entire tutorial for my lecture.
The Quadratic, Linear, and Constant properties (specified in the light entity properties along with Name, Brightness, etc.) are related to how far the light from an entity can travel. But the relationship is only slightly complex...
Suppose I have a light with intensity I = 256. (The intensity is specified by the last number in a light's Brightness property. The first three specify color.) Suppose q is your quadratic number, L is your linear number, c is your constant number, and d is a given distance from the light.
In most lighting programs, the brightness of your light at d is represented by:

That is, the brightness of the light at a particular distance is usually determined by the brightness of the light (256 in the example) times the reciprocal of the quadratic times the square of the distance, plus the linear times the distance, plus the constant.
The number in parentheses is called the attenuation factor of the light, so named because it is a factor (any value multiplied by another) used to attenuate (reduce) the brightness of the light. The larger the attenuation factor's reciprocal, the greater the amount of attenuation--so in most programs, setting high q, L, and c will greatly reduce the light's intensity per unit of distance.
In Source, however, q, L, and c are first used to scale I. The intensity is scaled such that, at d=100, I has exactly the same value as q*100*100 + L*100 + c. For any I, this means Inew = Iold*(Q*100*100 + L*100 + C).
The actual meaning of this is that the intensity set in the light's properties is actually achieved at d=100. Another wording: the last number of the Brightness property controls the brightness of the light at 100 units. Once the intensity is so scaled, then we use the attenuation factor normally.
Also, because q, L, and c are first used to scale I, they will actually become a part of the intensity (256 in the above example). After the intensity is multiplied by the attenuation factor, what results is that q, L, and c end up in the numerator of the attenuation factor. Notice a problem with that? If we have a similar expression of q, L, and c in both numerator and denominator...

...the coefficients will attempt to cancel one another wherever possible. At d=100, no matter the settings of q, L, and c, the light will have a brightness of 256. A similar phenomenon occurs for all d: the values themselves of q, L, and c are not important because they will be canceled and reduced; what is important is the ratio of q to L to c.
We need to know this because changing the intensity alone of the light has its limits with reference to falloff, the distance entity light can travel before it no longer brightens objects.
In general, if either q or L is significantly higher than the others, light near the entity will be very bright, falling to I at d=100. This is because the attenuation factor is very low for d<100 (because d itself, the coefficient of q and L, is low) but very high for d>100.
If q is significantly higher than L and c, light intensity will drop rapidly where d>100. If L is significantly higher, light intensity will try desperately to be linear where d>100.
If the highest value is c, because the attenuation factor is now extremely high for d<100, light near the entity is dimmer, and light intensity at d>100 is increased--this creates a more even falloff curve overall.
Special cases occur where any variable is 0, and where two of q/L/c are equal.
This isn't a mathematically sound perception, so let's dig deeper.
If the Quadratic number is Q, the Linear is L, the Constant is C, the set intensity of the light (last number of the Brightness property) is I, and the distance from the light to a point is d, then the intensity of the light ray at d, f(d), is defined as:

Graphing this function for a set Q, L, C, and I will show us how the brightness (on the f(d) axis) of the light decreases as the distance (on the x axis) increases. For instance, consider Q = 1, L = 5, C = 40000, and I = 100, graphed at -25<x<1000 and -25<f(x)<200, with marks every 25 units:

We can compare this to another graph for good measure. Consider Q=500, L=500, C=1:

The first light stays above 25 intensity for a reasonable 400 units, but it is never brighter than 125. The second light is much brighter nearer the entity (as a result of the lower Constant compared to the others), but drops to below 25 intensity in 200 units.
The Q, L, and C are therefore also related to the falloff of the light: how far the light from an entity travels until it is too dark to be considered. When you graph f(d), the Y-coordinates of the function are the brightnesses at a given distance X; by definition, this function can never cross the f(d) axis, but extremely dim light is ignored altogether.
One last vague attempt at laying it out simply. The attenuation factor [1/(qd^2+Ld+c)] is used to take power away from the light based on distance. A larger attenuation factor denominator [qd^2+Ld+c] would make the light dimmer. Keeping in mind that Q, L, and C are reduced, and that intensity is always known at a distance of 100:
- since Q is multiplied by the square of the distance, a comparitively higher Q will cause a sharp drop in intensity as distance increases.
- since L is multiplied by only the distance, it will increase the attenuation factor's denominator linearly. This has the net effect of morphing the f(d) graph (see above) to look more like a graph of 1/x-1, pulling intensities up or pushing them down as necessary.
- since C is always the same and unaffected by distance, a comparitively higher C will try very, very hard to make light near the entity dimmer.
So, to make a light that's bright but isn't bright for very long, set a comparitively high Quadratic.
To dim light near the entity, use a comparitively high Constant.
To even out the brightnesses so that they don't look abnormal, use a comparitively high Linear.
Extremely high and extremely low positive numbers are acceptable. 50000 works, 0.002 works...
What a mouthful!
Still need help? Ask your questions in one of our HELP FORUMS
|
|
|
| Comments |
| Cameron - Jun 27, 2007 |
I set up a map with lots of rooms with different light values to try and see what the differences were but none of those values actually seem to do anything except setting one of them (such as linear) to 1 and the others to 0. Even setting numbers as high as 50000 Q, 1 L and 1 C, it's exactly the same as 500 Q, 1 L and 1 C, or 20 Q, 1 L and 0 C. All the same (full VIS and Light compiles).
Using the 50% and 100% falloff distance gives you better control IMHO. Just remember that the 50% and 100% seem to be for direct light, compiling with full/final lighting will add rad bounces which will continue past these ranges. |
| Splambob - Apr 10, 2007 |
Hovis, vrad doesn't compute lighting after it has dropped to 1/256 intensity.
In other words, it's ridiculously pedantic. |
| reaper47 - Nov 15, 2006 |
| The math is a bit scary. But finally a full explaination of what q/l/c does. A few example screenshots would be gold. |
| Warren - Nov 3, 2006 |
Good tutorial. It's been a while since my last highschool math class, though.
My only suggestion is it would be nice to have examples, screenshots of lighting setups inside Hammer so we can see how best to adjust the quadratic, linear and constant variables. I'm interested in having more control over my lighting but I still don't understand how to use those variables. So far I've been relying on 50% falloff distance to achieve fading. |
| Raeven0 - Jul 11, 2006 |
| Hovis, if you're referring to the lowest intensity that means anything, I'm not exactly sure. I believe based on my rudimentary knowledge of code that the light travels infinitely in all directions, even if it becomes too dark to be seen. |
| Hovis - Jul 7, 2006 |
Very concise, tyvm for this great explanation and equations.
-----> One question, do you know what value is considered "negligible" for computing light by vrad?
(I'm having errors because my switchable lights are overlapping, and i'm trying to find way to workaround this without redesigning my level : /) |
[2 extra comments]
|
|
|
|