程序代写代做代考 cse3431-lecture8

cse3431-lecture8

Derivation of the perspective
transformation

• It is basically a mapping of planes
• Normalized view volume is a left

handed system
• However, there is an easier

derivation

Text

Interpretation of the Perspective
transformation

Warps the view volume and
the objects in it
• Eye becomes a point


at infinity, and the projection 

rays become parallel lines

(orthographic projection)

• We also want to keep z

Two step derivation

• Start with the Canonical Perspective Projection matrix
• Adjust CPP to scale z so that after the application of CPP 


z = -near maps to z’=-near and z=-far maps to z’=-far)
• We now have the standard orthographic view volume
• Use the previously derived orthographic projection matrix MO

MP
MO

First: What are the view volume
points in viewing coordinates?

-n -f

t
tf

y

-z

From similar triangles:
t

�n
=

tf
�f

! tf = t
f

n

Similarly y = b, and for x = r and x = l

So for example: black point: (r, t,�n) ! Red point: (rf/n, tf/n,�f)

b
bf

First step: What does the CPP
produce?

• P’x = n Px/ Pz
• P’y = n Py/Pz
• P’z = -n

MP?

The four front( near) corners map as follows:
(left,bottom,-near) –> (left,bottom,-near)
(left,top,-near) –> (left,top,-near)
(right,bottom,-near) –> (right,bottom,-near)
(right,top,-near) –> (right,top,-near)

The four back (far) corners map as follows:
(l*f/n,b*f/n, -f) –> (l, b,-n) instead of (l,b,-f)
(l*f/n,t*f/n,-f) –> (l, t, -n) instead of (l,t,-f)
(r*f/n,b*f/n, -f) –> (r,b,-n) instead of (r,b,-f)
(r*f/n,t*f/n,-f) –> (r,t,-n) instead of (r,t,-f)

So we just have to adjust the matrix for z

First step:Adjust the matrix to
keep and scale Z

• We want to keep z and
• We want P’z = -n for Pz= -n and P’z = -f for Pz =-f after

the perspective division
• Where do we do the changes?
2

66
4

1 0 0 0
0 1 0 0
0 0 1 0
0 0 �1

n
0

3

77
5

2

66
4

n 0 0 0
0 n 0 0
0 0 n 0
0 0 �1 0

3

77
5

First step: With some intuition…
Reminder: n,f are positive

Sanity check
• (l*f/n,b*f/n,-f) –> (l,b,-f)
• (l,b,-n) –> (l,b,-n)

MP

2

66
4

Px
Py
Pz
1

3

77
5 =

2

66
4

Px
Py

Pz
n+f
n

+ f
�Pz

n

3

77
5 �!

Homogenize with h=�Pz/n

2

666
4

�Pxn
Pz

�Pyn
Pz

�(n+ f)� fn
Pz

1

3

777
5

Therefore

MP =

2

66
4

1 0 0 0
0 1 0 0
0 0 n+f

n
f

0 0 �1
n

0

3

77
5 or MP =

2

66
4

n 0 0 0
0 n 0 0
0 0 n+ f fn
0 0 �1 0

3

77
5 .

First step: MP
• Creates the previous orthographic view volume

• Which can then be transformed to NDCS with MO

MP
MO

Second Step: Combine with
Orthographic Projection Matrix

Now all we need to do is an orthographic
transformation
• We can use matrix Mo that transforms an orthographic

view volume to a normalized one (NDCS)

MO =

2

66
4

2
r�l 0 0 �

r+l
r�l

0 2
t�b 0 �

t+b
t�b

0 0 �2
f�n �

f+n
f�n

0 0 0 1

3

77
5

Second Step: Combine with
Orthographic Projection Matrix

MP
MO

Mprom = MOMP

OpenGL Perspective Matrix
Old form
• Still widely used

MOpenGL =

⇧⇧⇧

2|n|
r�l 0

r+l
r�l 0

0 2|n|
t�b

b+t
t�b 0

0 0 |n|+|f ||n|�|f |
2|f ||n|
|n|�|f |

0 0 �1 0

⌃⌃⌃

.

Projections in OpenGL
(mimicking the old way)

New way

projMat = frustum(-left, right, bottom, top, near, far);
projMat = ortho(-left, right, bottom, top, near, far) ;
projMat = Perspective(fov, aspect, near far) ;

near plane at z = -near
far plane at z = -far

Matrix Order

Normally projection has to apply to all
objects (i.e. the entire scene) thus it must
pre-multiply the modelview matrix
• M = MprojMmodelview or
• M = MprojMviewMmodel

Important
Projection parameters are given in CAMERA
Coordinate system (Viewing).

So if camera is at z = 50, is aligned with the
world CS, and you give near = 10 where is
the near plane with respect to the world?

Important
Projection parameters are given in CAMERA
Coordinate system (Viewing).

So if the camera is at z = 50, is aligned with
the world CS, and you give |near| = 10 where
is the near plane with respect to the world?
• Transformed by inverse(Mvcs)
• i.e. (0,0,40)

Perspective Division in Pipeline
The perspective division is done
automatically
• Typically the vertex shaders writes CCS in gl_Position.

Modeling
transformation

Viewing
transformation

Projection
transformation

Perspective
division

Viewport
transformation

OCS WCS VCS CCS

NDCSDCS

(e.g. pixels)

lookAt()translate()…

ModelView Matrix

Perspective Division in Pipeline

However, we can do it ourselves if we want.

The vertex shader has total freedom on how
to deal with projections