12.4 Distant Lights
Another useful light source type is the distant light, also known as a directional light. It describes an emitter that deposits illumination from the same direction at every point in space. Such a light is also called a point light “at infinity,” since, as a point light becomes progressively farther away, it acts more and more like a directional light. For example, the sun (as considered from Earth) can be thought of as a directional light source. Although it is actually an area light source, the illumination effectively arrives at Earth in parallel beams because it is so far away. The DistantLight, implemented in the files lights/distant.h and lights/distant.cpp, implements a directional source.
Note that the DistantLight constructor does not take a MediumInterface parameter; the only reasonable medium for a distant light to be in is a vacuum—if it was itself in a medium that absorbed any light at all, then all of its emission would be absorbed, since it’s modeled as being infinitely far away.
Some of the DistantLight methods need to know the bounds of the scene. Because lights are created before the scene geometry, these bounds aren’t available when the DistantLight constructor runs. Therefore, DistantLight implements the optional Preprocess() method to get the bound. (This method is called at the end of the Scene constructor.)
Most of the implementation of the Sample_Li() method is straightforward: for a distant light, the incident direction and radiance are always the same. The only interesting bit is the initialization of the VisibilityTester: here, the second point for the shadow ray is set along the distant light’s incident direction a distance of twice the radius of the scene’s bounding sphere, guaranteeing a second point that is outside of the scene’s bounds (Figure 12.14).
The distant light is unusual in that the amount of power it emits is related to the spatial extent of the scene. In fact, it is proportional to the area of the scene receiving light. To see why this is so, consider a disk of area being illuminated by a distant light with emitted radiance where the incident light arrives along the disk’s normal direction. The total power reaching the disk is . As the size of the receiving surface varies, power varies proportionally.
To find the emitted power for a DistantLight, it’s impractical to compute the total surface area of the objects that are visible to the light. Instead, we will approximate this area with a disk inside the scene’s bounding sphere oriented in the light’s direction (Figure 12.15). This will always overestimate the actual area but is sufficient for the needs of code elsewhere in the system.