3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for...

57
3D Polygon Rendering Pipeline Michael Kazhdan (601.457/657) HB Ch. 12 FvDFH Ch. 6, 18.3

Transcript of 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for...

Page 1: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Polygon Rendering Pipeline

Michael Kazhdan

(601.457/657)

HB Ch. 12

FvDFH Ch. 6, 18.3

Page 2: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Polygon Rendering• Many applications use (interactive) rendering of

3D polygons with direct illumination

Page 3: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Polygon Rendering• Many applications use (interactive) rendering of

3D polygons with direct illumination

God of War(Santa Monica Studio, 2018)

Page 4: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Ray Casting• For each sample:

Construct ray from the camera into the scene Find first surface intersected by ray through pixel Compute color of sample based on surface radiance

⇓ Send 2D pixels into the scene and get color

Page 5: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Polygon Rendering• For each primitive:

Send 3D points to the camera and set the pixel color

Page 6: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

3D Model

2D Image

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Page 7: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Transform into 3D world coordinate system

Page 8: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transform into 3D camera coordinate system

3D Rendering Pipeline (for direct illumination)

Transform into 3D world coordinate system

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Page 9: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Illuminate vertices using lighting and reflectance

3D Rendering Pipeline (for direct illumination)

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Page 10: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

Transform into 2D camera coordinate system

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Illuminate vertices using lighting and reflectance

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Page 11: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

Clip (parts of) primitives outside camera’s view

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Transform into 2D camera coordinate system

Illuminate vertices using lighting and reflectance

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Page 12: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

Clip (parts of) primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate vertices using lighting and reflectance

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Transform into 2D image coordinate system

Page 13: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

Draw pixels (includes texturing, hidden surface, etc.)

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Clip (parts of) primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate vertices using lighting and reflectance

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Transform into 2D image coordinate system

Page 14: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion Draw pixels (includes texturing, hidden surface, etc.)

Clip (parts of) primitives outside camera’s view

Transform into 2D camera coordinate system

Illuminate vertices using lighting and reflectance

Transform into 3D camera coordinate system

Transform into 3D world coordinate system

Transform into 2D image coordinate system

Page 15: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Recall: Homogeneous Coordinates• Add a 4th coordinate to every 3D point

(𝑥𝑥,𝑦𝑦, 𝑧𝑧,𝑤𝑤) represents a point at location 𝑥𝑥𝑤𝑤

, 𝑦𝑦𝑤𝑤

, 𝑧𝑧𝑤𝑤

(𝑥𝑥,𝑦𝑦, 𝑧𝑧, 0) represents a (directed) point at infinity (0, 0, 0,0) is not allowed

Page 16: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Recall: 3D Transformations• Using homogenous coordinates, we have two

types of transformations: Affine

𝑥𝑥′𝑦𝑦′𝑧𝑧′1

=

𝑎𝑎 𝑏𝑏 𝑐𝑐 𝑑𝑑𝑒𝑒 𝑓𝑓 𝑔𝑔 ℎ𝑖𝑖 𝑗𝑗 𝑘𝑘 𝑙𝑙0 0 0 1

𝑥𝑥𝑦𝑦𝑧𝑧1

Projective𝑥𝑥′𝑦𝑦′𝑧𝑧′𝑤𝑤′

=

𝑎𝑎 𝑏𝑏 𝑐𝑐 𝑑𝑑𝑒𝑒 𝑓𝑓 𝑔𝑔 ℎ𝑖𝑖 𝑗𝑗 𝑘𝑘 𝑙𝑙𝑚𝑚 𝑛𝑛 𝑜𝑜 𝑝𝑝

𝑥𝑥𝑦𝑦𝑧𝑧𝑤𝑤

Page 17: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

Transformations map points from one coordinate system to another

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)3D World

Coordinates

3D CameraCoordinates

3D ObjectCoordinates

x

z

y

Page 18: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

}Model-view Transformations

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)

Page 19: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)

Page 20: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Viewing Transformation• Canonical coordinate system

Convention is right-handed (looking down −𝑧𝑧 axis) Convenient for projection, clipping, etc.

3D WorldCoordinates

3D CameraCoordinates

Camera Right

Camera Up

𝑥𝑥

𝑦𝑦

𝑧𝑧Camera Back

Page 21: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Viewing Transformation• The transformation, 𝑇𝑇𝑊𝑊→𝐶𝐶, taking us from world

coordinates to camera coordinates should map: The right vector to the 𝑥𝑥-axis:

𝑅𝑅𝑥𝑥 ,𝑅𝑅𝑦𝑦,𝑅𝑅𝑧𝑧, 0 → (1,0,0,0) The up vector to the 𝑦𝑦-axis:

𝑈𝑈𝑥𝑥,𝑈𝑈𝑦𝑦,𝑈𝑈𝑧𝑧, 0 → (0,1,0,0) The back vector to the 𝑧𝑧-axis:

𝐵𝐵𝑥𝑥 ,𝐵𝐵𝑦𝑦,𝐵𝐵𝑧𝑧, 0 → (0,0,1,0) The eye position to the origin:

𝐸𝐸𝑥𝑥,𝐸𝐸𝑦𝑦,𝐸𝐸𝑧𝑧, 1 → (0,0,0,1)

How should we define this transformation/matrix?

Page 22: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Viewing Transformation• Consider the inverse transformation, 𝑇𝑇𝐶𝐶→𝑊𝑊, taking

us from camera coordinates to world coordinates:𝑅𝑅𝑥𝑥 ,𝑅𝑅𝑦𝑦,𝑅𝑅𝑧𝑧, 0 ← (1,0,0,0)𝑈𝑈𝑥𝑥,𝑈𝑈𝑦𝑦,𝑈𝑈𝑧𝑧, 0 ← (0,1,0,0)𝐵𝐵𝑥𝑥 ,𝐵𝐵𝑦𝑦,𝐵𝐵𝑧𝑧, 0 ← (0,0,1,0)𝐸𝐸𝑥𝑥,𝐸𝐸𝑦𝑦,𝐸𝐸𝑧𝑧, 1 ← (0,0,0,1)

• This is described by the matrix:𝑥𝑥𝑤𝑤𝑦𝑦𝑤𝑤𝑧𝑧𝑤𝑤1

=

𝑅𝑅𝑥𝑥 𝑈𝑈𝑥𝑥 𝐵𝐵𝑥𝑥 𝐸𝐸𝑥𝑥𝑅𝑅𝑦𝑦 𝑈𝑈𝑦𝑦 𝐵𝐵𝑦𝑦 𝐸𝐸𝑦𝑦𝑅𝑅𝑧𝑧 𝑈𝑈𝑧𝑧 𝐵𝐵𝑧𝑧 𝐸𝐸𝑧𝑧0 0 0 1

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

𝑇𝑇𝐶𝐶→𝑊𝑊

Page 23: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Finding the Viewing Transformation• The camera-to-world matrix:

𝑥𝑥𝑤𝑤𝑦𝑦𝑤𝑤𝑧𝑧𝑤𝑤1

=

𝑅𝑅𝑥𝑥 𝑈𝑈𝑥𝑥 𝐵𝐵𝑥𝑥 𝐸𝐸𝑥𝑥𝑅𝑅𝑦𝑦 𝑈𝑈𝑦𝑦 𝐵𝐵𝑦𝑦 𝐸𝐸𝑦𝑦𝑅𝑅𝑧𝑧 𝑈𝑈𝑧𝑧 𝐵𝐵𝑧𝑧 𝐸𝐸𝑧𝑧0 0 0 1

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

• The world-to-camera matrix is its inverse:

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

=

𝑅𝑅𝑥𝑥 𝑈𝑈𝑥𝑥 𝐵𝐵𝑥𝑥 𝐸𝐸𝑥𝑥𝑅𝑅𝑦𝑦 𝑈𝑈𝑦𝑦 𝐵𝐵𝑦𝑦 𝐸𝐸𝑦𝑦𝑅𝑅𝑧𝑧 𝑈𝑈𝑧𝑧 𝐵𝐵𝑧𝑧 𝐸𝐸𝑧𝑧0 0 0 1

−1 𝑥𝑥𝑤𝑤𝑦𝑦𝑤𝑤𝑧𝑧𝑤𝑤1

𝑇𝑇𝐶𝐶→𝑊𝑊

𝑇𝑇𝑊𝑊→𝐶𝐶 = 𝑇𝑇𝐶𝐶→𝑊𝑊−1

Page 24: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)

Page 25: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Projection• General definition:

A linear transformation of points in 𝑛𝑛-space to 𝑚𝑚-space (𝑚𝑚 < 𝑛𝑛)

• In computer graphics: Map 3D camera coordinates to 2D screen

coordinates

Page 26: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FvDFH Figure 6.13

Page 27: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Projection• Two general classes of projections, both of which

shoot rays from the scene, through the view plane: Parallel Projection:

» Rays converge at a point at infinity and are parallel Perspective “Projection”:

» Rays converge at a finite point, giving rise to perspective distortion

View Plane View Plane

Page 28: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FvDFH Figure 6.13

Page 29: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Parallel Projection

Angel Figure 5.4

• Center of projection is at infinity Direction of projection (DoP) same for all points

DOP

ViewPlane

Page 30: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Parallel ProjectionParallel lines remain parallel

Relative proportions of objects preserved

Angles are not preserved

Less realistic looking

Page 31: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FvDFH Figure 6.13

Page 32: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Orthographic Projections

Angel Figure 5.5Top

Side Front

• DoP perpendicular to view plane

Isometric

Page 33: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Orthographic Projections

Angel Figure 5.5Top

Side Front

• DoP perpendicular to view plane

Isometric

• Lines perpendicular to the view plane vanish

• Faces parallel to the view plane are un-distorted.

Page 34: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Orthographic Projections• DoP perpendicular to view plane

Maps a point in 3D space to the (𝑥𝑥,𝑦𝑦)-plane, through the origin, by projecting out the 𝑧𝑧-component:

𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 → 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 0 In terms of the matrix representation:

𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠0

=1 0 00 1 00 0 0

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐

(0,0,0) 𝑧𝑧−𝑧𝑧

𝑦𝑦

View Plane

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐)

Page 35: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Orthographic Projections• DoP perpendicular to view plane

Maps a point in 3D space to the (𝑥𝑥,𝑦𝑦)-plane, through the origin, by projecting out the 𝑧𝑧-component:

𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 → 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 0 In terms of the matrix representation:

𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠0

=1 0 00 1 00 0 0

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐

Or, in homogenous coordinates:𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠01

=

1 0 0 00 1 0 00 0 0 00 0 0 1

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

Page 36: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FvDFH Figure 6.13

Page 37: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Oblique Projections

H&B Figure 12.21

• DoP not perpendicular to view plane

• 𝜙𝜙 is the angle of the projection of the view plane’s normal

• 𝐿𝐿 is the scale factor applied to the view plane’s normal

Cavalier(DoP 𝛼𝛼 = 45∘)

Cabinet(DoP 𝛼𝛼 = 63.4∘)

1

11

1

11/2

𝜙𝜙 = 45∘𝐿𝐿 = 1

𝜙𝜙 = 45∘𝐿𝐿 = 1/2

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 1)

(𝑥𝑥,𝑦𝑦)

𝑥𝑥𝑠𝑠 ,𝑦𝑦𝑠𝑠 = 𝐿𝐿(cos𝜙𝜙, sin𝜙𝜙)

𝜙𝜙

𝐿𝐿

𝑧𝑧

𝑥𝑥

𝑦𝑦

Page 38: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Parallel Projection Matrix

H&B Figure 12.21

• General parallel projection transformation:

1

11

1

11/2

Cavalier(DoP 𝛼𝛼 = 45∘)

Cabinet(DoP 𝛼𝛼 = 63.4∘)

𝜙𝜙 = 45∘𝐿𝐿 = 1

𝜙𝜙 = 45∘𝐿𝐿 = 1/2

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 1)

(𝑥𝑥,𝑦𝑦)

𝑥𝑥𝑠𝑠 ,𝑦𝑦𝑠𝑠 = 𝐿𝐿(cos𝜙𝜙, sin𝜙𝜙)

𝜙𝜙

𝐿𝐿

𝑧𝑧

𝑥𝑥

𝑦𝑦

𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠01

=

1 0 𝐿𝐿 cos𝜙𝜙 00 1 𝐿𝐿 sin𝜙𝜙 00 0 0 00 0 0 1

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

Page 39: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Parallel Projection Matrix

H&B Figure 12.21

• General parallel projection transformation:

1

11

1

11/2

Cavalier(DoP 𝛼𝛼 = 45∘)

Cabinet(DoP 𝛼𝛼 = 63.4∘)

𝜙𝜙 = 45∘𝐿𝐿 = 1

𝜙𝜙 = 45∘𝐿𝐿 = 1/2

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 1)

(𝑥𝑥,𝑦𝑦)

𝑥𝑥𝑠𝑠 ,𝑦𝑦𝑠𝑠 = 𝐿𝐿(cos𝜙𝜙, sin𝜙𝜙)

𝜙𝜙

𝐿𝐿

𝑧𝑧

𝑥𝑥

𝑦𝑦

𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠01

=

1 0 𝐿𝐿 cos𝜙𝜙 00 1 𝐿𝐿 sin𝜙𝜙 00 0 0 00 0 0 1

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

Note:This matrix represents an affine transformation

Page 40: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Parallel Projection View Volume

H&B Figure 12.30

Page 41: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FVFHP Figure 6.10

Page 42: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective “Projection”

Angel Figure 5.9

• Map points onto “view plane” along “projectors” emanating from “center of projection” (CoP)

Center ofProjection

View Plane

Page 43: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection

Angel Figure 5.10

3-PointPerspective

2-PointPerspective

1-PointPerspective

• How many vanishing points?

Number of vanishing pointsdetermined by number of axes

parallel to the view plane

𝑥𝑥 𝑥𝑥𝑥𝑥

𝑦𝑦𝑦𝑦 𝑦𝑦

𝑧𝑧

𝑧𝑧𝑧𝑧

Page 44: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection• Not all parallel lines remain parallel!

Page 45: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection• What are the coordinates of the point resulting

from projection of 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 onto the view plane a unit distance along the 𝑧𝑧-axis?

(0,0,0)𝑧𝑧

𝑦𝑦

1

View Plane

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐)

Page 46: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection• For any point 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 and any scalar 𝛼𝛼, the

points 𝑥𝑥𝑐𝑐 , 𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 and 𝛼𝛼𝑥𝑥𝑐𝑐 ,𝛼𝛼𝑦𝑦𝑐𝑐 ,𝛼𝛼𝑧𝑧𝑐𝑐 map to the same location.

(0,0,0)𝑧𝑧

𝑦𝑦

1

View Plane

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐)

(2𝑥𝑥𝑐𝑐 , 2𝑦𝑦𝑐𝑐 , 2𝑧𝑧𝑐𝑐)

Page 47: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection• For any point 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 and any scalar 𝛼𝛼, the

points 𝑥𝑥𝑐𝑐 , 𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 and 𝛼𝛼𝑥𝑥𝑐𝑐 ,𝛼𝛼𝑦𝑦𝑐𝑐 ,𝛼𝛼𝑧𝑧𝑐𝑐 map to the same location.

• Since we want the position on the view plane that intersect the line from 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 to the origin:

𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 →𝑥𝑥𝑐𝑐

𝑧𝑧𝑐𝑐,𝑦𝑦𝑐𝑐

𝑧𝑧𝑐𝑐, 1

(0,0,0)𝑧𝑧

𝑦𝑦

1

View Plane

(𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐)

Page 48: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection Matrix

𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 →𝑥𝑥𝑐𝑐

𝑧𝑧𝑐𝑐,𝑦𝑦𝑐𝑐

𝑧𝑧𝑐𝑐, 1

We can’t represent this with a 3 × 3 matrix!

With homogenous coordinates, we can write this as:

𝑥𝑥𝑐𝑐 , 𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 , 1 →𝑥𝑥𝑐𝑐

𝑧𝑧𝑐𝑐,𝑦𝑦𝑐𝑐

𝑧𝑧𝑐𝑐, 1,1 ≡ 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 , 𝑧𝑧𝑐𝑐

In matrix form, this gives:𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠11

1 0 0 00 1 0 00 0 1 00 0 1 0

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

Page 49: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection Matrix

𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 →𝑥𝑥𝑐𝑐

𝑧𝑧𝑐𝑐,𝑦𝑦𝑐𝑐

𝑧𝑧𝑐𝑐, 1

We can’t represent this with a 3 × 3 matrix!

With homogenous coordinates, we can write this as:

𝑥𝑥𝑐𝑐 , 𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 , 1 →𝑥𝑥𝑐𝑐

𝑧𝑧𝑐𝑐,𝑦𝑦𝑐𝑐

𝑧𝑧𝑐𝑐, 1,1 ≡ 𝑥𝑥𝑐𝑐 ,𝑦𝑦𝑐𝑐 , 𝑧𝑧𝑐𝑐 , 𝑧𝑧𝑐𝑐

In matrix form, this gives:𝑥𝑥𝑠𝑠𝑦𝑦𝑠𝑠11

1 0 0 00 1 0 00 0 1 00 0 1 0

𝑥𝑥𝑐𝑐𝑦𝑦𝑐𝑐𝑧𝑧𝑐𝑐1

Note:This matrix represents a projective transformation

Page 50: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective Projection View Volume

H&B Figure 12.30

ViewPlane

Page 51: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Taxonomy of Projections

FVFHP Figure 6.10

Page 52: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Classical Projections

Angel Figure 5.3

Page 53: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Perspective vs. Parallel• Perspective projectionSize varies inversely with distance - looks realisticAngles are preserved on faces

parallel to the view plane Distance are not preserved

• Parallel projectionGood for exact measurementsParallel lines remain parallelAngles and distance are preserved

on faces parallel to the view plane Less realistic looking

Page 54: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

𝑣𝑣𝑥𝑥1 𝑣𝑣𝑥𝑥2𝑣𝑣𝑦𝑦1

𝑣𝑣𝑦𝑦2

𝑤𝑤𝑥𝑥1 𝑤𝑤𝑥𝑥2𝑤𝑤𝑦𝑦1

𝑤𝑤𝑦𝑦2Window Viewport

Screen Coordinates Image Coordinates

(𝑤𝑤𝑥𝑥,𝑤𝑤𝑦𝑦) (𝑣𝑣𝑥𝑥 , 𝑣𝑣𝑦𝑦)

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)

𝑉𝑉 = viewport transform

𝑉𝑉 =1 0 𝑣𝑣𝑥𝑥1

0 1 𝑣𝑣𝑥𝑥20 0 1

𝑣𝑣𝑥𝑥2 − 𝑣𝑣𝑥𝑥1

𝑤𝑤𝑥𝑥2 − 𝑤𝑤𝑥𝑥10 0

0𝑣𝑣𝑦𝑦2 − 𝑣𝑣𝑦𝑦1

𝑤𝑤𝑦𝑦2 − 𝑤𝑤𝑦𝑦10

0 0 1

1 0 −𝑤𝑤𝑥𝑥1

0 1 −𝑤𝑤𝑦𝑦1

0 0 1

Note that this may scale non-uniformly.

Page 55: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

3D Rendering Pipeline (for direct illumination)

3D Model2D Screen

ModelingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

(𝑥𝑥,𝑦𝑦, 𝑧𝑧)

(𝑥𝑥′,𝑦𝑦′)

Page 56: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations𝑁𝑁

𝐿𝐿1

𝐿𝐿2

𝑉𝑉

Viewer

𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿

𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿

3D Model2D Screen

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion

Page 57: 3D Polygon Rendering Pipelinemisha/Fall20/12.pdf · 2020. 10. 2. · 3D Rendering Pipeline (for direct illumination) Clip (parts of) primitives outside camera’s view. Transform

Transformations

3D Model2D Screen

}Vertex processing• Originally, vertex processing was fixed• On modern cards this can be programmed in the

vertex shader

Lighting

ViewingTransformation

3D Primitives

ModelingTransformation

ProjectionTransformation

Clipping

Image

ViewportTransformation

ScanConversion