+ All Categories
Home > Documents > Lecture 07: perspective projection - Utrecht University projection Perspective projection...

Lecture 07: perspective projection - Utrecht University projection Perspective projection...

Date post: 15-Mar-2018
Category:
Upload: nguyenthu
View: 247 times
Download: 6 times
Share this document with a friend
64
Introduction Overview Windowing transforms Camera transformation Perspective transform Wrap-up Graphics 2011/2012, 4th quarter Lecture 7 Perspective projection Graphics 2011/2012, 4th quarter Lecture 07: perspective projection
Transcript
Page 1: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Graphics 2011/2012, 4th quarter

Lecture 7

Perspective projection

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 2: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

PerspectiveParallel projectionPerspective projection

Perspective

Goal: create 2D images of 3D scenes

Standard approach: linear perspective,i.e. straight lines in the scene become straight lines in the image(in contrast to, e.g., fisheye views)

Two important distinctions:

parallel projection

perspective projection

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 3: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

PerspectiveParallel projectionPerspective projection

Parallel projection

Maps 3D points to 2D by moving them along a projection directionuntil they hit an image plane

image plane perpendicular toviewing direction: orthographic

otherwise: oblique

(note: other definitions exist)

Characteristics:

keep parallel lines parallel

preserve size and shape ofplanar objects

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 4: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

PerspectiveParallel projectionPerspective projection

Perspective projection

Maps 3D points to 2D by projecting them along lines that passtrought a single viewpoint until they hit an image plane

distinction between oblique andnon-oblique based on projectiondirection at the center of theimage

Characteristics:

objects farther from theviewpoint naturally becomesmaller

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 5: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

PerspectiveParallel projectionPerspective projection

Parallel vs. perspective projection

Perspective projection: more natural and realistic

Parallel: usage in mechanical and architectural drawings

How to get 3D objects perspectively correct on 2D screen?

Note: usually your API takes care of most of this, but it’sgood to know what’s going on behind those function calls

And it’s a good opportunity to improve your maths skills ;)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 6: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Perspective projection

How to get 3D objects perspectively correct on 2D screen?

This task is best solved by splitting it in subtasksthat in turn can be solved by matrix multiplication

Let’s start with what we got ...

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 7: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

World space

Our 3D scene is given in worldspace, i.e. linear combinationsof the base vectors ~x, ~y, and ~z

Given an arbitrary cameraposition, we want to display our3D world in a 2D image usingperspective projection

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 8: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Camera position

The camera position is specified by

the eye vector ~e(it’s location)

the gaze vector ~g(it’s direction)

the image plane(it’s field of view (FOV) anddistance)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 9: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

View frustum

The view frustum (aka view volume)specifies everything that the cameracan see. It’s defined by

the left plane l

the right plane r

the top plane t

the bottom plane b

the near plane n

the far plane f

Note: for now, let’s assume all ourobjects are completely within theview frustum

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 10: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Camera transformation

Hmm, it would be much easier if thecamera were at the origin . . .

We can do that by moving fromworld space coordinates to cameraspace coordinates.

This is just a simple matrixmultiplication (cf. later).

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 11: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Camera transformation

Per convention, we look into thedirection of the negative Z-axis

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 12: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Orthographic projection

Hmm, it would be much easier if wecould do parallel projection . . .

We can do that by transforming theview frustum to the orthographicview volume.

Again, this is just a matrixmultiplication (but this time, it’s notthat simple, cf. later).

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 13: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

The canonical view volume

Hmm, it would be much easier if ourvalues were between -1 and 1 . . .

We can do that by transforming theorthographic view volume to thecanonical view volume.

Again, this is just a (simple) matrixmultiplication (cf. later).

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 14: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Windowing transform

Now all that’s left is a parallelprojection along the Z-axis (everyeasy) and . . .

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 15: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

Windowing transform

. . . a windowing transformation inorder to display the square [−1, 1]2

onto an nx × ny image.

Again, these are just some (simple)matrix multiplications (cf. later).

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 16: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

IntroductionProjecting from arbitrary camera positionsCamera transformationOrthographic projection and the canonical view volumeWindowing transform

The graphics pipeline (part I)

Notice that every step in this sequence canbe represented by a matrix operation, sothe whole process can be applied byperforming a single matrix operation!(well, almost . . . )

We call this sequence a graphics pipeline= a special software or hardware subsystemthat efficiently draws 3D primitives inperspective.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 17: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

Overview

Let’s start with the easier stuff, e.g.

Windowing transformation(aka viewport transformation)

How do we get the data from the canonicalview volume to the screen?

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 18: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

The canonical view volume

The canonical view volume is a2× 2× 2 box, centered at the origin.

The view frustum is transformed tothis box (and the objects within theview frustum undergo the sametransformation).

Vertices in the canonical viewvolume are orthographicallyprojected onto an nx × ny image.

−z

x

y

(−1,−1, 1)

(1, 1,−1)

(1,−1,−1)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 19: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

Mapping the canonical view volume

We need to map the square [−1, 1]2

onto a rectangle [0, nx]× [0, ny].

The following matrix takes care ofthat: nx

2 0 nx2

0 ny

2ny

20 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 20: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

Mapping the canonical view volume

In practice, pixels represent unitsquares centered at integercoordinates, so we actually have tomap to the rectangle[−1

2 , nx − 12 ]× [−1

2 , ny − 12 ].

Hence, our matrix becomes:

nx2 0 nx

2 − 12

0 ny

2ny

2 − 12

0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 21: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

Mapping the canonical view volume

Notice that we did orthographic projection by “throwing away ”the z-coordinate.

But since we want to combine all matrices in the end, we need a4× 4 matrix, so we add a row and colum that “doesn’t change z”.

Our final matrix for the windowing or viewport transformation is

Mvp =

nx2 0 0 nx

2 − 12

0 ny

2 0 ny

2 − 12

0 0 1 00 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 22: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

Overview

Hence, our last step will bexscreen

yscreen

zcanonical

1

= Mvp

xcanonical

ycanonical

zcanonical

1

Ok, now let’s work our way up:

How do we get the data from theorthographic view volume to the canonicalview volume, i.e. . . .

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 23: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

The orthographic view volume

. . . how do we get the datafrom the axis-aligned box[l, r]× [b, t]× [n, f ] to a2× 2× 2 box around theorigin?

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 24: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

The orthographic view volume

First we need to move thecenter to the origin:

1 0 0 − l+r

2

0 1 0 − b+t2

0 0 1 −n+f2

0 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 25: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

The orthographic view volume

Then we have to scaleeverything to [−1, 1]:

2

r−l 0 0 00 2

t−b 0 00 0 2

n−f 00 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 26: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The canonical view volumeThe orthographic view volumeThe orthographic projection matrix

The orthographic view volume

Since these are just matrix multiplications (associative!), we cancombine them into one matrix:

Morth =

2

r−l 0 0 00 2

t−b 0 00 0 2

n−f 00 0 0 1

1 0 0 − l+r2

0 1 0 − b+t2

0 0 1 −n+f2

0 0 0 1

=

2

r−l 0 0 − r+lr−l

0 2t−b 0 − t+b

t−b

0 0 2n−f −n+f

n−f

0 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 27: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Overview

Hence, our last step becomesxpixel

ypixel

zcanonical

1

= MvpMorth

xyz1

Now, how do we get the data in theorthographic view volume?

That’s more difficult, so let’s look atcamera transformation first.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 28: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

How do we get the camera to theorigin, i.e. how do we move fromworld space to camera space?

Remember:

world space is expressed by thebase vectors ~x, ~y, and ~z

the camera is specified by eyevector ~e and gaze vector ~g

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 29: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

To map one space to another, weneed a coordinate system for bothspaces.

We can easily get that using a viewup vector ~t, i.e. a vector in the planebisecting the viewer’s head into leftand right halves and “pointing to thesky”

This gives us an orthonormal base(~u,~v, ~w) of our camera coordinatesystem (how?)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 30: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

How do we align the two coordinatesystems?

1 align the origins

2 align the base vectors

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 31: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

Aligning the origins is a simple translation:

1 0 0 −xe

0 1 0 −ye

0 0 1 −ze

0 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 32: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

Aligning the axes is a simple rotation, if you remember that the columns of our

matrix are just the images of the base vectors under the linear transformation.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 33: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

These are easy to find for the reverse rotation:

xu xv xw 0yu yv yw 0zu zv zw 00 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 34: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

Hence, our rotation matrix is:

xu yu zu 0xv yv zv 0xw yw zw 00 0 0 1

(Remember: the inverse of an orthogonal matrix is always its transposed)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 35: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Aligning coordinate systemsTransformation matrix

Aligning coordinate systems

For the total transformation we get

Mcam =

xu yu zu 0xv yv zv 0xw yw zw 00 0 0 1

1 0 0 −xe

0 1 0 −ye

0 0 1 −ze

0 0 0 1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 36: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Overview

If it wasn’t for perspective projection, we’dbe done:

xpixel

ypixel

zcanonical

1

= MvpMorthMcam

xyz1

Now, let’s put things into perspective . . .

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 37: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Transforming the view frustum

cf. book, fig. 7.13 (3rd ed.) or 7.12 (2nd ed.)

View frustum Orthographic view volume

Perspective projection Parallel/orthographic projection

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 38: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Transforming the view frustum

cf. book, fig. 7.10 (2nd ed.; not in 3rd one)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 39: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Transforming the view frustum

We have to transform the viewfrustum into the orthographic viewvolume. The transformation needs to

Map lines through the origin tolines parallel to the z axis

Map points on the viewingplane to themselves.

Map points on the far plane to(other) points on the far plane.

Preserve the near-to-far order ofpoints on a line.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 40: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Transforming the view frustum

How do we calculate this? (cf. book, fig. 7.8/7.9 (3rd/2nd ed.))

From basic geometry we know:

ys

y = dz and thus ys = d

z y

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 41: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Transforming the view frustum

So we need a matrix that gives us

xs = dxz

ys = dyz

and a z-value that

stays the same for all points on the near and fare planesdoes not change the order along the z-axis for all other points

Problem: we can’t do division with matrix multiplication

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 42: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Extending homogeneous coordinates

Remember: matrix multiplication is a linear transformation, i.e. itcan only produce values such as:

x′ = a1x + b1y + c1z

Introducing homogeneous coordinates and representing points as(x, y, z, 1), enables us to do affine transformations, i.e. createvalues such as:

x′ = a1x + b1y + c1z + d1

Now we introduce projective transformation (aka homography)that allows us to create values such as:

x′ = a1x+b1y+c1z+d1

ex+fy+gz+h

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 43: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Extending homogeneous coordinates

How can we transform

a vector

xyz

to a vector

x′

y′

z′

=

a1x+b1y+c1z+d1

ex+fy+gz+ha2x+b2y+c2z+d2

ex+fy+gz+ha3x+b3y+c3z+d3

ex+fy+gz+h

using matrix multiplication?

We do this by replacing “the one” in the 4th coordinate with avalue w that serves as denominator.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 44: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Extending homogeneous coordinates

With homogeneous coordinates, the vector

(x, y, z, 1) represents the point (x, y, z).

Now we extend this in a way that the homogeneous vector

(x, y, z, w) represents the point (x/w, y/w, z/w).

And matrix transformation becomes:xyzw

=

a1 b1 c1 d1

a2 b2 c2 d2

a3 b3 c3 d3

e f g h

xyz1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 45: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Extending homogeneous coordinates

Notice that this doesn’t change our existing framework(i.e. all affine transformations “still work”).

We just have to set

e = f = g = 0 and h = 1.

Then our resulting vector

(x, y, z, w) becomes (x, y, z, 1),

and it represents the point

(x/w, y/w, z/w) = (x/1, y/1, z/1)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 46: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Extending homogeneous coordinates

With this extension, we do matrix multiplication:a1 b1 c1 d1

a2 b2 c2 d2

a3 b3 c3 d3

e f g h

xyz1

=

a1x + b1y + c1z + d1

a2x + b2y + c2z + d2

a3x + b3y + c3z + d3

ex + fy + gz + h

=

xyzw

Followed by a step called homogenization:

a1x + b1y + c1z + d1

a2x + b2y + c2z + d2

a3x + b3y + c3z + d3

ex + fy + gz + h

homogenize−−−−−−−−→

a1x+b1y+c1z+d1

ex+fy+gz+ha2x+b2y+c2z+d2

ex+fy+gz+ha3x+b3y+c3z+d3

ex+fy+gz+hex+fy+gz+hex+fy+gz+h

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 47: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Perspective transform matrix

So, by multiplication with this matrixa1 b1 c1 d1

a2 b2 c2 d2

a3 b3 c3 d3

e f g h

and homogenization,we can create this vector

a1x+b1y+c1z+d1

ex+fy+gz+ha2x+b2y+c2z+d2

ex+fy+gz+ha3x+b3y+c3z+d3

ex+fy+gz+hex+fy+gz+hex+fy+gz+h

Q: how do we chose theai, bi, ci, di and e, f, g, hto get what we want forperspective projection,i.e. the vector

nxz

nyzz∗

1

(z∗ denotes a z-valuefulfilling the conditionsthat we specified)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 48: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Perspective transform matrix

The following matrix will do the trick:

n 0 0 00 n 0 00 0 n + f −fn0 0 1 0

Notice that

we are looking in negative Z-direction

n, f denote the near and far plane of the view frustum

n serves as projection plane

Let’s verify that . . .Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 49: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Perspective transform matrix

n 0 0 00 n 0 00 0 n + f −fn0 0 1 0

xyz1

=

xy

z n+fn− f

zn

homogenize−−−−−−−−→

nxz

nyz

n + f − fnz

1

Indeed, that gives the correct values for xs and ys.

But what about z? Remember our requirements for z:

stays the same for all points on the near and fare planes

does not change the order along the z-axis for all other points

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 50: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Homogeneous coordinates and perspective transformation

We have zs = n + f − fnz and need to prove that . . .

values on the near plane stay on the near plane,i.e. if z = n, then zs = n:

zs = n + f − f = n = z

values on the far plane stay on the far plane,i.e. if z = f , then zs = n:

zs = n + f − n = f = z

and . . .

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 51: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Homogeneous coordinates and perspective transformation

We have zs = n + f − fnz and need to prove that . . .

values within the view frustum stay within the view frustum,i.e. if z > n then zs > n:

zs = n + f − fnz > n + f − fn

n = n

and if z < f then zs < f :

zs = n + f − fnz < n + f − fn

f = f

and . . .

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 52: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Homogeneous coordinates and perspective transformation

We have zs = n + f − fnz and need to prove that . . .

the order along the Z-axis is preserved,i.e. if z1 > z2 then z1s > z2s:

z1s = n + f − fnz1

> n + f − fnz2

= z2s

− 1z1

< − 1z2

z1 > z2

and we are done.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 53: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Homogeneous coordinates and perspective transformation

Hence, the order is preserved. But how?

zs = n + f − fnz ,

so zs is proportional to −1z

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 54: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Transforming the view frustumHomogeneous coordinatesPerspective transform matrix

Perspective transform matrix

With this, we got our final matrix P . To map the perspective viewfrustum to the orthographic view volume, we need to combine itwith the orthographic projection matrix Morth, i.e. Mper =

MorthP = Morth

n 0 0 00 n 0 00 0 n + f −fn0 0 1 0

=

2nr−l 0 l+r

l−r 00 2n

t−bb+tb−t 0

0 0 f+nn−f

2fnf−n

0 0 1 0

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 55: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Overview

The following achieved parallel projection:xpixel

ypixel

zcanonical

1

= MvpMorthMcam

xyz1

And if we replace Morth with Mper we getperspective projection:

xpixel

ypixel

zcanonical

1

= MvpMperMcam

xyz1

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 56: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Wrap-up

To draw lines on the screen, we can use thefollowing pseudo code:

compute Mvp ///view portcompute Mper ///persp. proj.compute Mcam ///camera spaceM = MvpMperMcam

for each line segment (ai,bi) dop = Mai

q = Mbi

drawline(xp/wp, yp/wp, xq/wq, yq/wq)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 57: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Other stages in the graphics pipeline

Now we can draw points and lines.But there’s more . . .

Triangles that lie (partly)outside the view frustum neednot be projected, and areclipped.

The remaining triangles areprojected if they are frontfacing.

Projected triangles have to beshaded and/or textured.

We will talk about this in theupcoming lectures.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 58: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Schedule

Schedule this week:

Today: tutorial 3 (room 61, and if necessary 79)(solutions online tonight, next tutorial sheet online next week)

Thursday: no lecture, tutorial, or TA session

Friday: midterm exam (and P3 will go online in the evening)

Next week (herkansing exams):

“Officially” no events

Thursday: additional TA session (time TBA on website)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 59: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Schedule

First week after herkansing:

Monday:

Practical sessions with TA as usual(maybe extended hours; check website!)

Tuesday:

Lecture: recap midterm exam (by Peter; no recording)No tutorialsPractical sessions with TAs as usualDeadline practicals P2, 15:00

Thursday:

No tutorialsPractical sessions with TAs as usualLecture: intro to P3 (by Bas and Marries, no recording)

Second week after herkansing:

Business as usual (lecture, tutorials, TA sessions)

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 60: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Practicals and midterm exam

IMPORTANT INFORMATION!

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 61: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Practicals

Considering the 2nd assignment:

We will offer additional TA sessions before the deadline!

Check the website for details!

Take advantage of this, but don’t rely on it!

Spaces in the room are limited and it will be crowded!

Bring your laptop if you have one, so you can also askquestions to the TAs if all computers are blocked!

Take advantage of the forum!

Most importantly: plan ahead and don’t rely on last minute help!We try our best, but we don’t guarantee anything!

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 62: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

Midterm exam

Time and date:

Friday, 25.5.119:00 - 12:00 hZaal: EDUC-GAMMA

Note: no responsibility is taken for the correctness of thisinformation. For final information about time and room seehttp://www.cs.uu.nl/education/vak.php?vak=INFOGR

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 63: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The midterm exam

What do I have to do?

Come in time

Bring a pen (no pencil)

Bring your student id

And know the answers ;)

Note: You may not use books, notes, or any electronic equipment(including cell phones!).

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection

Page 64: Lecture 07: perspective projection - Utrecht University projection Perspective projection Perspective ... viewing direction: ... Windowing transform Perspective projection

IntroductionOverview

Windowing transformsCamera transformationPerspective transform

Wrap-up

The midterm exam

The exam covers lectures 1-5 and tutorials 1-3.

If you ...

... followed the lectures

... read the textbook

... and actively did theexercises

... you should be fine.

Graphics 2011/2012, 4th quarter Lecture 07: perspective projection


Recommended