II Light Maps

•Light maps • Simulates the effect of a local light source •Environment Maps

• Projective Textures += • Bump Maps • Displacement Maps • Solid Textures • Can be pre-computed and dynamically •Mipmaps adapted •Shadows 1 2

7. Texture Mapping 7. Texture Mapping

Light Maps Environment Map

• Texture mapping in Quake

3 4

textures only textures and light maps 7. Texture Mapping 7. Texture Mapping Environment Map Examples – Environment Map

• Method to render reflective objects (θ,φ) • Compute intersection of reflected ray with n surrounding sphere • Take parameter values of intersection as texture coordinates

5 6

7. Texture Mapping 7. Texture Mapping

Environment Map Cube Mapping

• How to get an environment map of a real • Sphere can be replaced by cube environment? • Simplify computations

7 8

7. Texture Mapping 7. Texture Mapping Cube Map Demo Linear Mapping

• Uses object or eye coordinates • (In)dependent of transforms • Can be used to visualize distance from objects y

-x

z-z

9 10 http://developer.nvidia.com/object/cube_map_ogl_tutorial.html 7. Texture Mapping x 7. Texture Mapping

An Example Projective Textures

• Mapping of distances from laser range data • Generalize texture coordinates to a 4D homogeneous vector (u, v, r, q) • Texture matrix computes full 4x4 transform to (up, vp) used for texture lookup • Texture image can be projected independently of viewing projection • Applications: – Slide projector – Spotlight simulation 11 12

7. Texture Mapping 7. Texture Mapping Projection Examples

Polygon

Screen Texture

Eye 13 14

7. Texture Mapping 7. Texture Mapping

Examples

• Adding surface detail without adding geometry • Perturbation of surface normal • Details interact with light • Bumps are small compared to geometry • Bump pattern is taken from a (texture-) map • Can also be procedural (fractals)

15 16

Ö movie 7. Texture Mapping 7. Texture Mapping Bump Mapping Bump Mapping

• Given a surface p(u,v) and • Partial derivatives at point p’ p a perturbation value b (Jim Blinn) ’ ∂p' ∂p ∂ (bn) b = + ∂p ∂p ∂u ∂u ∂u n n = × = p ×p p ∂u ∂v u v Bump •Point p’ on the bumpy surface pattern • Perturbed normal approximated by (see Blinn) bn p' = p + n' = n + b (n×p )+ b (n×p ) n u u v v • Compute normal at Point p’

∂p' ∂p' 17 18 n' = × ∂u ∂v 7. Texture Mapping 7. Texture Mapping

Bump Mapping Examples

• Discretization using Finite Differences b(u ,v )− b(u ,v )+ b(u ,v )− b(u ,v ) b = 2 1 1 1 2 2 1 2 u 2 ∆u b(u ,v )− b(u ,v )+ b(u ,v )− b(u ,v ) b = 1 2 1 1 2 2 2 1 v 2 ∆v

b(u1 ,v2) b(u2 ,v2)

∆v Sphere w/Diffuse Texture Swirly Bump Map Sphere w/Diffuse Texture & Bump Map

19 20 b(u1 ,v1) ∆u b(u2 ,v1) 7. Texture Mapping 7. Texture Mapping Examples Bump Mapping

•What’s missing? – Bumps on silhouette – Self-occlusion – Self-shadowing

Bump Map

Cylinder w/Diffuse Texture Map Cylinder w/Texture Map & Bump Map

21 22

Ö movie 7. Texture Mapping 7. Texture Mapping

Displacement Mapping

• Use the texture map to displace the geometry Image from: Geometry Caching for Ray-Tracing Displacement Maps by Matt Pharr and Pat Hanrahan.

note the detailed shadows cast by the stones

23 24

7. Texture Mapping 7. Texture Mapping Solid Textures Perlin Noise

•3D bitmaps •Procedural textures

25 26

7. Texture Mapping 7. Texture Mapping

Mip-Mapping Texture Interpolation

• Minimized textures produce aliasing effects • Compute texture value (R,G,B) as function of (u,v,z) • Store texture at multiple levels-of-detail • Tri-linear interpolation •Usesmaller versions when far from camera • MIP comes from the Latin multum in parvo, meaning a multitude in a small space. v

v v

u u u 27 z 28 without mipmap with mipmap mipmap z 7. Texture Mapping 7. Texture Mapping Computation of the Mip Map Shadows

• Why are shadows important? –Depth cue – Scene lighting – Realism – Contact points

• Color = weighted average of nearby pixels (filter) •See gluBuild2DMipMaps() 29 30

from Fredo Durand’s graphics class… Ö demo 7. Texture Mapping 7. Texture Mapping

Shadows as a Depth Cue For Intuition about Scene Lighting

• Position of the light (e.g. sundial) • Hard shadows vs. soft shadows • Directional light vs. point light

31 32

7. Texture Mapping 7. Texture Mapping Cast Shadows on Planar Surfaces Limitations of Planar Shadows

• Draw the object primitives a second time, • Does not produce self-shadows, shadows cast projected to the ground plane on other objects, shadows on curved surfaces, etc.

33 34

7. Texture Mapping 7. Texture Mapping

Fake Shadows using Projective Shadow/View Duality Textures

• A point is lit if it is • Separate obstacle and receiver visible from the light • Compute b/w image of obstacle from light source • Use image as projective texture for each receiver

Image from light source BW image of obstacle Final image

• Shadow computation similar to view computation

35 36

7. Texture Mapping Figure from Moller & Haines “Real Time Rendering” 7. Texture Mapping Projective Texture Shadow Shadow Maps Limitations

• Must specify occluder & receiver • In Renderman (High-end production software) •No self-shadows • In Games (GPUs) • Resolution

Image from light source BW image of obstacle Final image

37 38

Figure from Moller & Haines “Real Time Rendering” 7. Texture Mapping 7. Texture Mapping

Shadow Mapping Shadow Map Look Up

• Texture mapping with • We have a 3D point (x,y,z)WS depth information • How do we look up •Requires 2 passes the depth from the through the pipeline: shadow map? (x',y',z')LS (x,y,z)WS – Compute shadow • Use the 4x4 map (depth from perspective projection light source) matrix from the light – Render final image, check shadow map source to get (x',y',z')LS to see if points are • ShadowMap(x',y') < z'? Foley et al. “Computer Graphics Principles and Practice” Foley et al. “ Principles and Practice” in shadow

39 40

7. Texture Mapping 7. Texture Mapping Limitations of Shadow Maps 1. Field of View Problem

1. Field of View • What if point to shadow is outside 2. Bias (Epsilon) field of view of 3. Aliasing shadow map? – Use cubical shadow map –Use only spot lights! Foley et al. “Computer Graphics Principles and Practice” Foley et al. “Computer Graphics Principles and Practice”

41 42

7. Texture Mapping 7. Texture Mapping

2. The Bias (Epsilon) Nightmare 2. Bias (Epsilon) for Shadow Maps

• For a point visible • ShadowMap(x’,y’) + bias < z’ from the light • Choosing a good bias value can be very tricky source ShadowMap(x’,y’) ≈ z’

•How can we avoid erroneous self-shadowing? Foley et al. “Computer Graphics Principles and Practice” – Add bias (epsilon) Correct image Not enough bias Way too much bias 43 44

7. Texture Mapping 7. Texture Mapping 3. Shadow Map Aliasing 3. Shadow Map Filtering

• Under-sampling of the shadow map • Should we filter the depth? • Reprojection aliasing – especially bad when the (weighted average of neighboring depth camera & light are opposite each other values) • No... filtering depth is not meaningful

45 46

7. Texture Mapping 7. Texture Mapping

3. Percentage Closer Filtering 3. Percentage Closer Filtering

• Instead filter the result of the test •5x5 samples (weighted average of comparison results) • Nice antialiased • But makes the bias issue more tricky shadow • Using a bigger filter produces fake soft shadows • Setting bias is tricky 47 48

7. Texture Mapping 7. Texture Mapping Projective Texturing + Shadow Map Shadows in Production

•Often use shadow maps • Ray casting as fallback in case of robustness issues

Light’s View Depth/Shadow Map Eye’s View

Images from Cass Everitt et al., “Hardware Shadow Mapping” NVIDIA SDK White Paper 49 50

7. Texture Mapping 7. Texture Mapping

Hardware Shadow Maps Shadow Volumes

• Can be done with hardware texture mapping • Explicitly represent the volume – Texture coordinates u,v,w generated using 4x4 of space in shadow matrix •For each polygon – Modern hardware permits tests on texture values – Pyramid with point light as apex – Include polygon to cap •Shadow test similar to clipping

51 52

7. Texture Mapping 7. Texture Mapping Shadow Volumes Shadow Volumes

• If a point is inside a shadow • Shoot a ray from the eye to volume cast by a particular light, the visible point the point does not receive any • Increment/decrement a illumination from that light counter each time we intersect a shadow • Cost of naive volume polygon -1 +1 implementation: • If the counter ≠ 0, +1 #polygons * #lights the point is in shadow

53 54

7. Texture Mapping 7. Texture Mapping

Optimizing Shadow Volumes Limitations of Shadow Volumes

• Use silhouette edges only (edge where • Introduces a lot of new geometry a back-facing & front-facing polygon meet) • Expensive to rasterize long skinny triangles • Objects must be watertight to use silhouette trick L • Rasterization of polygons sharing an edge must not overlap & must not have gap A

55 56

7. Texture Mapping 7. Texture Mapping Homework

57 58

7. Texture Mapping 7. Texture Mapping