Download Projective Textures and Shadow Maps: A Comprehensive Lecture on 3D Rendering Techniques - and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!
Lecture 11: Projective Textures and Shadow Maps
Prof. Aaron Lanterman
School of Electrical and Computer Engineering
Georgia Institute of Technology
2
What is projective texturing?
• An intuition for projective texturing
– The slide projector analogy
Source: Source: WolfgangWolfgang HeidrichHeidrich [99][99]
From Stanford CS448A: Real-Time Graphics Architectures lecture 11; see graphics.stanford.edu/courses/cs448a-01-fall
4
Texture matrix
s
t
r
q
Light
Frustrum
( projection )
Matrix
Light
View
( lookat )
Matrix
Modeling
Matrix
x 0 y 0 z 0 w 0
From “The Cg Tutorial,” p. 252.
5
Projective texturing vertex shader
void C9E4v_projTexturing( float4 position : POSITION,
float3 normal : NORMAL,
out float4 oPosition : POSITION,
out float4 texCoordProj : TEXCOORD0,
out float4 diffuseLighting : TEXCOORD1,
uniform float Kd, uniform float4x4 modelViewProj,
uniform float3 lightPosition,
uniform float4x4 textureMatrix)
oPosition = mul (modelViewProj, position);
// Compute texture coordinates for
// querying the projective texture
texCoordProj = mul (textureMatrix, position);
// Compute diffuse lighting
float3 N = normalize (normal);
float3 L = normalize (lightPosition - position.xyz);
diffuseLighting = Kd * max ( dot (L, N), 0);
From “The Cg Tutorial”
7
Watch out for reverse projection!
Images from C. Everitt, “Projective Texture Mapping,” developer.nvidia.com/object/Projective_Texture_Mapping.html
8 A dramatic shadow in 2K Games’ BioShock From www.wired.com/gaming/gamingreviews/multimedia/2007/08/pl_bioshock?slide=16&slideView=
10
The shadow mapping concept (2)
• Shadow determination with the depth map
– Second, render scene 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 map
• compare the depth value at light position XY in
the depth map to fragment’s light position Z
Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/
11
The shadow mapping concept (3)
• The Shadow Map Comparison
– Two values
• A = Z value from depth map 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
• then the fragment is shadowed
– If A and B are approximately equal, the
fragment is lit
Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/
13
Shadow mapping with a picture in 2D (2)
light
source
eye
position
depth map Z = A
fragment’s
light Z = B
depth map image plane
eye view image plane,
a.k.a. the frame buffer
The A The A ≅≅ B unshadowed fragment caseB unshadowed fragment case
Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/
14
Shadow mapping with a picture in 2D (3)
Note image precision mismatch! Note image precision mismatch!
The depth map The depth map
could be at a could be at a
different resolution different resolution
from the framebuffer from the framebuffer
This mismatch can This mismatch can
lead to artifacts lead to artifacts
Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/
16
- Compare with and without shadows with shadows with shadows without shadowswithout shadows Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/ Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/ Visualizing the shadow mapping technique (2)
17
- The scene from the light’s point-of-view FYI: from the FYI: from the eye eye’’s point-of-views point-of-view again again Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/ Visualizing the shadow mapping technique (3)
19
- Projecting the depth map onto the eye’s view FYI: depth map for FYI: depth map for light light’’s point-of-views point-of-view again again Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/ Visualizing the shadow mapping technique (5)
20
- Projecting light’s planar distance onto eye’s view Slide from C. Everitt, “Shadow Mapping,” Powerpoint presentation, developer.nvidia.com/attach/ Visualizing the shadow mapping technique (6)