Projection And Bounding Box culling TongYee Lee 1
Projection And Bounding Box culling Tong-Yee Lee 1
Readings Computer Graphics Using Open. GL by F. S Hill, J. R. Chapter 7 2
Perspective(透視投影)v. s. Orthographic (正投影) projection 3
Projection in standard CG pipeline 4
5
6
7
8
9
Image plane is Z = 0 Zs is lost , so it can not be used for Visible Surface Removal!!! 10
d (dx, dy, dz, 0) d=(0, 0, 1, 0) Note that projection vector d (dx, dy, dz, 0) is specified from -Z toward Z in the eye space coordinate 11
What Open. GL wants is: Regardless of parallel projection or perspective projection!! ! After projection, the image space (after division) become ……. (1) Left hand system (2) -1<=xs, ys, zs <=1 12
-Z Parallel Projection in Open. GL glortho(l, r, b, t, n, f) -Z Translate and Scale l (x’, 0) r +X d=(0, 0, 1, 0) -1 +1 +X 13
Parallel Projection Matrix in Open. GL Image space in right hand system negate Z Image space in left hand system (Open. GL) 14
This row will not affect the projection!!! Only affect the Zs value! And substitute the following to solve A and B 15
Final Parallel Projection Matrix in Open. GL gl. Ortho(l, r, b, t, n, f) In parallel projection, w term also is 1. We do not need division!! Zs is good for Hidden Surface Removal !!! So, we want this model!! Zs is not lost Zs is lost 16
Object is distorted in screen space but the projection result is still same!! 17
18
(針孔成像模型) Generally, graphics is pinhole camera-like model! Lens (鏡頭) 19
20
22
23
i. e. same正切 tangent (tan) 24
25
26
OR Remember this!! Zs is lost again!! 27
We will introduce bounding box or sphere to accelerate culling test!! 28
29
(after division) In the eye space coordinate (right-hand system) In the image (screen) space coordinate (left hand system) 30
Object is distorted in screen space but the projection result is still same!! 31
- 32
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer 3 D NDC to 2 D Image (Near) Plane Resulting image on the near plane Chapter 14
fovx and fovy are assumed to be equal Note (1) X, Y, Z axis are named u, v, w in the following discussions! 34
Note that the representation of point transform is different from the previous one in the following discussions: For example: Old New 35
36
Good when we choose a canonical screen space volume or clipping volume Clipping Space Coordinate 37
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! 38
39
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. 40
We neglect scales at X and Y first and we Will compute them latter 41
the near plane (w = - n ) goes to the face w = -1 of the image space cub , and the face defined by the far plane (w = - f ) goes to the face w = 1 of the image space cube. That’s Note that in image space (0, 0, -n)P = (0, 0, -1) (after division) (0, 0, -f)P = (0, 0, 1) 42
43
We want to map them to (0, 0, -1) and (0, 0, 1) So, 44
We should also note that (1) the above P has transformed any point to image space (left hand system (n=-1, f = 1)). Zs is lost So, as Zs is larger, it means it is far away from camera. (2) Point in image space will not lost its Zs component!! 45
46
But, we want this term to be 1. So, after division, we get : 47
Scale can help ………. Before we apply projection, we scale X, Y …………. . 48
Re-organize our Representation !!!! Clipping space division Eye space fovx and fovy can be different!! Image (screen) space 49
Furthermore ……………… glu. Frustum (l, r, b, t, n, f) when r = - l , b = -t , we will have a symmetric frustrum -X -r -Z eye Z=-n r 50
How about asymmetric frustrum ? 51
52
53
54
asymmetric frustum Left-right asymmetric eye viewing 55
Final Projection Matrix Used in Open. GL gl. Frustum(l, r, b, t, n, f) 56
Final Projection Matrix Used in Open. GL glu. Perspective(angle, aspect, n, f) We use angle and aspect ratio to find l, r, t, b by the following…. . l -Z eye Z=-n r +X 57
Programmer must responsibly specify correct ratio in viewport gl. Viewport(x, y, w, h). Otherwise, the result will be distorted. 58
59
For example: when zc = 0; Eye (Xc, Yc, Zc, 1) = (0, 0, 0, 1) P(Eye): z’c = -2 fn/(f-n), w’c=0; Inside –w’c <=z’c<=w’c So, P(EYE) is outside, so, we avoid division by zero 60
Normalized Device Coordinate To Window Coordinate glviewport(lv, bv, w, h) rv=lv+(w-1), tv=bv+(h-1) Zs will be translated and scaled to be (0, 1) 61
62
63
Mapping from Window Coordinate to Monitor Screen Coordinate Usually done by your window system for you. Screen Coordinate: (0, 0) is at left-top corner and y is increasing downward the screen (0, 0) (xmax, ymax) Monitor Screen Coordinate (0, 0) Window coordinate (xmax, ymax) 64
glut. Init. Windowsize(w, h) glut. Init. Windowposition(x, y) (0, 0) (x, y) w h Monitor Screen window 65
(0, 0) w (xmax, ymax) (x 1, y 1) (0, 0) h Window coordinate (x, y) h (x 2, y 2) Monitor Screen Coordinate w (xmax’, ymax’) 66
67
View Frustum Culling 68
Ax+By+Cz+D=0, six planes are required for view frustum; it is not easy to directly find each plane! Fortunately, we can obtain six planes from 69 PROJECTION and MODELVIEW matrices
70
Clipping space coordinate projection eye transform 71
72
73
Therefore, the clipping volume has six clipping planes. The right clipping plane can be determined by 74
in = (X, Y, Z, 1) So, we find the equation of right plane distance =(AX+BY+CZ+D)/sqrt(A^2+B^2+C^2) 75
76
77
Bounding Volume n n n Simple shape that completely encloses an object Generally a box or sphere We’ll use spheres: n n Easiest to work with Though hard to get tight fits 78
79
If this sphere is outside for one plane, then this sphere is outside the Frustrum! d <= -radius |d|>= radius 80
LOD (level of details) d+r r d Near plane 81
Invisible Condition: eight corners are all outside for any specific plane!!! Eight corners are outside, but still visible!! 82
Center is at (x, y, z) Left(x-size, ? ), right(x+size, ? ) If one case > 0 Then we stop checking this plane! When all cases <0 for a plane This means this Cube is out of this plane and returns false 83
d>r Good for hierarchical FOV culling For example, it is a bounding sphere tree 84
85
86
87
88
Culling: doing a trivial reject test to avoid drawing objects that aren’t in the view volume. Open. GL/GPU will do it but you don’t want to waste time sending data that won’t be used Test if each object is inside or outside view volume or on the border: clipping (in a few weeks) Too much work to test real object Instead, introduce bounding volumes
Culling complex objects or groups n n If an object is big and complex, it’s possible that only parts of it will be in view. Or if we have groups of objects, it’s possible that entire groups will be out of view. n n Want to be able to cull the whole group quickly But if the group is partly in and partly out, want to be able to cull individual objects. 90
Hierarchical bounding volumes n If you have a hierarchy of objects or parts, make a hierarchy of bounding volumes n n The bounding volume of each node encloses the bounding volumes of all its children Start by testing the outermost bounding volume n n If it’s entirely out, don’t draw the group at all If it’s entirely in, draw the whole group 91
Hierarchical culling n If the outermost bounding volume is partly inside and partly outside the view volume: n n n Test each child’s bounding volume individually If the child is in, draw it; if it’s out cull it; if it’s partly in and partly out, recurse. If recursion reaches a leaf node, draw it normally 92
Depth Buffer 93
Z-buffer 94
Z-buffer 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). 95
Z-buffer 96
glu. Perspective(60. 0, 1. 3, 1. 0, 30000. 0); glu. Perspective(60. 0, 1. 3, 10000. 0, 30000. 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. 97
- Slides: 97