This is an updated repost from my old, deactivated blog or from notes of my past studies. The date follows the original time of writing.

Welcome to my reflections!

Today we dive right into the topic of light sources. We’re going to study the 3 basic light sources most frequently used in real-time rendering: omni, spot and directional light sources, understand the theory behind them, and learn when to use each of the three based on the scene description. It is important to note that omni and spot light sources are both point-light sources – they don’t have a finite area; in other words, the entire source is located at a point in space. The directional light source, on the other hand, is treated differently, as it doesn’t have a location per se. So, without further ado, let’s start; as we all know, this isn’t a Dream Theater track introduction!

Point-Light Sources

We start with point light sources, without any doubt the most used light sources in real-time rendering! Right now, take a look around: you’ll see that there isn’t such a thing as a point light source; all light sources in real-life environments possess area and shape, so what about point light sources? What actually happens is the use of an approximation based on the following assumption: the distance between the source point s and the shaded point p is large compared to the object being shaded itself. Using this assumption, we can simulate light sources without worrying about the complications of shape and area variation. By the way, these light sources are called area-light sources and are very useful and realistic; I intend to write a post specifically about area-light sources soon. Well, as stated before, point light sources can be divided into two major source types: omni and spot. Let’s first take a look at the omni light source case.

Omni Light Sources

First, let’s understand the reason for this name. Omni means “of all things”; in our case, omni has to do with the fact that the light source has no directional variation in intensity, only spatial. Therefore, we can see omni light sources as sources that emanate radiation equally in all directions. See figure 1, which illustrates this fact geometrically.

Figure 1
Figure 1: Omni-Light Source – No directional variation, all light direction vectors L have the same intensity.

Well, we saw the description of how omni lights work; now it is time to see how to represent them. We know that point-light sources don’t have area, so we can leave it behind; we also know that omni-light sources don’t have directional variation, therefore no directional vector will be necessary either. This leaves us with position and color (irradiance in our case). We know that the color can be represented with an RGB vector, very simple; the spatial variation, on the other hand, needs a little more information than only the light position itself: some way to account for the distance of the shaded point from the light source, how the intensity fades with it. We need a falloff function!

Physically speaking, point light sources fall off with the inverse-square law, but in practice we don’t use it; instead, we prefer a different function, but before we talk about why we choose another function, let’s see the reason behind the 1r2\frac{1}{r^2}. It isn’t very hard to prove the inverse-square law for point light sources; it goes as follows (see Figure 2 below): imagine a point light source S emanating radiation radially. If we pick a surface element ω of a sphere centered at S with radius 1 and another sphere also centered at S but with radius r, we can use proportions to see that the area element A on this new sphere is proportional to r2r^2, but the ray density in this direction is constant, therefore the rays through A are the same rays through ω, thus the intensity of the rays is proportional to 1r2\frac{1}{r^2}. See equation 1 for the mathematical definition.

Aω=4πr24π=r2  ⟹  A=r2ω(1) \frac{A}{\omega} = \frac{4\pi r^{2}}{4\pi} = r^{2} \implies A = r^{2}\omega \tag{1}
Figure 1
Figure 2: Inverse-square law: the light intensity falls with 1/r².

Even though we know that the inverse-square law is physically correct for this case, we prefer to use other falloff functions – I say other because there are different variations used in both the real-time and offline worlds. Here we’ll use the same one used in the Real-Time Rendering, Third Edition textbook, which is also used to calculate the linear fog falloff:

f(r)=rmax−rrmax−rmin(2) f(r) = \frac{r_{max} - r}{r_{max} - r_{min}} \tag{2}

This function works as follows (now is a good moment to take a look at Figure 1 again): if you have 2 cutoff distances rminr_{min} and rmaxr_{max}, you can define the falloff function in the following way: if the distance rr is less than rminr_{min}, then the intensity is maximum; if rr is between rminr_{min} and rmaxr_{max}, then use the falloff function above; and last but not least, if rr is greater than rmaxr_{max}, then the intensity is minimum. But what about the WHY? Why use this function instead of the inverse-square law? Well, the first thing is the fact that this function reaches 0 intensity, so we can cut objects after a certain distance, reducing the amount of computation necessary. Another point is overflow: with the inverse-square law we don’t have a maximum value for the intensity, therefore the values could get really big for a very small rr and mess up the computations.

An important tool to always have in our pockets is the notion of approximation: even though sometimes we work out the physics and get the right results, things may just not work out when implementing them. In these kinds of situations we need to make some additional assumptions, while always trying to be as physically correct as possible.

Well, we’re done with omni light sources, but not with point-light sources. Now it is time to discuss spot light sources; it is time to vary intensity with direction! But before we go, take a look at figure 3.

Figure 1
Figure 3: Utah Teapot rendered using the Omni-Light Source.

Spot Light Sources

Enter the spot light! Now it is time to talk about point light sources with directional variation – the ones you see in nearly all metal shows – approximation, remember? Until now we have only looked at intensity variation relative to distance; even though this representation is useful and important, not all light effects can be simulated by it, therefore we need to develop a new mathematical model that accounts for other variations, in our case angular. See the example below:

Figure 1
Figure 4: Spot light.

Actually, there isn’t much ground to cover here; most of the mathematical background is already covered. The point to make is how we can represent the angular variation, and the answer is another falloff function. The idea is the same as before: keep some minimum intensity, use the falloff to vary the intensity between the max and min, and also keep some maximum intensity for the light source.

So, what about this new falloff function? Well, keep an eye on figure 5 while reading the explanation, ok?

Figure 1
Figure 5: Spot-Light Angular variation.

First of all, we’ll assume that the cosine function will only receive input in the interval [0,π][0,π]; this makes total sense given the idea of a spot-light – to direct the light, not radiate it radially as in the omni case! Think of a spot-light if you are having doubts about this. Well, with this point made, we can start the discussion about the falloff function itself. The first things to note are the angles; we have θuθ_u, θpθ_p and θiθ_i:

  • θuθ_u is the umbra angle and it is the cutoff to the minimum – if your angle is greater than it, then you are at minimum intensity.
  • θpθ_p is the penumbra angle, it is the mediator between the maximum and the falloff function. If your angle is greater than θpθ_p and smaller than θuθ_u you are in the falloff, otherwise you’re inside the maximum range.
  • θiθ_i is the guy that varies; it represents the angle between the direction of light’s propagation ss and the light-to-point direction −l-l (pay attention to the minus sign) – this is the classic ll vector we use to compute the diffuse light dot product n^.l^\hat{n}.\hat{l}, but here we invert the direction because we are going from the light to the point (see figure 5).

The last thing we need to take care of before looking at the function is the relation of the cosine function with its input angle. As we all know, the cosine function decreases between 00 and π\pi, therefore the greater the angle the smaller the cosine value. With that fact in mind, we move to the next step.

After all this prelude, we finally look at the falloff (see Equation 3 below). It’s actually a pretty simple function, as it follows the same pattern as equation 2, but now the cutoffs are cosines – remember θpθ_p and θuθ_u! (I leave to the reader the task of putting it all together and making sense of the central part of the equation – the ratio inside, as it is the most important part of understanding its mathematical representation).

f(θi)=(cos⁡θi−cos⁡θucos⁡θp−cos⁡θu)t(3) f(\theta_{i}) = \left( \frac{\cos\theta_{i} - \cos\theta_{u}}{\cos\theta_{p} - \cos\theta_{u}} \right)^{t} \tag{3}

Finally, the tt parameter! Well, tt is actually pretty easy to understand – just remember the classic exponent on the specular Blinn-Phong term. Its main function is to help control the thickness of the ring between the maximum and minimum (Figure 4 can help). The greater tt is, the thinner the ring is. One way to visualize it is as follows: the falloff function is always between 0 and 1, and we all know that if some x is in this interval, x2x^{2} also is, but it isn’t just that. Actually, …<x3<x2<x1\ldots < x^{3} < x^{2} < x^{1}, so the greater tt is, the faster the falloff function reaches the minimum. Take a look at the figure below.

Figure 1
Figure 6: The t parameter variation, from left to right: t = 1, t = 5, t = 10, t = 20.

That is it for point light sources, crew; we have only one more light source to boldly explore before take-off!

Directional Light Sources

Last but not least, the directional light source! This is actually the simplest of the three; we only need a constant vector to represent the light propagation direction l^\hat{l} and an RGB color vector for the irradiance; with this we can already compute directional light sources. The only point I want to make is related to when to use it. Directional light sources come with the following implication: the distance between the shaded point and the light source is greater than the entire scene. That is the same implication as with sunlight, in which the rays can be considered parallel to each other (directional); see the figure below:

Figure 1
Figure 7: An example of directional light source. The sunlight rays can be considered parallel to each other, as they are coming from a distance much greater than the scene itself.

Conclusion

Well, my friend, that is it for today’s post! I hope you have gained some more knowledge about light sources and understood how to use, when to use and why to use them. Also, always keep in mind the trade-off between speed and physical correctness, we must always work together with those two. Right, Realistic and Running! See you in another post, take care!