viewing - cg.tuwien.ac.at
TRANSCRIPT
Einführung in Visual Computing186.822
Viewing
Werner Purgathofer
Viewing in the Rendering Pipeline
Werner Purgathofer 2raster image in pixel coordinates
clipping + homogenization
object capture/creation
modelingviewing
projection
rasterizationviewport transformation
shading
vertex stage(„vertex shader“)
pixel stage(„fragment shader“)
scene in normalized device coordinates
transformed vertices in clip space
scene objects in object space
From Object Space to Screen Space
Werner Purgathofer 3
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Viewport Transformation
From Object Space to Screen Space
Werner Purgathofer 5
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Viewport Transformation
assumption: scene is in clip space !clip space = [–1,1] × [–1,1] × [–1,1]orthographic camera looking in –z directionscreen resolution nx × ny pixels
Werner Purgathofer / Einf. in Visual Computing 6
nx ny(–1,–1,–1)
(1,1,1)
(–1,–1) (0,0)(1,1) (nx,ny)
clip space:
z
Viewport Transformation
can be done with the matrix
this ignores the z-coordinate, but…
(–1,–1) (0,0)(1,1) (nx,ny)
xscreenyscreen
nx/2 00 ny/2
nx/2ny/2
0 0 11
xy1
= ·
Werner Purgathofer / Einf. in Visual Computing
Projection Transformation
From Object Space to Screen Space
Werner Purgathofer 10
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Parallel Projection (Orthographic Projection)
11
3 parallel-projection views of an object, showing relative proportions from different viewing positions
top side front
Werner Purgathofer / Einf. in Visual Computing
Parallel vs. Perspective Projection
12Werner Purgathofer / Einf. in Visual Computing
For Now: Parallel (Orthographic) Projection
Werner Purgathofer 13
object space world space camera space
clip space screen space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
FB
Projection Transformation (Orthographic)
assumption: scene in box [L,R] × [B,T] × [F,N]orthographic camera looking in –z directiontransformation to clip space
14
L
(L,B,F) (–1,–1,–1)(R,T,N) (1,1,1)
clip space:
(–1,–1,–1)
(1,1,1)
z(L,B,F)
(R,T,N)z
orthographic view volumein camera space:
R
T
N
Werner Purgathofer / Einf. in Visual Computing
Projection Transformation (Orthographic)
15
(L,B,F) (–1,–1,–1)(R,T,N) (1,1,1)
0 0 0 1
R – L2
T – B2
N – F2
R – LR + L
T – BT + B
N – FN + F
0 0
0 0
0 0
–
–
–Morth =
1
L
F
B
1
–1
–1
–1· =
Werner Purgathofer / Einf. in Visual Computing
Parallel Projection Types
16
orthographicprojection
obliqueprojection
different orientation of the projection vector –g
–g
viewing plane
–g
viewing plane
Werner Purgathofer / Einf. in Visual Computing
Camera Transformation
For Now: Parallel (Orthographic) Projection
Werner Purgathofer 18
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Viewing: Projection Plane
19
coordinate reference for obtaining a selected view of a 3D scene
displayplane
Werner Purgathofer / Einf. in Visual Computing
Viewing: Camera Definitionsimilar to taking a photographinvolves selection of
camera positioncamera directioncamera orientation“window” (zoom) of camera
20
worldcoordinates
cameracoordinates
Werner Purgathofer / Einf. in Visual Computing
Viewing: Camera Transformation (1)
view reference pointorigin of camera coordinate systemgaze direction or look-at point
21
right-handed camera-coordinate system, with axes u, v, w, relative to world-coordinate scene
y
zx
vw
u
eo
Werner Purgathofer / Einf. in Visual Computing
Viewing: Camera Transformation (2)
22
eg
e … eye positiong … gaze direction (positive w-axis points to the viewer)t … view-up vector
wu
t
v = w × u
w = – g|g|
u =|t × w|t × w
Werner Purgathofer / Einf. in Visual Computing
Viewing: Camera Transformation (2)
23
eg
e … eye positiong … gaze direction (positive w-axis points to the viewer)t … view-up vector
vw
ut
v = w × u
w = – g|g|
u =|t × w|t × w
Werner Purgathofer / Einf. in Visual Computing
Viewing: Camera Transformation (3)
24
aligning viewing system with world-coordinate axes using translate-rotate transformations
Mcam = Rz· Ry· Rx·T
x
y
z
o
uvw
e
x
y
z
uv
wx
y
z
ouv
we
Werner Purgathofer / Einf. in Visual Computing
For Now: Parallel (Orthographic) Projection
Werner Purgathofer 26
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Viewing: Camera + Projection + Viewport
27
xscreenyscreen
z1
= Mvp·Morth·Mcam ·
xyz1
pixels onthe screen
world coordinates
( )
Werner Purgathofer / Einf. in Visual Computing
For Now: Parallel (Orthographic) Projection
Werner Purgathofer 28
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Perspective Projection
Perspective Projection
30
perspective projection of equal-sized objects at different distances from the view plane
x
y
zview plane
projection reference
point
Werner Purgathofer / Einf. in Visual Computing
Parallel vs. Perspective Projection
31
parallel projection: preserves relative proportions & parallel features (affine transform.)
perspective projection: center of projection, realistic views
Werner Purgathofer / Einf. in Visual Computing
Perspective Transform
32
N F
T
B
O
Werner Purgathofer / Einf. in Visual Computing
Perspective Transformation
33
fypO
view plane
yp = yfz
z
y
f … focal length
derivation of perspective
transformation
Werner Purgathofer / Einf. in Visual Computing
yp fzy =
Perspective Transformation
34
fz
yp
y
view plane
yp = yfz
(z=N)
O(z=0)
N
N N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0
= P
xp = xdzNanalogous:
derivation of perspective
transformation
Werner Purgathofer / Einf. in Visual Computing
Perspective Transformation
35
N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0
xyz1
· =
x·Ny·N
z·(N+F) –F·Nz
~>
x·N/zy·N/z
(N+F) –F·N/z1
homogenization: divide by z
yp = yz
xp = xzN
N
P =derivation of
perspective transformation
Werner Purgathofer / Einf. in Visual Computing
Example: (Right) Top Near Corner
36
N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0
RTN1
· =
R·NT·N
N·(N+F) –F·NN
~>
RTN1
x (B or T or L or R)
view plane
NO
F
Werner Purgathofer / Einf. in Visual Computing
Example: (Left) Top Far Corner
37
N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0
L·F/NT·F/N
F1
· =
L·FT·F
F·(N+F) –F·NF
~>
LTF1
x (B or T or L or R)
NO
F
view plane x·F/N
Werner Purgathofer / Einf. in Visual Computing
Perspective Transform
38
N F
T
B
O
Werner Purgathofer / Einf. in Visual Computing
Nonlinear z-Behaviour
39Werner Purgathofer / Einf. in Visual Computing
Nonlinear z-Behaviour
40Werner Purgathofer / Einf. in Visual Computing
From Object Space to Screen Space
Werner Purgathofer 41
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
Viewing: Camera + Projection + Viewport
42
xscreenyscreen
z´1
= Mvp·Morth·P·Mcam ·
xyz1
( )
Mper
pixels onthe screen
world coordinates
Werner Purgathofer / Einf. in Visual Computing
From Object Space to Screen Space
Werner Purgathofer 43
object space world space camera space
clip space pixel space
„view frustum“modeling
transformationcamera
transformation
projectiontransformation
viewporttransformation
z-Values Remain in Order
44Werner Purgathofer
N 0 0 00 N 0 00 0 N+F –F·N0 0 1 0
xyz1
· ~>
x·N/zy·N/z
(N+F) –F·N/z1
z1, z2, N, F < 0z1 < z2
1/z1 > 1/z2 | · (–F·N) (<0)– F·N/z1 < – F·N/z2 | + (N+F)(N+F) – F·N/z1 < (N+F) – F·N/z2
Werner Purgathofer / Einf. in Visual Computing
Perspective Projection Properties
parallel lines parallel to view plane ⇒ parallel linesparallel lines not parallel to view plane ⇒ converging lines (vanishing point)lines parallel to coordinate axis ⇒principal vanishing point (one, two or three)
45Werner Purgathofer / Einf. in Visual Computing
Principle Vanishing Points
46
2-point perspectiveprojection
3-point perspectiveprojection
1-pointperspectiveprojection
vanishing point
Werner Purgathofer / Einf. in Visual Computing