3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository 3D graphics eBook - Course Materials Repository
Shadow mapping 183 External links • Hardware Shadow Mapping (http:/ / developer. nvidia. com/ attach/ 8456), nVidia • Shadow Mapping with Today's OpenGL Hardware (http:/ / developer. nvidia. com/ attach/ 6769), nVidia • Riemer's step-by-step tutorial implementing Shadow Mapping with HLSL and DirectX (http:/ / www. riemers. net/ Tutorials/ DirectX/ Csharp3/ index. php) • NVIDIA Real-time Shadow Algorithms and Techniques (http:/ / developer. nvidia. com/ object/ doc_shadows. html) • Shadow Mapping implementation using Java and OpenGL (http:/ / www. embege. com/ shadowmapping) Shadow volume Shadow volume is a technique used in 3D computer graphics to add shadows to a rendered scene. They were first proposed by Frank Crow in 1977 [1] as the geometry describing the 3D shape of the region occluded from a light source. A shadow volume divides the virtual world in two: areas that are in shadow and areas that are not. The stencil buffer implementation of shadow volumes is generally considered among the most practical general purpose real-time shadowing techniques for use on modern 3D graphics hardware. It has been popularised by the video game Doom 3, and a particular variation of the technique used in this game has become known as Carmack's Reverse (see depth fail below). Example of Carmack's stencil shadowing in Doom 3. Shadow volumes have become a popular tool for real-time shadowing, alongside the more venerable shadow mapping. The main advantage of shadow volumes is that they are accurate to the pixel (though many implementations have a minor self-shadowing problem along the silhouette edge, see construction below), whereas the accuracy of a shadow map depends on the texture memory allotted to it as well as the angle at which the shadows are cast (at some angles, the accuracy of a shadow map unavoidably suffers). However, the shadow volume technique requires the creation of shadow geometry, which can be CPU intensive (depending on the implementation). The advantage of shadow mapping is that it is often faster, because shadow volume polygons are often very large in terms of screen space and require a lot of fill time (especially for convex objects), whereas shadow maps do not have this limitation. Construction In order to construct a shadow volume, project a ray from the light source through each vertex in the shadow casting object to some point (generally at infinity). These projections will together form a volume; any point inside that volume is in shadow, everything outside is lit by the light. For a polygonal model, the volume is usually formed by classifying each face in the model as either facing toward the light source or facing away from the light source. The set of all edges that connect a toward-face to an away-face form the silhouette with respect to the light source. The edges forming the silhouette are extruded away from the light to construct the faces of the shadow volume. This volume must extend over the range of the entire visible scene; often the dimensions of the shadow volume are extended to infinity to accomplish this (see optimization below.) To form a closed volume, the front and back end of this extrusion must be covered. These coverings are called "caps". Depending on the method used for the shadow volume, the front end may be covered by the object itself, and the rear end may sometimes be omitted (see depth pass below).
Shadow volume 184 There is also a problem with the shadow where the faces along the silhouette edge are relatively shallow. In this case, the shadow an object casts on itself will be sharp, revealing its polygonal facets, whereas the usual lighting model will have a gradual change in the lighting along the facet. This leaves a rough shadow artifact near the silhouette edge which is difficult to correct. Increasing the polygonal density will minimize the problem, but not eliminate it. If the front of the shadow volume is capped, the entire shadow volume may be offset slightly away from the light to remove any shadow self-intersections within the offset distance of the silhouette edge (this solution is more commonly used in shadow mapping). The basic steps for forming a shadow volume are: 1. Find all silhouette edges (edges which separate front-facing faces from back-facing faces) 2. Extend all silhouette edges in the direction away from the light-source 3. Add a front-cap and/or back-cap to each surface to form a closed volume (may not be necessary, depending on the implementation used) Illustration of shadow volumes. The image above at left shows a scene shadowed using shadow volumes. At right, the shadow volumes are shown in wireframe. Note how the shadows form a large conical area pointing away from the light source (the bright white point). Stencil buffer implementations After Crow, Tim Heidmann showed in 1991 how to use the stencil buffer to render shadows with shadow volumes quickly enough for use in real time applications. There are three common variations to this technique, depth pass, depth fail, and exclusive-or, but all of them use the same process: 1. Render the scene as if it were completely in shadow. 2. For each light source: 1. Using the depth information from that scene, construct a mask in the stencil buffer that has holes only where the visible surface is not in shadow. 2. Render the scene again as if it were completely lit, using the stencil buffer to mask the shadowed areas. Use additive blending to add this render to the scene. The difference between these three methods occurs in the generation of the mask in the second step. Some involve two passes, and some only one; some require less precision in the stencil buffer. Shadow volumes tend to cover large portions of the visible scene, and as a result consume valuable rasterization time (fill time) on 3D graphics hardware. This problem is compounded by the complexity of the shadow casting objects,
- Page 137 and 138: Quaternions and spatial rotation 13
- Page 139 and 140: Quaternions and spatial rotation 13
- Page 141 and 142: Quaternions and spatial rotation 13
- Page 143 and 144: Quaternions and spatial rotation 13
- Page 145 and 146: Radiosity 140 Overview of the radio
- Page 147 and 148: Radiosity 142 This is sometimes kno
- Page 149 and 150: Radiosity 144 References [1] " Mode
- Page 151 and 152: Ray casting 146 the light will reac
- Page 153 and 154: Ray tracing 148 Typically, each ray
- Page 155 and 156: Ray tracing 150 independence of eac
- Page 157 and 158: Ray tracing 152 On June 12, 2008 In
- Page 159 and 160: Reflection 154 Reflection Reflectio
- Page 161 and 162: Reflection 156 Glossy Reflection Fu
- Page 163 and 164: Reflection mapping 158 Cube mapping
- Page 165 and 166: Render Output unit 160 Render Outpu
- Page 167 and 168: Rendering 162 • indirect illumina
- Page 169 and 170: Rendering 164 Ray tracing Ray traci
- Page 171 and 172: Rendering 166 Academic core The imp
- Page 173 and 174: Rendering 168 • 1984 Distributed
- Page 175 and 176: Retained mode 170 Retained mode In
- Page 177 and 178: Scanline rendering 172 Comparison w
- Page 179 and 180: Screen Space Ambient Occlusion 174
- Page 181 and 182: Screen Space Ambient Occlusion 176
- Page 183 and 184: Shadow mapping 178 Algorithm overvi
- Page 185 and 186: Shadow mapping 180 Drawing the scen
- Page 187: Shadow mapping 182 Further reading
- Page 191 and 192: Shadow volume 186 The depth fail me
- Page 193 and 194: Silhouette edge 188 Silhouette edge
- Page 195 and 196: Specular highlight 190 Specular hig
- Page 197 and 198: Specular highlight 192 normalized o
- Page 199 and 200: Sphere mapping 194 Sphere mapping I
- Page 201 and 202: Stencil codes 196 Stencil codes Ste
- Page 203 and 204: Stencil codes 198 Stencils The shap
- Page 205 and 206: Stencil codes 200 [7] Wellein, G et
- Page 207 and 208: Subdivision surface 202 used a four
- Page 209 and 210: Subsurface scattering 204 Subsurfac
- Page 211 and 212: Subsurface scattering 206 External
- Page 213 and 214: Surface normal 208 If a (possibly n
- Page 215 and 216: Surface normal 210 Normal in geomet
- Page 217 and 218: Texture filtering 212 Texture filte
- Page 219 and 220: Texture mapping 214 Texture mapping
- Page 221 and 222: Texture mapping 216 constant distan
- Page 223 and 224: Texture synthesis 218 • Structure
- Page 225 and 226: Texture synthesis 220 Pattern-based
- Page 227 and 228: Texture synthesis 222 • Micro-tex
- Page 229 and 230: UV mapping 224 A UV map can either
- Page 231 and 232: Vertex 226 Polytope vertices are re
- Page 233 and 234: Vertex Buffer Object 228 //Make the
- Page 235 and 236: Vertex Buffer Object 230 GLuint sha
- Page 237 and 238: Vertex Buffer Object 232 vertexes *
Shadow volume 184<br />
There is also a problem with the shadow where the faces along the silhouette edge are relatively shallow. In this<br />
case, the shadow an object casts on itself will be sharp, revealing its polygonal facets, whereas the usual lighting<br />
model will have a gradual change in the lighting along the facet. This leaves a rough shadow artifact near the<br />
silhouette edge which is difficult to correct. Increasing the polygonal density will minimize the problem, but not<br />
eliminate it. If the front of the shadow volume is capped, the entire shadow volume may be offset slightly away from<br />
the light to remove any shadow self-intersections within the offset distance of the silhouette edge (this solution is<br />
more commonly used in shadow mapping).<br />
The basic steps for forming a shadow volume are:<br />
1. Find all silhouette edges (edges which separate front-facing faces from back-facing faces)<br />
2. Extend all silhouette edges in the direction away from the light-source<br />
3. Add a front-cap and/or back-cap to each surface to form a closed volume (may not be necessary, depending on<br />
the implementation used)<br />
Illustration of shadow volumes. The image above at left shows a scene shadowed using shadow volumes. At right, the shadow volumes are<br />
shown in wireframe. Note how the shadows form a large conical area pointing away from the light source (the bright white point).<br />
Stencil buffer implementations<br />
After Crow, Tim Heidmann showed in 1991 how to use the stencil buffer to render shadows with shadow volumes<br />
quickly enough for use in real time applications. There are three common variations to this technique, depth pass,<br />
depth fail, and exclusive-or, but all of them use the same process:<br />
1. Render the scene as if it were completely in shadow.<br />
2. For each light source:<br />
1. Using the depth information from that scene, construct a mask in the stencil buffer that has holes only where<br />
the visible surface is not in shadow.<br />
2. Render the scene again as if it were completely lit, using the stencil buffer to mask the shadowed areas. Use<br />
additive blending to add this render to the scene.<br />
The difference between these three methods occurs in the generation of the mask in the second step. Some involve<br />
two passes, and some only one; some require less precision in the stencil buffer.<br />
Shadow volumes tend to cover large portions of the visible scene, and as a result consume valuable rasterization time<br />
(fill time) on <strong>3D</strong> <strong>graphics</strong> hardware. This problem is compounded by the complexity of the shadow casting objects,