COMPUTER GRAPHICS גרפיקה ממוחשבת CS

Download Report

Transcript COMPUTER GRAPHICS גרפיקה ממוחשבת CS

University of British Columbia
CPSC 314 Computer Graphics
Jan-Apr 2005
Tamara Munzner
Projections II
Week 4, Wed Jan 26
http://www.ugrad.cs.ubc.ca/~cs314/Vjan2005
Reading (Mon and today)

FCG



Section 5.3.1
rest of Chapter 6
RB


rest of Chapter Viewing
rest of Appendix Homogeneous Coords
2
Review: Graphics Cameras

real pinhole camera: image inverted
image
plane

eye
point
computer graphics camera: convenient equivalent
eye
point
center of
projection
image
plane
3
Review: Basic Perspective Projection
similar triangles
P(x,y,z)
y
P(x’,y’,z’)
z’=d
 x 
z/d 


 y 


z
/
d




 d 


homogeneous
coords
yd
y' y
  y' 
d z
z
xd
z'  d
x' 
z
z
 x 
 y 
 z 
 z / d 
1
0
0
0
0 0
1 0
0 1
0 1d
0
0
0
0
4
Review: Orthographic Cameras



center of projection at infinity
no perspective convergence
just throw away z values
 x p  1
 y  0
 p  
 z p  0
  
 1  0
0
1
0
0
0
0
0
0
0  x 
0  y 
0  z 
 
1  1 
5
Review: Transforming View Volumes
orthographic view volume
perspective view volume
y=top
y=top
x=left
y
x=left
y
VCS
z
x
y=bottom z=-near
VCS
z=-far
x
y=bottom
x=right
NDCS
x=right
y
z=-far
z=-near
(1,1,1)
z
(-1,-1,-1)
x
6
Review: Ortho to NDC Derivation

scale, translate, reflect for new coord sys
VCS
NDCS
y
y=top
(1,1,1)
x=left
y
z
(-1,-1,-1)
z
x
x=right
x
y=bottom
z=-far
z=-near
2

 right  left


0
P'  

0


0

0
2
top  bot
0
0
right  left 
right  left 

top  bot 
0

top  bot  P
2
far  near


far  near
far  near
0
1

0

7
NDC to Viewport Transformation

generate pixel coordinates


map x, y from range –1…1 (NDC) to pixel
coordinates on the display
involves 2D scaling and translation
y
display
x
viewport
8
NDC to Viewport Transformation

2D scaling and translation
(1,1)
(w,h)
DCS
NDCS
y
(-1,-1)
( x NDCS  1)
xDCS  w
2
( y NDCS  1)
y DCS  h
2
( z NDCS  1)
z DCS 
2
b
(0,0)
a
x
OpenGL
glViewport(x,y,a,b);
default:
glViewport(0,0,w,h);
9
Origin Location

yet more possibly confusing conventions



OpenGL: lower left
most window systems: upper left
often have to flip your y coordinates

when interpreting mouse position
10
Perspective Example
view volume
left = -1, right = 1
bot = -1, top = 1
near = 1, far = 4
tracks in VCS:
left x=-1, y=-1
right x=1, y=-1
x=-1
x=1
1
ymax-1
z=-4
real
midpoint
z=-1
x
z
VCS
top view
-1
-1 -1
1
NDCS
(z not shown)
0 0
xmax-1
DCS
(z not shown)
11
Viewing Transformation
y
VCS
image
plane
z
z
Peye
y
x
OCS
y
WCS x
object
world
viewing
OCS
WCS
VCS
modeling
transformation
viewing
transformation
Mmod
M cam
OpenGL ModelView matrix
12
Projective Rendering Pipeline
object
OCS
world
WCS
modeling
transformation
viewing
VCS
viewing
transformation
alter w
projection
transformation
/w
OCS - object coordinate system
perspective
division normalized
device
NDCS
WCS - world coordinate system
VCS - viewing coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device coordinate system
clipping
CCS
viewport
transformation
device
DCS
13
Projective Rendering Pipeline
object
OCS
world
WCS
modeling
transformation
viewing
VCS
viewing
transformation
alter w
projection
transformation
/w
OCS - object coordinate system
perspective
division normalized
device
NDCS
WCS - world coordinate system
VCS - viewing coordinate system
CCS - clipping coordinate system
NDCS - normalized device coordinate system
DCS - device coordinate system
clipping
CCS
viewport
transformation
device
DCS
14
Perspective Projection



specific example
assume image plane at z = -1
a point [x,y,z,1]T projects to [-x/z,-y/z,-z/z,1]T 
[x,y,z,-z]T
 x
 y
 
 z 
 
 z 
 x
 y
 
z
 
1 
-z
15
Perspective Projection
  x   1
   
  y   0
T


 z  0
   
 1  0
   
0  x   x    x / z 







1 0 0  y   y    y / z 



0 1 0  z   z    1 
     

0  1 0  1    z   1 
0
0
projection
transformation
alter w
perspective
division
/w
16
Canonical View Volumes

standardized viewing volume representation
orthographic
orthogonal
parallel
x or y
Front
Plane
1
perspective
x or y
back
plane
-1
-z
front
plane
x or y = +/- z
back
plane
-z
-1
17
Why Canonical View Volumes?

permits standardization

clipping
easier to determine if an arbitrary point is
enclosed in volume
 consider clipping to six arbitrary planes of a
viewing volume versus canonical view volume


rendering

projection and rasterization algorithms can be
reused
18
Projection Normalization


one additional step of standardization
warp perspective view volume to orthogonal
view volume

render all scenes with orthographic projection!
x
x
z= z=d
z=0
Z
z=d
Z
19
Predistortion
20
Perspective Normalization


perspective viewing frustum transformed to
cube
orthographic rendering of cube produces same
image as perspective rendering of original
frustum
21
Demos

Tuebingen applets from Frank Hanisch

http://www.gris.uni-tuebingen.de/projects/grdev/doc/html/etc/
AppletIndex.html#Transformationen
22
Perspective Warp

matrix formulation
1
0

( x, y, z,1)0


0


0
1
0
0
d
0
d 
  d
0
d 
0
0 
(z  )  d z 
1 
   x, y ,
, 
d  d 
d 

0
 x
y
d 2   

(xp , yp , zp )  
,
,
1   
 z / d z / d d    z 
preserves relative depth (third coordinate)
what does   0 mean?
Projection Normalization
viewing
VCS
clipping
CCS
projection
transformation
alter w

perspective
division
/w
normalized
device
NDCS
distort such that orthographic projection of
distorted objects is desired persp projection



separate division from standard matrix
multiplies
clip after warp, before divide
division: normalization
24
Projective Rendering Pipeline
glVertex3f(x,y,z)
object
OCS
world
WCS
modeling
transformation
viewing
VCS
viewing
transformation
alter w
projection
transformation
glFrustum(...)
clipping
CCS
glTranslatef(x,y,z)
gluLookAt(...)
/w
glRotatef(th,x,y,z)
perspective
....
division normalized
OCS - object coordinate system
glutInitWindowSize(w,h)
device
WCS - world coordinate system glViewport(x,y,a,b)
NDCS
viewport
VCS - viewing coordinate system
transformation
CCS - clipping coordinate system
device
NDCS - normalized device coordinate system
DCS - device coordinate system
DCS
25
Coordinate Systems
http://www.btinternet.com/~danbgs/perspective/
26
Perspective Derivation
VCS
NDCS
y=top
x=left
y
y
(1,1,1)
z
(-1,-1,-1)
z
x
y=bottom z=-near
x
z=-far
x=right
27
Perspective Derivation
earlier:
 x'  1
 y '  0
 
 z '  0
  
 w' 0
0 0
1 0
0 1
0 1/ d
0  x 
0  y 
0  z 
 
0  1 
complete: shear, scale, projection-normalization
 x'   E
 y'  0
 
 z'   0
  
 w'  0
0
F
0
0
A
B
C
1
0  x
0   y 
D  z 
 
0  1 
28
Perspective Derivation
 x'   E
 y'  0
 
 z'   0
  
 w'  0
0
F
0
0
A
B
C
1
0  x
0   y 
D  z 
 
0  1 
x'  Ex  Az
y '  Fy  Bz
z '  Cz  D
w'   z
x  left  x' / w'  1
x  right  x' / w'  1
y  top  y ' / w'  1
y  bottom  y ' / w'  1
z  near  z ' / w'  1
z   far  z ' / w'  1
y ' Fy  Bz
Fy  Bz
Fy  Bz
y '  Fy  Bz ,

, 1
, 1
,
w'
w'
w'
z
y
z
y
top
1 F
B
, 1 F
 B, 1  F
 B,
z
z
z
 (near )
top
1 F
B
near
29
Perspective Derivation
similarly for other 5 planes
 6 planes, 6 unknowns

 2n
r  l

 0

 0

 0

0
2n
t b
0
0
r l
r l
t b
t b
 ( f  n)
f n
1

0 

0 

 2 fn 
f n

0 
30
Perspective Example
view volume
 left = -1, right = 1
 bot = -1, top = 1
 near = 1, far = 4
 2n
r  l

 0

 0

 0

0
2n
t b
0
0
r l
r l
t b
t b
 ( f  n)
f n
1

0 

0 

 2 fn 
f n
0 
1
0

0

0
0
0
0 
1
0
0 
0  5 / 3  8 / 3

0
1
0 
31
Perspective Example
1

 1
 1 







1
1

1




 5 zVCS / 3  8 / 3 
 5 / 3  8 / 3  zVCS 

 


 zVCS
1
 1 

 
x NDCS  1 / zVCS
/w
y NDCS  1 / zVCS
z NDCS
5
8
 
3 3zVCS
32
Asymmetric Frusta


our formulation allows asymmetry
why bother?
x
x
right
right
Frustum
left
z=-n
Frustum
-z
left
-z
z=-f
33
Simpler Formulation

left, right, bottom, top, near, far



look through window center


nonintuitive
often overkill
symmetric frustum
constraints

left = -right, bottom = -top
34
Field-of-View Formulation

FOV in one direction + aspect ratio (w/h)


determines FOV in other direction
also set near, far (reasonably intuitive)
x
w

Frustum
z=-n
fovx/2
-z
z=-f
h
fovy/2
35
Perspective OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left,right,bot,top,near,far);
or
glPerspective(fovy,aspect,near,far);
36
Demo: Frustum vs. FOV

Nate Robins tutorial (take 2):

http://www.xmission.com/~nate/tutors.html
37
Projection Taxonomy
planar
projections
perspective:
1,2,3-point
parallel
oblique
cabinet
orthographic
cavalier
top,
front,
side
axonometric:
isometric
dimetric
trimetric
http://ceprofs.tamu.edu/tkramer/ENGR%20111/5.1/20
38
Perspective Projections

classified by vanishing points
one-point
perspective
two-point
perspective
three-point
perspective
39
Parallel Projection

projectors are all parallel



vs. perspective projectors that converge
orthographic: projectors perpendicular to
projection plane
oblique: projectors not necessarily
perpendicular to projection plane
Orthographic
Oblique
Axonometric Projections


projectors perpendicular to image plane
select axis lengths
http://ceprofs.tamu.edu/tkramer/ENGR%20111/5.1/20
41
Oblique Projections


projectors oblique to image plane
select angle between front and z axis


lengths remain constant
both have true front view


cavalier: distance true
cabinet: distance half
d/2
y
y
d
d
d

x
z
cavalier

x
z
cabinet
42
Demos

Tuebingen applets from Frank Hanisch

http://www.gris.uni-tuebingen.de/projects/grdev/doc/html/etc/
AppletIndex.html#Transformationen
43