Tigue 2004

Introduction

Shadows are an important component in rendering realistic images in computer graphics. Important visual cues are given to the eye by shadow casting. However, rendering realistic shadows in real time is an expensive operation. Consequently, most real time applications use alternatives such as shadow maps, or avoid shadows completely. Applications that do not use shadows often sacrifice visual realism. Contemporary real time applications (Doom 3, Half Life 2) utilize a technique known as shadow volume determination to render shadow geometry. As a result, complex realistic scenes are rendered in real time.

Significance

Shadows enhance the realism in real-time scenes. A viewer of a scene relies upon shadows in order to determine information about light sources and objects including depth perception and light intensity cues (Hu, et. al 2002). Therefore, it is important to be able to render shadows in real time applications in order to enhance the immersive makeup of a particular environment. Moreover, shadows allow more flexibility in light models. Previous applications often rely on static lights so that the shadows did not have to be rendered per frame. Allow dynamic lighting makes more possible in real time applications such as the movement of the sun, or the use of a flashlight or torch. Moving lights also adds more interest to scene and allows the application to direct the attention of the user’s eyes. Per frame determination of shadows provides flexible and realistic scenes.

Background

Because of the dynamic nature of shadows, they are inherently difficult to render in real-time computer graphics applications. Because objects are shifting position and orientation within a scene, new shadow volumes must be determined per frame. Many real time applications use alternatives in order to avoid these per frame calculations. A common alternative is light maps. Light mapping is the application of a light texture to scene objects. All of the shadow determination is pre-computed and the light maps are rendered using multiple passes. However, light maps can only be applied to static objects such as walls. Moreover, the actual light sources are not allowed to change. Implementing realistic shadow volumes is an important step in real-time application’s advancement. Recent advancements in hardware have made realistic per frame shadow determination viable. Shadow volumes are determined per object for every light source. For a given light source, the edges of the shadow volume are determined. All edges with one polygon front-facing the light source, and the other polygon back-facing the light source, establish the shadow volume. McGuire, et al, refer to these edges as the possible silhouette, since some edges may be on the interior of the true silhouette (2003). The points from the silhouette are extruded to infinity along the vector of the light source. Directional light sources are at infinity, so the silhouette is extruded along parallel vectors. Point light sources cause the shadow volume to expand away from the light Tigue 2004 source (Barequet et al, 2001). The entire volume is the light cap, consisting of the light facing possible silhouette, the dark cap, or the extruded possible silhouette, and the sides, consisting of the faces connecting the two caps (McGuire et al, 2003). Any point within this volume is in shadow, and consequently is not illuminated by the light source. Heidmann suggested a method using the stencil buffer in order to determine if a point is within a shadow volume(1991). The stencil buffer is a bit buffer that can be incremented or decremented when a polygon is rendered onto it. Heidmann would draw the faces of the shadow volume (from the extruded silhouette) to determine which areas of the scene are in shadow. Shadow volume faces pointing towards the user would increment the buffer, and faces pointing away would decrement the user. The stencil buffer pixels that are non-zero are in shadow. A depth test is then committed on the scene to determine the polygons in shadow. The depth test can be done from the point to the user, known as a z-pass method because it is within the viewing frustrum, or from infinity, known as a z-fail method. The first published approach to shadow volumes was by Frank Crow in 1977. Tim Heidmann released an article discussing the use of a stencil buffer to determine which pixels were in shadow (1991). John Carmack is credited with a method for overcoming near and far clip anomalies (2000). Lengyel compiled a completed algorithm for shadow volume rendering (2002). Everitt and Kilgard released articles on the NVIDIA website discussing the use of the stencil buffer for shadow rasterization (2002, 2003). McGuire, Hughes, and Egan with help from Everitt and Kilgard produced an extensive paper describing shadow volumes and added several optimizations (2003). Finally, Brabec and Seidel recently published a method for determining and rendering shadow volumes in hardware (2003).

Problem

The problem included an investigation of rendering shadow-volumes in real time. This included implementing a small 3d engine capable of showing dynamic light sources and objects. A dynamic scene is necessary in order to display the effects for the shadow volumes. The scene must include both point light sources and directional light sources to show the different extrusions of shadow volumes. The more important details of the problem space included actual code implementation of shadow volumes. This included determining object silhouettes relative to a given light source, the extrusion of a silhouette and determination of a shadow volume, and finally the rendering of the shadow volumes using the stencil buffer and depth buffer. Another important detail of the problem space is overcoming near and far clipping plane anomalies. These occur when the view point enters into a shadow volume and can be overcome by switching the z-pass method (Carmack 2001). Finally, I wanted the engine to be robust. This meant handling infinite shadow volume extrusion. Many non-robust systems render the shadow within a box to avoid these calculations. However, I wanted to be able to determine the shadow volumes for any scene.

Methodology Tigue 2004

Initially, I needed to load a scene including objects and light sources. Because the calculations needed silhouette determination, I loaded the objects into an edge table. This allowed a quick derivation of a silhouette because the outline is formed by edges with one polygon facing a light source and another polygon facing away from a light source. Because the silhouette determination occurred for every object per light source in every frame, the calculation is quick in order to be a real time application. After a silhouette is determined for an object, the silhouette needs to be extruded. The vertices need to be extruded to infinite so that the light cap and dark cap for the shadow volume can be determined. The extrusion can be done in hardware using a vertex shader. The Gamasutra website offers a Cg version of this extrusion so that the rendering is fast. Of course, this relies upon hardware that is able to support the vertex shader. In my implementation, I relied upon the software in order to determine and extrude the silhouette. To do so, I converted all the object points in to world space and compared them to a given light vector. This allowed me to determine the light facing and back facing polygons on each object, thus producing the silhouette. Rather than extending my vertices to infinite, I simply extended them to a large distance away from the light source. This is done by finding the normalized vector pointing from the light source to a model vector and multiplying it by a large extrusion number. Once the shadow volume is determined it needs to be rendered in the stencil buffer. I first render the scene with only ambient colors turned on. This also sets the depth values in the depth buffer. I then render the shadow volumes with the stencil buffer turned on and the depth and color buffer turned off. I then render the shadow volume geometry for the objects. If the object is front facing it increments the stencil buffer, and if it is back facing it decrements the stencil buffer. A comparison is made to the depth buffer, so that the stencil buffer is set on zfail. The result is non zero values where a shadow is found. When the scene is rendered again into the color buffer with all the lights turned on, the stencil buffer omits the shadowed region, and the shadow region is only drawn with ambient lighting.

Results

I was able to display shadows with dynamic lighting effects given an arbitrary light source. This included both point light sources and dynamic light sources. I was also able to have a moving light source that showed a moving shadow effect for every scene. Figure 1 shows the scene rendered with a directional light source to the left of center. This results in a shadow volume extrusion to the right from both the cubes. Since it is a directional light, the shadows extrude out in parallel lines which can also be seen in the figure. Figure 2 shows the scene rendered with a point light source. The point light source is centered between the two cubes. This results in a projection of the shadow out opposite ends of each cube. Point light sources have shadow volumes that extrude out from in vectors passing through the light source position and the object vertices. This results in larger shadows as the point light gets closer to the object. In the demonstration, I have the point light moving to show the shadow volume difference as the light source gets closer to the rotating cubes. Tigue 2004

Unfortunately, there were also some poor results of the demonstration. Because I did not use the accumulation buffer, I received z-fighting artifacts. The artifacts can be seen in both figures.

Figure 1. Shadows extruded from a directional light source. The white outline is the actual shadow volume. The lines on the cubes are the light cap triangles. The dark cap is drawn at some large point beyond the scene. Also note the artifacts due to z-fighting on the shadow and the cubes. Tigue 2004

Figure 2. The scene rendered with a point light source in between the two cubes. Note the projection of the shadows is larger than for the directional light. The projection gets larger as the point light gets closer to the object. The z fighting can also be seen here.

Future Work There are several methods I could use to improve the project. Initially, I would make use of OpenGL’s vertex shader extensions to extrude the silhouette vertices. This would improve the performance of the demonstration tremendously because it would remove the need to convert the vertices into world space manually. Consequently, all vertex calculations could take place in hardware. A second extension would be to use the accumulation buffer. Not only would this remove the z-fighting artifacts from the demonstration, but would allow multiple light sources. Currently the demonstration only shows one light source at a time. McGuire recommends use of the accumulation buffer to show multiple shadow volumes from multiple light sources (2003). Another possible improvement is in the silhouette determination. Kilgard has showed that the bulk of the computation is from determining which edges are silhouette edges. A possible way of speeding this up is to implement something similar to a BSP tree for the objects. Although it would require more memory, it could be used to quickly determine silhouette edges for an arbitrary light source, speeding up the shadow volume process. Tigue 2004

References

Barequet, G. C.A Duncan, M. T. Goodrich, W. Huang, S. Kumar, M. Pop. “Efficient Perspective-Accurate Silhouette Computation” Proc. 17. Annual. ACM Symposium on Computational Geometry, Medford, MA, pp. 60-68, June 2001.

Brabec, S. and Seidel, H. “Shadow Volumes on Programmable Graphics Hardware”, Eurographics 2003.

Carmack, J. May 2001. E-mail Published on NVIDIA website: http://developer.nvidia.com/docs/IO/2585/ATT/CarmackonShadowVolumes.txt

Crow, F. C., “Shadow Algorithms for Computer Graphics”, Computer Graphics (SIGGRAPH ’77 Proceedings), vol 11., no2., pp 242-248, July 1977.

Everitt, C. and Kilgard, M. J., “Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering.” NVIDIA Corporation, Austin, TX, March 12, 2002. Retrieved from website: http://developer.nvidia.com/view.asp? IO=robust_shadow_volumes

Everitt, C. and Kilgard, M. J., “Optimized Stencil Shadow Volumes.” Slides from Game Developer Conference, San Jose, March, 2003. Retrieved from website: http://developer.nvidia.com/docs/IO/4449/SUPP/GDC2003_ShadowVolumes.pdf

Heidmann, Tim. “Real Shadows, Real Time” Iris Universe, No. 18, p. 23-31, Silicon Graphics Inc., November 1991.

Hu, Helen, and Amy Gooch, Sarah Creem-Regehr, William Thompson. “Visual Cues for Perceiving Distance from Surfaces to Objects.” Presence: Teleporters and Virtual Environments, v11 i6, December 2002.

Lengyel, E.. “The Mechanics of Robust Stencil Shadows.” Gamasutra, October 11, 2002. Retrieved from website: http://www.gamasutra.com/features/20021011/lengyel_01.htm

McGuire, Morgan, and John F. Hughes, Kevin T. Egan, Mark J. Kilgard, Cass Everitt. “Fast, Practical and Robust Shadows” NVIDIA Corporation, Austin, TX, November 6, 2003. Retrieved from website: http://developer.nvidia.com/fast_shadow_volumes.html