1
Projection
Tong-Yee Lee
2
Projection
3
Projection
4
View frustrum
culling
Readings
5
From view to projection�i.e., perspective and parallel
6
From right hand to left hand
Perspective(透視投影)v.s. Orthographic (正投影) projection
7
From right hand to left hand
8
Orthographic (正投影) projection
9
From right hand to left hand
Parallel and Perspective Projection
10
11
Near clipping plane
Perspective view to Normalized Coordinates
12
13
14
Oblique parallel projection
16
Parallel
Volume
Rendering
17
18
Multi-view Orthographic
20
Zs is lost , so it can not be used for Visible Surface Removal!!!
21
Note that projection vector d (dx, dy,dz,0) is specified from -Z toward Z in the eye space coordinate
d=(0,0,1,0)
d (dx, dy,dz,0)
22
23
What OpenGL wants is:
After projection, the image
space (after division)
become …….
Regardless
of parallel
projection or
perspective
projection!!!
Parallel Projection in OpenGL glortho(l,r,b,t,n,f)
24
+X
-Z
r
l
(x’, 0)
+X
-Z
+1
-1
Translate and Scale
d=(0,0,1,0)
25
negate Z
Parallel Projection Matrix in OpenGL
Image space in
right hand system
Image space in left hand system (OpenGL)
26
This row will not affect the projection!!!
Only affect the Zs value!
And substitute the following to solve A and B
27
Final Parallel Projection Matrix in OpenGL
glOrtho(l,r,b,t,n,f)
Zs is not lost
Zs is lost
Zs is good for
Hidden Surface
Removal !!!
So, we want
this model!!
In parallel projection, w term also is 1.We do not need division!!
28
What OpenGL wants is:
After projection, the image
space (after division)
become …….
Regardless of parallel projection or perspective projection!!!
29
Object is distorted in screen
space but the projection result
is still same!!
30
31
(針孔成像模型)
鏡頭焦距
32
33
34
35
36
37
38
39
Zs is lost again!!
OR
Remember
this!!
40
41
42
In the image (screen)
space coordinate
(left hand system)
(after division)
In the eye space coordinate
(right-hand system)
43
Object is distorted in screen space
but the projection result is still same!!
44
-
3D NDC to 2D Image (Near) Plane
Chapter 14
Resulting image �on the near plane
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer
46
Note
(1) X, Y, Z axis are
named u,v,w in the following
discussions!
fovx and fovy are assumed
to be equal
47
Note that the representation
of point transform is different
from the previous one in the
following discussions:
For example:
Old
New
48
49
Good when we choose a canonical
screen space volume or clipping volume
Clipping Space Coordinate
50
In clipping coordinate space, we perform clipping.
We can therefore save division if points are outside
the frustum of clipping coordinate space
We will teach clipping soon!
51
52
Something Interesting …Clipping
What does it imply?
Remember if a point is behind eye, we can not
see it!!. i.e., w > 0, means it is behind eye.
So, we can check the fourth item (before division).
If the fourth item is negative, this point is behind
the eye point.
53
We neglect scales at
X and Y first and we
Will compute them latter
54
the near plane (w = - n ) goes to the face w = -1 of the image space cube
, and the face defined by the far plane (w = - f ) goes to the face w = 1 of
the image space cube.
That’s
(0,0,-n)P = (0,0,-1)
(0,0,-f)P = (0,0,1)
Note that in image space
(after division)
55
56
We want to map them to (0,0,-1) and (0,0,1)
So,
57
We should also note that
(1) the above P has transformed any
point to image space (left hand system (n=-1, f = 1)).
So, as Zs is larger, it means it is far away from camera.
(2) Point in image space will not lost its Zs component!!
Zs is lost
58
59
So, after division, we get :
But, we want this term
to be 1.
Scale can help ……….
60
Before we apply projection, we scale X, Y …………..
61
Re-organize our Representation !!!!
Eye space
Clipping space
division
Image (screen) space
fovx and fovy
can be different!!
62
Furthermore ………………
gluFrustum (l, r, b, t, n, f)
when r = - l , b = -t , we will have
a symmetric frustrum
-Z
-X
eye
Z = - n
-r
r
63
Final Projection Matrix Used in OpenGL gluPerspective(angle,aspect,n,f)
-Z
+X
eye
Z = - n
l
r
64
65
Programmer must responsibly specify correct ratio
in viewport glViewport(x,y, w,h).
Otherwise, the result will be distorted.
66
67
For example: when zc = 0;
Eye (Xc,Yc,Zc,1) = (0,0,0,1)
P(Eye): z’c = -2fn/(f-n), w’c=0;
Inside –w’c <=z’c<=w’c
So, P(EYE) is outside, so, we avoid division by zero
68
Normalized Device Coordinate
To Window Coordinate
69
Viewport transformation
70
Mapping from Window Coordinate to Monitor Screen Coordinate
71
(0,0)
(xmax,ymax)
Monitor Screen
Coordinate
(0,0)
(xmax,ymax)
Window
coordinate
glutInitWindowsize(w,h)�glutInitWindowposition(x,y)
72
(x,y)
w
h
(0,0)
Monitor
Screen
window
73
(0,0)
(xmax’,ymax’)
Monitor Screen
Coordinate
(xmax,ymax)
Window
coordinate
(x,y)
(0,0)
w
h
w
h
(x1,y1)
(x2,y2)
74
75
View Frustum Culling
Depth Buffer
76
Z-buffer
77
Z-buffer
78
For trivial setting Zn, Zf value such as Zn = 0, Zf = 10000000.
Then, each polygon’s Z-value of above equation is close to 1, so we need more depth resolution (i.e., more bits per pixel to represent Z-buffer value) of Z-buffer to make difference. Otherwise, the about the value of above equation is almost the same (i.e., close to 1, so we can not make difference).
Z-buffer
79
80
gluPerspective(60.0, 1.3, 1.0, 300000000.0);
gluPerspective(60.0, 1.3, 100000000.0, 300000000.0);
A good advice: first check the bounding box containing your scene and then make your near plane away from your eye and close to far plane as possibly as you could.