Shadows in Computer Graphics
Steven Janke
November 2014
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 1 / 49 Shadows (from Doom)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 2 / 49 Simple Shadows
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 3 / 49 Shadows give position information
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 4 / 49 Shadow Geometry
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 5 / 49 Camera Model
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 6 / 49 View Frustum
Far Near -z
Camera
H0,0,0L View Plane
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 7 / 49 Ideal City (circa 1485)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 8 / 49 Perspective Projection
y
* C C
E W z D
∗ E = (0, 0, e), C = (x, y, z), C = (xs , ys )
EW = e, CD = y, ED = e − z
∗ y · e y 4EWC ∼ 4EDC ys = = z e − z 1 − e
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 9 / 49 Albrecht Durer (Man drawing a Lute - 1525)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 10 / 49 Alberti Perspective Diagram
1. Draw lines from front tile corners to center point C. 2. Select point R on horizontal line so CR is distance to painting. 3. Connect R with front tile corners. 4. Draw horizontal lines through intersections of lines in 3 and vertical line through C. 5. Diagonals through tiles are projected into diagonals.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 11 / 49 Pedro Berreuguete - Anunciation (circa 1500)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 12 / 49 Masaccio - Trinity (1426)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 13 / 49 Calculating Cube Perspective
y x ys = z xs = z 1 − e 1 − e
Example (Cube Vertices) Eye Coordinates: (0,0,4) World Coordinates:
(1, 1, 1), (1, −1, 1), (−1, −1, 1), (−1, 1, 1) (1, 1, −1), (1, −1, −1), (−1, −1, −1), (−1, 1, −1)
Screen Coordinates:
(1.33, 1.33), (1.33, −1.33), (−1.33, −1.33), (−1.33, 1.33) (0.75, 0.75), (0.75, −0.75), (−0.75, −0.75), (−0.75, 0.75)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 14 / 49 Cubes in Perspective
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 15 / 49 Projections
Summary Perspective projections and Shadow projections are both projections from a point onto a plane.
Next steps: For shadows, we generalize projection to arbitrary plane. Describe calculations compactly and efficiently.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 16 / 49 Vectors
~v = (x1, y1, z1) and w~ = (x2, y2, z2) are displacements.
Algebra: ~v + w~ = (x1 + x2, y1 + y2, z1 + z2) and a~v = (ax1, ay1, az1).
Dot Product: ~v · w~ = |~v||w~ |cos(θ) = x1x2 + y1y2 + z1z2. (If ~v and w~ are perpendicular, then ~v · w~ = 0.) Cross Product:
~i ~j ~k y1 z1 ~ x1 z1 ~ x1 y1 ~ ~v × w~ = x1 y1 z1 = i − j + k y2 z2 x2 z2 x2 y2 x2 y2 z2
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 17 / 49 Vector Products
Hx1,y1L A ´ B
v v - w B
Θ w H0,0L Hx2,y2L A Dot Product
Cross Product
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 18 / 49 Transformations
a11 a12 a13 x a11x + a12y + a13z T~v = a21 a22 a23 y = a21x + a22y + a23z a31 a32 a33 z a31x + a32y + a33z Rotation around z-axis uses this matrix: cos θ − sin θ 0 Rz = sin θ cos θ 0 0 0 1
Matrices give linear transformations: T (~v + w~ ) = T~v + T w~ and T (a~v) = aT~v Cannot represent translations or projections.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 19 / 49 Homogeneous Coordinates
The point P0 = (−1, 5) is on the 2D line 3x + 2y = 7. The vector equation of the line:
(3, 2) · (P − P0) = (3, 2) · (x + 1, y − 5) = 0
Let P = (x, y) = ( xh , yh ) be any point on the line 3x + 2y = 7. wh wh
=⇒ 3xh + 2yh − 7wh = (3, 2, −7) · (xh, yh, wh) = 0
(xh, yh, wh) are homogeneous coordinates for the point P. Since wh is arbitrary, there are infinitely many sets of homogeneous coordinates representing P. For example,
P0 = (−1, 5, 1) = (−2, 10, 2) = (−0.5, 2.5, 0.5)
Two-dimensional Homogeneous Line equation: ~n · P = 0
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 20 / 49 Homogeneous Coordinates for Lines
Example (2D Line coordinates)
P1 = (3, 2, 1) and P2 = (5, 7, 3) determine a two-dimensional line. ~n · (3, 2, 1) = 0 and ~n · (5, 7, 3) = 0. ~n = (3, 2, 1) × (5, 7, 3) = (−1, −4, 11) The homogeneous coordinates (−1, −4, 11) represent the line.
Both points and lines in two dimensions can be represented by homogeneous coordinates (x, y, w).
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 21 / 49 Calculating with Homogeneous Coordinates
Example (2D Intersection Point) Consider two lines: (2, 2, −1) and (6, −5, 2) (They represent the lines 2x + 2y − 1 = 0 and 6x − 5y + 2 = 0) P is the point of intersection. (2, 2, −1) · P = 0 and (6, −5, 2) · P = 0 P must be a vector perpendicular to the two homogeneous line vectors. P = (2, 2, −1) × (6, −5, 2) = (−1, −10, −22) is the cross product. 1 10 P = (−1, −10, −22) represents the Cartesian point P = ( 22 , 22 )
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 22 / 49 Points at Infinity
Lines 2x + 4y − 8 = 0 and 2x + 4y − 10 = 0 are parallel.
The homogeneous point (4, −2, 0) is on both lines.
Points of the form (xh, yh, 0) are points at infinity.
Notice that (4, −2, 0) and (5, 3, 0) are distinct points at infinity.
Points in 2D
Points at Infinity
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 23 / 49 Homogeneous Coordinates in Three Dimensions
Homogeneous coordinates for three dimensional points add a fourth coordinate:
Cartesian (x, y, z) =⇒ Homogeneous (x, y, z, 1) or (tx, ty, tz, t)
Since planes are determined by a normal and a point, (tx, ty, tz, t) also represents a plane. Homogeneous plane equation: ~n · P = 0 Lines have homogeneous coordinates called Pl¨ucker coordinates.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 24 / 49 Perspective Matrix
Now we can express the perspective transformation as a matrix multiplication:
1 0 0 0 x x 0 1 0 0 y y T (P) = MP = = 0 0 0 0 z 0 1 z 0 0 − e 1 1 1 − e
In the space of homogeneous coordinates (Projective Space), the perspective transformation is a linear function.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 25 / 49 Perspective Drawing
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 26 / 49 Two Point Perspective
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 27 / 49 Projective Geometry
Girard Desargues (1591 - 1661) was the founding father.
Parallel lines intersect in a point at infinity: (xh, yh, 0) Points at infinity fall on a line. Duality: In 2D, for any theorem about points there is a theorem about lines. No concept of length or angle. Projective transformations are linear transformations. In 2D, there is a projective transformation that sends a given four points to another specified four points.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 28 / 49 Desargues Theorem
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 29 / 49 Additional Vector Algebra
Tensor Product vx vx wx vx wy vx wz T ~v ⊗ w~ = ~vw~ = vy wx wy wz = vy wx vy wy vy wz vz vz wx vz wy vz wz
Vector Triple Product
A~ × (B~ × C~ ) = (A~ · C~ )B~ − (A~ · B~ )C~
Dot to Tensor (A~ · C~ )B~ = (B~ ⊗ A~ )C~
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 30 / 49 2D Projection
L
E P’=THPL P
Line through E and P is E × P.
T (P) = P0 = ~L × (E × P) = (~L · P)E − (~L · E)P = ((E ⊗ ~L) − (~L · E)I )P = MP
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 31 / 49 2D Projection
Example Project P = (3, 1) onto the line 6x + y − 5 = 0 from the point (8, 2).
~L = (6, 1, −5) E = (8, 2, 1) P = (3, 1, 1)
M = (E ⊗ ~L) − (~L · E)I 48 8 −40 45 0 0 3 8 −40 = 12 2 −10 − 0 45 0 = 12 −43 −10 6 1 −5 0 0 45 6 1 −50
3 8 −40 3 −23 T (P) = MP = 12 −43 −10 1 = −17 6 1 −50 1 −31 Cartesian coordinates for P are (23/31, 17/31).
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 32 / 49 3D Projection
E
P
n 0 P’ P = αP + βE.
−β(~n · E) ~n · (αP + βE) = 0 =⇒ α = (~n · P) −β(~n · E) P0 = P + βE ~n · P
P0 = T (P) = (~n · P)E − (~n · E)P = (E ⊗ ~n)P − (~n · E)P =⇒ M = (E ⊗ ~n) − (~n · E)I
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 33 / 49 3D Projection
Example Eye point: E = (7, 2, 6) Vertex: P = (4, 5, 0) Plane: 2x − y + 2z = −4
~n = (2, −1, 2, 4) E = (7, 2, 6, 1) P = (4, 5, 0, 1)
14 −7 14 28 28 0 0 0 4 −2 4 8 0 28 0 0 M = (E ⊗ ~n) − (~n · E)I = − 12 −6 12 24 0 0 28 0 2 −1 2 4 0 0 0 28 −14 −7 14 28 4 −30 4 8 0 = =⇒ P = (−63, −126, 42, −21) 12 −6 −16 24 2 −1 2 −24
This gives Cartesian coordinates (3, 6, −2) Steven Janke (Seminar) Shadows in Computer Graphics November 2014 34 / 49 Compare to earlier 3D matrix
M = (E ⊗ ~n) − (~n · E)I Perspective projection: Viewing plane is the xy plane with homogeneous representation ~n = (0, 0, 1, 0). The eye point is E = (0, 0, e, 1) and P = (x, y, z, 1).
−e 0 0 0 1 0 0 0 0 −e 0 0 0 1 0 0 M = = −e 0 0 0 0 0 0 0 0 1 0 0 1 −e 0 0 − e 1
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 35 / 49 Shadow Geometry
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 36 / 49 Points in Shadow
Shadow: Fill in the polygon determined by projected vertices.
For convex objects, shadows are convex.
Vertices that are not incident on both visible and hidden faces are inside the shadow.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 37 / 49 Multiple Shadows
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 38 / 49 Ray Tracing
To Light Source Camera v
View Window
Reflected Ray
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 39 / 49 Shadow Ray
Light
Shadow P
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 40 / 49 Soft Shadows
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 41 / 49 Penumbra & Umbra
Light
Object
Umbra
Penumbra Penumbra
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 42 / 49 More Soft Shadows
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 43 / 49 Multiple Lights
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 44 / 49 Shadow Volume
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 45 / 49 More Multiple Lights
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 46 / 49 Further Refinements
Shadow Maps
Curves (NURBS)
Complex Lighting Models (Radiosity)
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 47 / 49 Complex Shadows
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 48 / 49 Reference (2015
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 49 / 49