1 1 CS 430 Computer Graphics 3D Viewing Pipeline Week 7, Lecture 13 David Breen, William Regli and Maxim Peysakhov Department of Computer Science Drexel University 1 2 Overview • Projection Mathematics • Canonical View Volume • Parallel Projection Pipeline • Perspective Projection Pipeline Lecture Credits: Most pictures are from Foley/VanDam; Additional and extensive thanks also goes to those credited on individual slides 1994 Foley/VanDam/Finer/Huges/Phillips ICG Pics/Math courtesy of Dave Mount @ UMD-CP 2 3 Projection Mathematics • What is the set of transformations needed to map 3D lines/planes onto a 2D screen positioned in 3D? • Basic procedure – 4D homogeneous coordinates to – 3D homogeneous coordinates for – every primitive in – the 3D view volume 3 4 Projection Mathematics We present 4x4 matrices to be used for implementing projections • Perspective Projections – How much to scale objects as a function of distance? • Parallel Projections – (simplified case) Just chop out the z coordinate 4 5 The Perspective Projection Determining scale • Consider – Point P – Projected onto projection plane as point Pp • Idea: compute ratios via similar triangles 1994 Foley/VanDam/Finer/Huges/Phillips ICG 5 6 The Perspective Projection • In the x direction ratio is 1994 Foley/VanDam/Finer/Huges/Phillips ICG z d = x x p x p = x z / d 6
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
1
CS 430Computer Graphics
3D Viewing PipelineWeek 7, Lecture 13
David Breen, William Regli and Maxim PeysakhovDepartment of Computer Science
Lecture Credits: Most pictures are from Foley/VanDam; Additional and extensive thanks also goes to those credited on individual slides
1994 Foley/VanDam/Finer/Huges/Phillips ICGPics/Math courtesy of Dave Mount @ UMD-CP
2
3
Projection Mathematics
• What is the set of transformations needed to map 3D lines/planes onto a 2D screen positioned in 3D?
• Basic procedure– 4D homogeneous coordinates to– 3D homogeneous coordinates for– every primitive in– the 3D view volume
3
4
Projection Mathematics
We present 4x4 matrices to be used for implementing projections
• Perspective Projections– How much to scale objects as a function of
distance?• Parallel Projections
– (simplified case) Just chop out the z coordinate
4
5
The Perspective Projection
Determining scale• Consider
– Point P– Projected onto
projection plane as point Pp
• Idea: compute ratios via similar triangles
1994 Foley/VanDam/Finer/Huges/Phillips ICG
5
6
The Perspective Projection
• In the x direction ratio is
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
zd
=xxp
xp =xz /d
6
2
7
The Perspective Projection
• In the y direction ratio is
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
zd
=yyp
yp =yz /d
7
8
The Perspective Projection
• Homogenous perspective projection matrix
1994 Foley/VanDam/Finer/Huges/Phillips ICG
!!!!!
"
#
$$$$$
%
&
=
0100010000100001
per
d
M Assumes VPN is z axis.
8
9
The Perspective Projection
• Homogenous perspective projection
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
xyzz /d
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0 00 1 0 00 0 1 00 0 1
d 0
"
#
$ $ $ $
%
&
' ' ' '
•
xyz1
"
#
$ $ $ $
%
&
' ' ' '
9
10
The Perspective Projection
• Homogenous perspective projection to 3D
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
xyzz /d
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 0 00 1 0 00 0 1 00 0 1
d 0
"
#
$ $ $ $
%
&
' ' ' '
•
xyz1
"
#
$ $ $ $
%
&
' ' ' '
➱
€
xz /dyz /dd
"
#
$ $ $ $
%
&
' ' ' '
10
11
The Orthographic Projection
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
Mort =
1 0 0 00 1 0 00 0 0 00 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
Assumes DOP is z axis.
Just makesz component 0
11
12
Implementing Projections(Foley et al.)
… a sequence of matrix operations and a clipping procedure…
1994 Foley/VanDam/Finer/Huges/Phillips ICG
12
3
13
Implementing Projections(Foley et al.)
1. Extend 3D coordinates to homogenous coords2. Apply normalizing transformation, Npar or Nper3. Divide by W to map back down to 3D4. Clip in 3D against canonical view volume
• parallel or perspective view volume5. Extend 3D coordinates back to homogenous6. Perform parallel projection using Mort or
Perform perspective projection Mper
7. Divide by W to map from homogenous to 2D coordinates (division effects perspective projection)
8. Translate and scale (in 2D) to device coordinates
13
14
Canonical View Volume: Parallel Projection
• Defined by 6 planes:– x = 1– x = -1– y = 1– y = -1– z = 0– z = -1
• Easy to clip against
1994 Foley/VanDam/Finer/Huges/Phillips ICG
14
15
Canonical View Volume: Perspective Projection
1994 Foley/VanDam/Finer/Huges/Phillips ICG
• Defined by 6 planes:– x = z– x = -z– y = z– y = -z– z = zmin
– z = -1
• Easy to clip against
15
16
Parallel Projection Pipeline
1. Translate VRP to the origin
2. Rotate so VPN becomes z, VUP becomes y and ubecomes x
3. Shear to make direction of the projection become parallel to z
4. Translate and scale into a canonical view volume
Transforming an arbitrary view volume into the canonical one
16
17
1. Translate VRP to the origin
• Simple translation T(-VRP)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Top Projection Off-Axis Projection Top Projection Off-Axis Projection
€
T =
1 0 0 −vrpx0 1 0 −vrpy0 0 1 −vrpz0 0 0 1
#
$
% % % %
&
'
( ( ( (
17
18
• VPN rotated to z• VUP rotated to y••
2. Rotate
1994 Foley/VanDam/Finer/Huges/Phillips ICG
!!!!
"
#
$$$$
%
&
=
1000000
321
321
321
zzz
yyy
xxx
rrrrrrrrr
R
||VPNVPN
zR =
|| z
zRVUPRVUP
xR ××=
xzy RRR ×=
[ ],...,, 321 xxxx rrrR =
VRP, VPN & VUP inWorld Coordinates (x,y,z)
18
4
2. Rotate
19
19
20
3. Shear• Computing direction of projection DOP
1994 Foley/VanDam/Finer/Huges/Phillips ICG
PRP =prpuprpvprpn
!
"
####
$
%
&&&&
,CW =
umax+umin2
vmax+vmin2
0
!
"
####
$
%
&&&&
,DOP =
umax+umin2 − prpu
vmax+vmin2 − prpv−prpn
!
"
####
$
%
&&&&
,SHpar =
1 0 shx 00 1 shy 0
0 0 1 00 0 0 1
!
"
#####
$
%
&&&&&
PRP in VRCCoordinates (u,v,n)
20
21
3. Shear (Cont.)
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
SHpar =
1 0 shx 00 1 shy 00 0 1 00 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
• For Shxy z’=z, x’=x+z•shx, y’=y+z•shy
€
x 'y 'z'1
"
#
$ $ $ $
%
&
' ' ' '
=
1 0 shx 00 1 shy 00 0 1 00 0 0 1
"
#
$ $ $ $
%
&
' ' ' '
•
xyz1
"
#
$ $ $ $
%
&
' ' ' '
21
22
3. Shear (Cont)• For Shxy z’=z, x’=x+z•shx, y’=y+z•shy
• Find Shxy such that:DOP’ = [0,0,DOPz,0]T = Shxy• DOP
0 = DOPx + DOPz • shx , 0 = DOPy + DOPz • shy
1994 Foley/VanDam/Finer/Huges/Phillips ICG
€
shx = − DOPxDOPz
, shy = −DOPyDOPz
Old Foley et al. is wrong!
22
24
• Given
• We can compute the SHpar matrix
3. Shear (Finally)
€
shx = − DOPxDOPz
,
shy = −DOPyDOPz
DOP =
umax+umin2 − prpu
vmax+vmin2 − prpv−prpn
"
#
$$$$
%
&
''''
,SHpar =
1 0 shx 00 1 shy 0
0 0 1 00 0 0 1
"
#
$$$$$
%
&
'''''
€
1 0 1/2(umax + umin ) − prpuprpn
0
0 1 1/2(vmax + vmin ) − prpvprpn
0
0 0 1 00 0 0 1
#
$
% % % % % %
&
'
( ( ( ( ( (
24
3. Shear
25
25
5
26
4. Translate and Scale • Translate the center of the volume to the origin• Scaling to 2x2x1• Needed for 3D clipping
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Top Projection Off-Axis Projection Top Projection Off-Axis Projection