Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward...

23
Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel

Transcript of Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward...

Projection Matrices

CS4395: Computer Graphics 1

Mohan SridharanBased on slides created by Edward Angel

Objectives

• Derive the projection matrices used for standard OpenGL projections.

• Introduce oblique projections.

• Introduce projection normalization.

CS4395: Computer Graphics 2

Projection Normalization

• Convert all projections to orthogonal projections with the default view volume.

• The same pipeline of operations for all types of projections

• Clip against simple cube regardless of type of projection.• Simplifies clipping because sides of the object are aligned

with coordinate axes.

• Delay final projection until end: important for hidden-surface removal.

CS4395: Computer Graphics 3

Projection Normalization

• Work in 4D using homogeneous coordinates.

• Convert all projections into orthogonal projections:– Distort objects such that the orthogonal projection of distorted

objects is the same as desired projection of original objects.

• Concatenation of normalization matrix (for distortion) and orthogonal projection matrix yields desired homogeneous coordinate matrix.

CS4395: Computer Graphics 4

Pictorial Representation

CS4395: Computer Graphics 5

Pipeline View

CS4395: Computer Graphics 6

modelviewtransformation

projectiontransformation

perspective division

clipping projection

nonsingular

4D 3D

against default cube 3D 2D

Stay in 4D coordinates for both the modelview and projection transformations (nonsingular transformations).

Orthogonal Normalization

glOrtho(left,right,bottom,top,near,far)

CS4395: Computer Graphics 7

Normalization find transformation to convert specified clipping volume to default.

Orthogonal Matrix

• Two steps:– Move center to origin:

T(-(left + right)/2, -(bottom + top)/2, (near + far)/2))

– Scale to have sides of length 2:S(2/(right-left), 2/(top-bottom), 2/(near-far))

CS4395: Computer Graphics 8

1000

200

02

0

002

nearfar

nearfar

farnear

bottomtop

bottomtop

bottomtop

leftright

leftright

leftright

P = ST =

Final Projection

• Set z =0

• Equivalent to the homogeneous coordinate transformation:

• General orthogonal projection in 4D:

CS4395: Computer Graphics 9

1000

0000

0010

0001

Morth =

P = MorthST

Oblique Projections

• The OpenGL projection functions cannot produce general parallel projections such as:

• However the cube it appears to have been sheared.• Oblique Projection = Shear + Orthogonal Projection!

CS4395: Computer Graphics 10

General Shear

side view

CS4395: Computer Graphics 11

top view

Shear Matrix

• For x-y shear (z values unchanged):

• Projection matrix:• General case: • See Section 5.8.

CS4395: Computer Graphics 12

1000

0100

0φcot10

0θcot01

H(,) =

P = Morth H(,)

P = Morth STH(,)

Equivalency

CS4395: Computer Graphics 13

Effect on Clipping

• Projection matrix P = STH transforms the original clipping volume to the default clipping volume.

CS4395: Computer Graphics 14

top view

DOPDOP

near plane

far plane

object

clippingvolume

z = -1

z = 1

x = -1x = 1

distorted object(projects correctly)

Simple Perspective

• Consider a simple perspective : COP at origin, the near clipping plane at z = -1, and a 90o field of view determined by planes: x = z, y = z.

CS4395: Computer Graphics 15

Perspective Matrices

• Simple projection matrix in homogeneous coordinates:

• This matrix is independent of the far clipping plane.

CS4395: Computer Graphics 16

0100

0100

0010

0001

M =

Generalization (Section 5.9)

N =

CS4395: Computer Graphics 17

0100

βα00

0010

0001• Perspective normalization matrix:

• After perspective division, the point (x, y, z, 1) goes to:

• Orthogonal projection to the desired point regardless of

and .

)("

/"

/"

zz

zyy

zxx

Picking and

CS4395: Computer Graphics 18

=

=

nearfar

farnear

farnear

farnear2

• If we pick:

• The near plane is mapped to z = -1• The far plane is mapped to z =1• The sides are mapped to x = 1, y = 1• The new clipping volume is the default volume.

Normalization Transformation

CS4395: Computer Graphics 19

original object new clipping volume

distorted objectprojects correctly

original clipping volume

Normalization and Hidden-Surface Removal

• The perspective projection matrices are chosen such that if z1 > z2 in the original clipping volume then for the transformed points: z1’ > z2’

• Thus hidden surface removal works if the normalization transformation is applied first.

• However, the formula z’’ = -(+ /z) implies that the distances are distorted by the normalization which can cause numerical problems if the near distance is small.

CS4395: Computer Graphics 20

OpenGL Perspective

• Function glFrustum allows for an un-symmetric viewing frustum (although gluPerspective does not).

CS4395: Computer Graphics 21

OpenGL Perspective Matrix• The normalization in glFrustum requires an initial shear to

form a right viewing pyramid, followed by a scaling to get the normalized perspective volume. Finally, the perspective matrix needs only a orthogonal transformation:

• See Section 5.9.2.

CS4395: Computer Graphics 22

P = NSH

previously defined perspective matrix

shear and scale

N =

0100

βα00

0010

0001

Recap: Why do we do it this way?

• Normalization allows for a single pipeline for both perspective and orthogonal viewing.

• Stay in 4D homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading.

• Simplifies clipping.

CS4395: Computer Graphics 23