shadows in computer graphics - colorado college

49
Shadows in Computer Graphics Steven Janke November 2014 Steven Janke (Seminar) Shadows in Computer Graphics November 2014 1 / 49

Upload: others

Post on 14-Nov-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Shadows in Computer Graphics - Colorado College

Shadows in Computer Graphics

Steven Janke

November 2014

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 1 / 49

Page 2: Shadows in Computer Graphics - Colorado College

Shadows (from Doom)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 2 / 49

Page 3: Shadows in Computer Graphics - Colorado College

Simple Shadows

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 3 / 49

Page 4: Shadows in Computer Graphics - Colorado College

Shadows give position information

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 4 / 49

Page 5: Shadows in Computer Graphics - Colorado College

Shadow Geometry

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 5 / 49

Page 6: Shadows in Computer Graphics - Colorado College

Camera Model

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 6 / 49

Page 7: Shadows in Computer Graphics - Colorado College

View Frustum

Camera

Near

Far

View Plane

H0,0,0L

-z

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 7 / 49

Page 8: Shadows in Computer Graphics - Colorado College

Ideal City (circa 1485)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 8 / 49

Page 9: Shadows in Computer Graphics - Colorado College

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

Page 10: Shadows in Computer Graphics - Colorado College

Albrecht Durer (Man drawing a Lute - 1525)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 10 / 49

Page 11: Shadows in Computer Graphics - Colorado College

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

Page 12: Shadows in Computer Graphics - Colorado College

Pedro Berreuguete - Anunciation (circa 1500)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 12 / 49

Page 13: Shadows in Computer Graphics - Colorado College

Masaccio - Trinity (1426)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 13 / 49

Page 14: Shadows in Computer Graphics - Colorado College

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

Page 15: Shadows in Computer Graphics - Colorado College

Cubes in Perspective

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 15 / 49

Page 16: Shadows in Computer Graphics - Colorado College

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

Page 17: Shadows in Computer Graphics - Colorado College

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

Page 18: Shadows in Computer Graphics - Colorado College

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

Page 19: Shadows in Computer Graphics - Colorado College

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

Page 20: Shadows in Computer Graphics - Colorado College

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

Page 21: Shadows in Computer Graphics - Colorado College

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

Page 22: Shadows in Computer Graphics - Colorado College

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

Page 23: Shadows in Computer Graphics - Colorado College

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

Page 24: Shadows in Computer Graphics - Colorado College

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

Page 25: Shadows in Computer Graphics - Colorado College

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

Page 26: Shadows in Computer Graphics - Colorado College

Perspective Drawing

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 26 / 49

Page 27: Shadows in Computer Graphics - Colorado College

Two Point Perspective

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 27 / 49

Page 28: Shadows in Computer Graphics - Colorado College

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

Page 29: Shadows in Computer Graphics - Colorado College

Desargues Theorem

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 29 / 49

Page 30: Shadows in Computer Graphics - Colorado College

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

Page 31: Shadows in Computer Graphics - Colorado College

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

Page 32: Shadows in Computer Graphics - Colorado College

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

Page 33: Shadows in Computer Graphics - Colorado College

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

Page 34: Shadows in Computer Graphics - Colorado College

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

Page 35: Shadows in Computer Graphics - Colorado College

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

Page 36: Shadows in Computer Graphics - Colorado College

Shadow Geometry

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 36 / 49

Page 37: Shadows in Computer Graphics - Colorado College

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

Page 38: Shadows in Computer Graphics - Colorado College

Multiple Shadows

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 38 / 49

Page 39: Shadows in Computer Graphics - Colorado College

Ray Tracing

Camera

View Window

To Light Source

Reflected Ray

v

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 39 / 49

Page 40: Shadows in Computer Graphics - Colorado College

Shadow Ray

Light

P

Shadow

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 40 / 49

Page 41: Shadows in Computer Graphics - Colorado College

Soft Shadows

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 41 / 49

Page 42: Shadows in Computer Graphics - Colorado College

Penumbra & Umbra

Light

Object

Umbra

Penumbra Penumbra

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 42 / 49

Page 43: Shadows in Computer Graphics - Colorado College

More Soft Shadows

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 43 / 49

Page 44: Shadows in Computer Graphics - Colorado College

Multiple Lights

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 44 / 49

Page 45: Shadows in Computer Graphics - Colorado College

Shadow Volume

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 45 / 49

Page 46: Shadows in Computer Graphics - Colorado College

More Multiple Lights

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 46 / 49

Page 47: Shadows in Computer Graphics - Colorado College

Further Refinements

Shadow Maps

Curves (NURBS)

Complex Lighting Models (Radiosity)

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 47 / 49

Page 48: Shadows in Computer Graphics - Colorado College

Complex Shadows

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 48 / 49

Page 49: Shadows in Computer Graphics - Colorado College

Reference (2015

Steven Janke (Seminar) Shadows in Computer Graphics November 2014 49 / 49