






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







10/16/2008 1
Juraj Obert [email protected] http://graphics.cs.ucf.edu/cap4720/fall2008/
Original algorithm PCF Variance shadow maps …
Stencil pass Stencil fail (also called John Carmack’s shadows ;)
10/16/2008 3
light source (^) shadow map
Shadow mapping determines whether a fragment is in shadow by comparing two depth values of the same fragment:
Depth of the fragment when rendered from a light’s point of view
Depth of the fragment when rendered from camera’s point of view, but transformed using the light’s view and projection matrices
10/16/2008 7
// pass these down from vertex shader varying vec3 positionEye; varying vec4 positionClip; void main() { // eye space depth gl_FragColor = vec4(vec3(1.0, 1.0, 1.0) * positionEye.z, 1.0); // clip space depth gl_FragColor = vec4(vec3(1.0, 1.0, 1.0) * positionClip.z / positionClip.w, 1.0); }
10/16/2008 9
x
y
w
1
A (x, y, w)
A’(x/w, y/w, 1)
Transformation of a point in 3D homogenous coordinates is in fact its projection on a plane w units away from origin
This can be generalized to higher dimensions
A (x, y, z, w) -> A’(x/w, y/w, z/w, 1)
A’(x’, y’, z’) -> A (x, y, z, 1)
10/16/2008 13
Shadow mapping shader code
overview
Vertex shader
Compute vertex position in light space (projection space of the light, i.e. light’s modelview matrix times render target’s projection matrix)
Shadow mapping shader code
overview
Fragment shader
Convert fragment’s light space position to texture space Light space has same dimensions as general clip space (<-1, +1> x <-1, +1> x <-1, +1>) Texture coordinates are in <0.0, 1.0> x <0.0, 1.0>
10/16/2008 15
Shadow mapping shader code
overview
Fragment shader
Sample depthMap at computed coordinates This will return fragment’s eye space (or clip space) distance as viewed from light’s location
if (sampled > computed) we’re in shadow else we’re not in shadow
Shadow mapping shader code
overview
Fragment shader
Compare computed fragment’s light space z value with sampled z value
10/16/2008 19
Hard shadow edges in shadow mapping
for (int u = -2; u < 2; u++) for (int v = -2; v < 2; v++) tex2D (baseUV + texelSizes*(u,v))
10/16/2008 21
Softer edges
Render target resolution dependency