shadows in computer graphics - colorado college
TRANSCRIPT
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
Camera
Near
Far
View Plane
H0,0,0L
-z
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
zE W
C C*
D
E = (0, 0, e),C = (x , y , z),C ∗ = (xs , ys)
EW = e,CD = y ,ED = e − z
4EWC ∗ ∼ 4EDC ys =y · ee − z
=y
1− ze
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 verticalline 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
ys =y
1− ze
xs =x
1− ze
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 froma 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:
~v × ~w =
∣∣∣∣∣∣~i ~j ~kx1 y1 z1x2 y2 z2
∣∣∣∣∣∣ =
∣∣∣∣y1 z1y2 z2
∣∣∣∣~i − ∣∣∣∣x1 z1x2 z2
∣∣∣∣~j +
∣∣∣∣x1 y1x2 y2
∣∣∣∣~k
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 17 / 49
Vector Products
v
w
v -w
Θ
Hx1,y1L
Hx2,y2LH0,0L
Dot Product
A
B
A´B
Cross Product
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 18 / 49
Transformations
T~v =
a11 a12 a13a21 a22 a23a31 a32 a33
xyz
=
a11x + a12y + a13za21x + a22y + a23za31x + a32y + a33z
Rotation around z-axis uses this matrix:
Rz =
cos θ − sin θ 0sin θ cos θ 0
0 0 1
Matrices give linear transformations: T (~v + ~w) = T~v + T ~w andT (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) = ( xhwh, yhwh
) be any point on the line 3x + 2y = 7.
=⇒ 3xh + 2yh − 7wh = (3, 2,−7) · (xh, yh,wh) = 0
(xh, yh,wh) are homogeneous coordinates for the point P. Since wh isarbitrary, there are infinitely many sets of homogeneous coordinatesrepresenting 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 byhomogeneous 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 linevectors.
P = (2, 2,−1)× (6,−5, 2) = (−1,−10,−22) is the cross product.
P = (−1,−10,−22) represents the Cartesian point P = ( 122 ,
1022)
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 fourthcoordinate:
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 Plucker coordinates.
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 24 / 49
Perspective Matrix
Now we can express the perspective transformation as a matrixmultiplication:
T (P) = MP =
1 0 0 00 1 0 00 0 0 00 0 −1
e 1
xyz1
=
xy0
1− ze
In the space of homogeneous coordinates (Projective Space), theperspective 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 theoremabout lines.
No concept of length or angle.
Projective transformations are linear transformations.
In 2D, there is a projective transformation that sends a given fourpoints 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
~v ⊗ ~w = ~v ~wT =
vxvyvz
[wx wy wz
]=
vxwx vxwy vxwz
vywx vywy vywz
vzwx vzwy vzwz
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
PP’=T HPL
E
L
Line through E and P is E × P.
T (P) = P ′ = ~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 −4012 2 −106 1 −5
−45 0 0
0 45 00 0 45
=
3 8 −4012 −43 −106 1 −50
T (P) = MP =
3 8 −4012 −43 −106 1 −50
311
=
−23−17−31
Cartesian coordinates for P are (23/31, 17/31).
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 32 / 49
3D Projection
n
P
P’
E
P ′ = αP + βE .
~n · (αP + βE ) = 0 =⇒ α =−β(~n · E )
(~n · P)
P ′ =−β(~n · E )
~n · PP + βE
P ′ = 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)
M = (E ⊗ ~n)− (~n · E )I =
14 −7 14 284 −2 4 8
12 −6 12 242 −1 2 4
−
28 0 0 00 28 0 00 0 28 00 0 0 28
=
−14 −7 14 28
4 −30 4 812 −6 −16 242 −1 2 −24
=⇒ P ′ = (−63,−126, 42,−21)
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 homogeneousrepresentation ~n = (0, 0, 1, 0). The eye point is E = (0, 0, e, 1) andP = (x , y , z , 1).
M =
−e 0 0 00 −e 0 00 0 0 00 0 1 −e
= −e
1 0 0 00 1 0 00 0 0 00 0 −1
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 areinside 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
Camera
View Window
To Light Source
Reflected Ray
v
Steven Janke (Seminar) Shadows in Computer Graphics November 2014 39 / 49
Shadow Ray
Light
P
Shadow
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