computer graphics (cs 543) lecture 7a: derivation of perspective projection...
TRANSCRIPT
![Page 1: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/1.jpg)
Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective
Projection Transformation
Prof Emmanuel Agu
Computer Science Dept.
Worcester Polytechnic Institute (WPI)
![Page 2: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/2.jpg)
Perspective Projection
Projection – map the object from 3D space to 2D screen
x
y
z
Perspective()Frustrum( )
![Page 3: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/3.jpg)
Perspective Projection: Classical
(0,0,0)
N
Projection plane
Eye (COP)
(x,y,z)
(x’,y’,z’)
-z
- z
y
Based on similar triangles:
y’ N y -z
Ny’ = y x
-z
=
Near Plane(VOP)
+ z
![Page 4: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/4.jpg)
Perspective Projection: Classical
So (x*,y*) projection of point, (x,y,z) unto near plane N is given as:
Numerical example:
Q. Where on the viewplane does P = (1, 0.5, -1.5) lie for a near plane at N = 1?
z
Ny
z
Nxyx ,**,
)333.0,666.0(5.1
15.0,
5.1
11,**,
z
Ny
z
Nxyx
![Page 5: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/5.jpg)
Pseudodepth
Classical perspective projection projects (x,y) coordinates to (x*, y*), drops z coordinates
But we need z to find closest object (depth testing)!!!
(0,0,0)
z
Map to same (x*,y*)Compare their z values?
![Page 6: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/6.jpg)
Perspective Transformation
Perspective transformation maps actual z distance of perspective view volume to range [ –1 to 1] (Pseudodepth) for canonical view volume
-Near
-Far
-1 1
Canonical view volume
Actual view volume
Pseudodepth
Actual depthWe want perspectiveTransformation and NOT classical projection!!
Set scaling zPseudodepth = az + bNext solve for a and b
![Page 7: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/7.jpg)
Perspective Transformation
We want to transform viewing frustum volume into canonical view volume
(-1, -1, 1)
(1, 1, -1)
Canonical View Volume
x
y
z
![Page 8: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/8.jpg)
Perspective Transformation using Pseudodepth
Choose a, b so as z varies from Near to Far, pseudodepthvaries from –1 to 1 (canonical cube)
Boundary conditions
z* = -1 when z = -N
z* = 1 when z = -F
z
baz
z
Ny
z
Nxzyx ,,**,*,
-Near -Far
Canonical view volume
Actual view volume
Pseudodepth
Actual depth
1-1
Z*
Z
![Page 9: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/9.jpg)
Transformation of z: Solve for a and b
Solving:
Use boundary conditions
z* = -1 when z = -N………(1)
z* = 1 when z = -F………..(2)
Set up simultaneous equations
z
bazz
*
)1........(1 baNNN
baN
)2........(1 baFFF
baF
![Page 10: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/10.jpg)
Transformation of z: Solve for a and b
Multiply both sides of (1) by -1
Add eqns (2) and (3)
Now put (4) back into (3)
)1........(baNN
)2........(baFF
)3........(baNN
aFaNNF
)4.........()(
NF
NF
FN
NFa
![Page 11: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/11.jpg)
Transformation of z: Solve for a and b
Put solution for a back into eqn (3)
So
bNF
NFNN
)(
)3........(baNN
NF
NFNNb
)(
NF
NF
NF
NNFNNF
NF
NFNNFNb
2)()( 22
NF
NFa
)(
NF
FNb
2
![Page 12: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/12.jpg)
What does this mean?
Original point z in original view volume, transformed into z* in canonical view volume
where-Near -Far
Canonical view volume
Actual view volume
1 -1
Original vertex z value
Transformed vertex z* value
z
bazz
*
NF
NFa
)(
NF
FNb
2
![Page 13: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/13.jpg)
Homogenous Coordinates
Want to express projection transform as 4x4 matrix
Previously, homogeneous coordinates of
P = (Px,Py,Pz) => (Px,Py,Pz,1)
Introduce arbitrary scaling factor, w, so that
P = (wPx, wPy, wPz, w) (Note: w is non-zero)
For example, the point P = (2,4,6) can be expressed as
(2,4,6,1)
or (4,8,12,2) where w=2
or (6,12,18,3) where w = 3, or….
To convert from homogeneous back to ordinary coordinates, first divide all four terms by w and discard 4th term
![Page 14: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/14.jpg)
Perspective Projection Matrix
Recall Perspective Transform
We have:
In matrix form:
1
)(
0100
00
000
000
z
bazz
Ny
z
Nx
wz
bazw
wNy
wNx
w
wz
wy
wx
ba
N
N
z
baz
z
Ny
z
Nxzyx ,,**,*,
z
Nxx
*z
Nyy
*z
bazz
*
Perspective Transform Matrix
Original vertex
TransformedVertex
Transformed Vertex after dividing by 4th term
![Page 15: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/15.jpg)
Perspective Projection Matrix
In perspective transform matrix, already solved for a and b:
So, we have transform matrix to transform z values
1
)(
0100
00
000
000
z
bazz
Ny
z
Nx
wP
baPw
wNP
wNP
w
wP
wP
wP
ba
N
N
z
z
y
x
z
y
x
NF
NFa
)(
NF
FNb
2
![Page 16: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/16.jpg)
Perspective Projection
Not done yet!! Can now transform z!
Also need to transform the x = (left, right) and y = (bottom, top) ranges of viewing frustum to [-1, 1]
Similar to glOrtho, we need to translate and scale previous matrix along x and y to get final projection transform matrix
we translate by –(right + left)/2 in x
-(top + bottom)/2 in y
Scale by: 2/(right – left) in x
2/(top – bottom) in y
1 -1
x
y
left rightbottom
top
![Page 17: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/17.jpg)
Perspective Projection
Translate along x and y to line up center with origin of CVV –(right + left)/2 in x
-(top + bottom)/2 in y
Multiply by translation matrix:
1 -1
x
y
left right
bottom
top
1000
0100
2/)(010
2/)(001
bottomtop
leftright
Line up centersAlong x and y
![Page 18: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/18.jpg)
Perspective Projection
To bring view volume size down to size of of CVV, scale by
2/(right – left) in x
2/(top – bottom) in y
Multiply by scale matrix:
1 -1
x
y
left right
bottom
top
Scale size downalong x and y
1000
0100
002
0
0002
bottomtop
leftright
![Page 19: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/19.jpg)
Perspective Projection Matrix
glFrustum(left, right, bottom, top, N, F) N = near plane, F = far plane
0100
2)(00
02
0
00minmax
2
NF
FN
NF
NF
bottomtop
bottomtop
bottomtop
N
leftright
leftright
xx
N
0100
00
000
000
1000
0100
2/)(010
2/)(001
1000
0100
002
0
0002
ba
N
N
bottomtop
leftright
bottomtop
leftright
Scale
Final PerspectiveTransform Matrix
Translate
Previous PerspectiveTransform Matrix
![Page 20: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/20.jpg)
Perspective Transformation
After perspective transformation, viewing frustum volume is transformed into canonical view volume
(-1, -1, 1)
(1, 1, -1)
Canonical View Volume
x
y
z
![Page 21: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/21.jpg)
Geometric Nature of Perspective Transform
a) Lines through eye map into lines parallel to z axis after transform
b) Lines perpendicular to z axis map to lines perp to z axis after transform
![Page 22: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/22.jpg)
Normalization Transformation
original clippingvolume original object new clipping
volume
distorted object
projects correctly
![Page 23: Computer Graphics (CS 543) Lecture 7a: Derivation of Perspective Projection …web.cs.wpi.edu/~emmanuel/courses/cs543/s18/slides/... · 2018. 3. 1. · Perspective Projection Not](https://reader034.vdocuments.site/reader034/viewer/2022052502/609ace543235857e1d3e2058/html5/thumbnails/23.jpg)
References
Interactive Computer Graphics (6th edition), Angel and Shreiner
Computer Graphics using OpenGL (3rd edition), Hill and Kelley