Practical Shadow Mapping
Stefan Brabec, Thomas Annen, and Hans-Peter Seidel
Max-Planck-Institut fur Informatik
This paper appears in issue Volume 7, Number 4.
Purchase this issue from the akpeters.com web site.
Abstract
We present several techniques that can drastically improve shadow quality, when using the shadow mapping algorithm. Visual artifacts like jagged shadow boundaries or z-fighting are mainly due to insufficient shadow map resolution during the shadow test and/or limited numerical precision. We show how to compute a tight light source viewing frustum, dependent on the current camera setup, such that nearly the full shadow map resolution is available. Furthermore, we recommend linear distribution of depth values instead of perspective depth values.
Author Information
Stefan Brabec, MPI fur informatik, Stuhlsatzenhausweg 8566123 Saarbrücken, Germany brabec@mpii.de
Thomas Annen, MPI Informatik, Stuhlsatzenhausweg 8566123 Saarbrücken, Germany tannen@mpii.de
Hans-Peter Seidel, MPI Informatik, Stuhlsatzenhausweg 8566123 Saarbrücken, Germany hpseidel@mpii.de
Figures
The following images illustrates different stages of our algorithm and show the results (Click on a thumbnail to see a larger image):
![]() |
![]() |
| (a) | (b) |
Figure 1. Distribution of depth values. (a) shows traditional perspective depth values, which are reasonable for camera views, where depth values for near objects are sampled more precise than for objects at large distance. (b) illustrates the proposed linear depth value distribution. This way, all objects are sampled at the same precision which more appropriate for the light source, because most occluders might be located far away from the light source.
![]() |
![]() |
| (a) | (b) |
Figure 2.
Tight fitting near/far setup for a point light source.
Often, near and far
planes are chosen arbitrarily like 0.01 and 1000.0. A better setup is to
set the planes in such a way that the frustum contains all relevant objects.
This setup is shown in (a). Anyway, this is still far away from being optimal.
When using a special texture shader setup (“depth replace” mode,
available on recent NVIDIA graphics cards) we can compress the depth range even
more, as depicted in (b).
Figure 3. Final settings. In the final step in the process of computing an optimal tight light source frustum, we have determine which parts of the scene are visible from the camera. We use projective texturing from the light source and map a control texture to the scene to detect all pixels, as seen from the camera. Reading back this information we can compute a minimum enclosing rectangle, which is then translated and scaled to maximize the resolution for the shadow map generation. Figure 3. illustrates the “Rotating Calipers” algorithm (H. Pirzadeh), which is used to compute the minimum enclosing rectangle in linear time.
![]() |
| (a) |
![]() |
| (b) |
Figure 4. In Figure (a) we demonstrate that the optimization process is dependent on the camera setup. Hence, in this case, the camera can see almost the complete room. This means that the benefit we gain from the optimization is low. The upper right image in (a) illustrates the camera and light source frustum. The lower right image in (a) depicts the visible pixels (blended in red) and the minimum enclosing rectangle.
Figure (b) shows a close camera view towards the plant in the room. The left image is split into the optimized part and the result from traditional shadow mapping to emphasize the difference of visual quality. Upper right image is again the camera and light source setup. The two images on the lower right side show the standard shadow map and the visible pixels. The image beside shows the optimized shadow map.
BibTeX Entry
@article{BrabecAnnenSeidel02,
author = "Stefan Brabec and Thomas Annen and Hans-Peter Seidel",
title = "Practical Shadow Mapping",
journal = "journal of graphics tools",
volume = "7",
number = "4",
pages = "9-18",
year = "2002",
}

![[Thumbnail of Figure 1(a)]](img/depthpsml.png)
![[Thumbnail of Figure 1(b)]](img/depthlsml.png)
![[Thumbnail of Figure 2(a)]](img/nearfarunoptisml.png)
![[Thumbnail of Figure 2(b)]](img/nearfaroptisml.png)
![[Thumbnail of Figure 4(a)]](img/office1sml.png)
![[Thumbnail of Figure 4(b)]](img/office2sml.png)