Filtered Shadow Maps
One algorithm that allows filtering of the shadow maps generated is Donnelly and Lauritzen’s variance shadow map (VSM) . The algorithm stores the depth in one map and the depth squared in another map. MSAA or other antialiasing schemes can be used when generating the maps. These maps can be blurred, mipmapped, put in summed area tables , or any other method. The ability to treat these maps as filterable textures is a huge advantage, as the entire array of sampling and filtering techniques can be brought to bear when retrieving data from them.
We will describe VSM in some depth here, to give a sense of how this process works; also, the same type of testing is used for all methods in this class of algorithm.
To begin, for VSM the depth map is sampled (just once) at the receiver’s location to return an average depth of the closest light occluder. When this average depth $M_1$, called the first moment, is greater than the depth on the shadow receiver $t$, the receiver is considered fully in light. When the average depth is less than the receiver’s depth, the following equation is used:
\[p_{max}(t)=\frac{\sigma^2}{\sigma^2+(t-M_1)^2}\]where $p_{max}$ is the maximum percentage of samples in light, $\sigma^2$ is the variance, $t$ is the receiver depth, and $M_1$ is the average expected depth in the shadow map. The depthsquared shadow map’s sample $M_2$, called the second moment, is used to compute the variance:
\[\sigma^2=M_2-M_1^2\]The value $p_{max}$ is an upper bound on the visibility percentage of the receiver. The actual illumination percentage $p$ cannot be larger than this value. This upper bound is from the one-sided variant of Chebyshev’s inequality. The equation attempts to estimate, using probability theory, how much of the distribution of occluders at the surface location is beyond the surface’s distance from the light. Donnelly and Lauritzen show that for a planar occluder and planar receiver at fixed depths, $p = p_{max}$, so the equation above can be used as a good approximation of many real shadowing situations.
Myers builds up an intuition as to why this method works. The variance over an area increases at shadow edges. The greater the difference in depths, the greater the variance. The $(t ? M_1)^2$ term is then a significant determinant in the visibility percentage. If this value is just slightly above zero, this means the average occluder depth is slightly closer to the light than the receiver, and $p_{max}$ is then near 1 (fully lit). This would happen along the fully lit edge of the penumbra. Moving into the penumbra, the average occluder depth gets closer to the light, so this term becomes larger and $p_{max}$ drops. At the same time the variance itself is changing within the penumbra, going from nearly zero along the edges to the largest variance where the occluders differ in depth and equally share the area. These terms balance out to give a linearly varying shadow across the penumbra.
One significant feature of variance shadow mapping is that it can deal with the problem of surface bias problems due to geometry in an elegant fashion. Lauritzen gives a derivation of how the surface’s slope is used to modify the value of the second moment. Bias and other problems from numerical stability can be a problem for variance mapping. For example, the Equation subtracts one large value from another similar value. This type of computation tends to magnify the lack of accuracy of the underlying numerical representation. Using floating point textures helps avoid this problem.
Overall VSM gives a noticeable increase in quality for the amount of time spent processing, since the GPU’s optimized texture capabilities are used efficiently. While PCF needs more samples, and hence more time, to avoid noise when generating softer shadows, VSM can work with just a single, high-quality sample to determine the entire area’s effect and produce a smooth penumbra. This ability means that shadows can be made arbitrarily soft at no additional cost, within the limitations of the algorithm.
As with PCF, the width of the filtering kernel determines the width of the penumbra. By finding the distance between the receiver and the closest occluder, the kernel width can be varied, so giving convincing soft shadows. Mipmapped samples are poor estimators of coverage for a penumbra with a slowly increasing width, creating boxy artifacts. Lauritzen details how to use summed-area tables to give considerably better shadows.
One place variance shadow mapping breaks down is along the penumbrae areas when two or more occluders cover a receiver and one occluder is close to the receiver. The Chebyshev inequality from probability theory will produce a maximum light value that is not related to the correct light percentage. The closest occluder, by only partially hiding the light, throws off the equation’s approximation. This results in light bleeding (a.k.a. light leaks), where areas that are fully occluded still receive light. By taking more samples over smaller areas, this problem can be resolved, turning variance shadow mapping into a form of PCF. As with PCF, speed and performance trade off, but for scenes with low shadow depth complexity, variance mapping works well. Lauritzen gives one artist-controlled method to ameliorate the problem, which is to treat low percentages as fully shadowed and to remap the rest of the percentage range to 0% to 100%. This approach darkens light bleeds, at the cost of narrowing penumbrae overall. While light bleeding is a serious limitation, VSM is good for producing shadows from terrain, since such shadows rarely involve multiple occluders .
The promise of being able to use filtering techniques to rapidly produce smooth shadows generated much interest in filtered shadow mapping; the main challenge is solving the various bleeding problems. Annen et al. introduced the convolution shadow map. Extending the idea behind Soler and Sillion’s algorithm for planar receivers , the idea is to encode the shadow depth in a Fourier expansion. As with variance shadow mapping, such maps can be filtered. The method converges to the correct answer, so the light leak problem is lessened.
A drawback of convolution shadow mapping is that several terms need to be computed and accessed, considerably increasing both execution and storage costs . Salvi and Annen et al. concurrently and independently came upon the idea of using a single term based on an exponential function. Called an exponential shadow map (ESM) or exponential variance shadow map (EVSM), this method saves the exponential of the depth along with its second moment into two buffers. An exponential function more closely approximates the step function that a shadow map performs (i.e., in light or not), so this works to significantly reduce bleeding artifacts. It avoids another problem that convolution shadow mapping has, called ringing, where minor light leaks can happen at particular depths just past the original occluder’s depth.
A limitation with storing exponential values is that the second moment values can become extremely large and so run out of range using floating point numbers. To improve precision, and to allow the exponential function to drop off more steeply, z-depths can be generated so that they are linear .
Due to its improved quality over VSM, and its lower storage and better performance compared to convolution maps, the exponential shadow map approach has sparked the most interest of the three filtered approaches. Pettineo notes several other improvements, such as the ability to use MSAA to improve results and to obtain some limited transparency, and describes how filtering performance can be improved with compute shaders.
More recently, moment shadow mapping was introduced by Peters and Klein . It offers better quality, though at the expense of using four or more moments, increasing storage costs. This cost can be decreased by the use of 16-bit integers to store the moments. Pettineo implements and compares this new approach with ESM, providing a code base that explores many variants.
Cascaded shadow-map techniques can be applied to filtered maps to improve precision . An advantage of cascaded ESM over standard cascaded maps is that a single bias factor can be set for all cascades . Chen and Tatarchuk go into detail about various light leak problems and other artifacts encountered with cascaded ESM, and present a few solutions.
Filtered maps can be thought of as an inexpensive form of PCF, one that needs few samples. Like PCF, such shadows have a constant width. These filtered approaches can all be used in conjunction with PCSS to provide variable-width penumbrae . An extension of moment shadow mapping also includes the ability to provide light scattering and transparency effects.