real-time shadow mapping. shadow mapping shadow mapping uses two-pass rendering - render depth...
TRANSCRIPT
Real-time Real-time Shadow Shadow MappingMapping
Real-time Real-time Shadow Shadow MappingMapping
Shadow Mapping
• Shadow mapping uses two-pass rendering- render depth texture from the light’s point-of-view
- render from the eye’s point-of-view using depth texture
• Completely image-space implementation- no knowledge of scene’s geometry is required
- must deal with aliasing artifacts
First Pass(1)
• The scene is rendered from the light’s point of view into the depth texture
First Pass(2)
• The result is a “depth texture” or “shadow map”- essentially a 2D function indicating the depth of the
closest pixels to the light
Second Pass
• The scene is rendered from the eye’s point of view• For each rasterized fragment
- determine fragment’s XYZ position relative to the light- this light position should be setup to match the frustum
used to create the depth texture- compare the depth value at light position XY in the depth
texture to fragment’s light position Z
Depth Texture Comparison(1)
• Two values- A = Z value from depth texture at fragment’s light XY
position- B = Z value of fragment’s XYZ light position
• If B is greater than A, then there must be something closer to the light than the fragment so the fragment is in shadow
• If A and B are approximately equal,the fragment is lit
Depth Texture Comparison(2)
Depth Texture Comparison(3)
The A < B shadowed fragment case
Depth Texture Comparison(4)
The A = B shadowed fragment case
Using Projective Texturing(1)
Using Projective Texturing(2)
• Normal 2D texture mapping uses (s, t) coordinates• Now consider homogeneous texture coordinates
- r/q holds the distance from the light - (s, t, r, q) --> (s/q, t/q, r/q)- similar to homogeneous clip coordinates where
(x, y, z, w) = (x/w, y/w, z/w)
• Next compare texture value at (s/q, t/q) to value r/q- if texture[s/q, t/q] r/q then not shadowed - if texture[s/q, t/q] < r/q then shadowed
Ambient Shadows
• Improvement for completely black shadows
Near and Far planes
• Distance between near and far planes should be minimized for better precision of Z value
Z-Fighting
• Problem take place when eye space pixel coordinates are transformed into light space to get the respective depth texture samples due to machine rounding errors in this stage
Aliasing Problems
• There is still the problem of aliasing
Summary
Implementation
• First pass uses the OpenSceneGraph library which based on OpenGL
• Second pass is done by hardware using cg and glsl language shaders