530 likes | 819 Views
Hidden Surface Elimination. I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 8. Wen-Chieh (Steve) Lin Institute of Multimedia Engineering. Hidden Surface Elimination (Removal).
E N D
Hidden Surface Elimination I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 8 Wen-Chieh (Steve) Lin Institute of Multimedia Engineering
Hidden Surface Elimination (Removal) • In a 3D wireframe displayer, the line segments between projected point pairs are drawn. • To fill projected polygons, we have to remove “hidden surfaces”. ILE5014 Computer Graphics 10F
Hidden Surface Elimination (Removal) • Object (Model) Space Algorithms • Work in the model data space • Image Space Algorithms • Work in the projected space • Most common domain for hidden surface removal ILE5014 Computer Graphics 10F
Hidden Surface Removal • Object-space approach: use pairwise testing between polygons (objects) • Worst case complexity O(n2) for n polygons ILE5014 Computer Graphics 10F
Backface Culling View ILE5014 Computer Graphics 10F
Back Face Culling: Object Space v v z v v ILE5014 Computer Graphics 10F
Back Face Culling: Object Space Visible: v v z ILE5014 Computer Graphics 10F
Back Face Culling Test • For Object Space look at sign of • For Image Space look at sign of ILE5014 Computer Graphics 10F
Back Face Culling: Image Space z ILE5014 Computer Graphics 10F
Back Face Culling: Image Space z Visible: ILE5014 Computer Graphics 10F
Painter’s Algorithm • Render polygons in a back to front order so that polygons behind others are simply painted over • Depth sort method ILE5014 Computer Graphics 10F
Depth Sort Method • Requires ordering of polygons first • O(n log n) calculation for ordering • Not every polygon is either in front or behind all other polygons • Sort polygons and deal with easy cases first, harder later ILE5014 Computer Graphics 10F
Easy Cases • A polygon lies behind all other polygons • Can render • Polygons overlap in z but not in either x or y • Can render independently z z ILE5014 Computer Graphics 10F
Difficult Cases cyclic overlap penetration ILE5014 Computer Graphics 10F
Space Partitioning • Avoid rendering an object when it’s unnecessary • In many real-time applications, we want to eliminate as many objects as possible within the application. • Reduce burden on pipeline • Reduce traffic on bus • Octree • BSP tree ILE5014 Computer Graphics 10F
Octree http://www.imagico.de/fast_iso/patch.html ILE5014 Computer Graphics 10F
Why do we use BSP trees? • Hidden surface removal • A back-to-front painter’s algorithm • Partition space with Binary Spatial Partition (BSP) Tree ILE5014 Computer Graphics 10F
A Simple Example top view The plane of A separates B and C from D, E and F ILE5014 Computer Graphics 10F
Binary Space Partitioning Tree • Can continue recursively • Plane of A separates C from D • Plane of D separates E and F • Can put this information in a BSP tree • Use for visibility and occlusion testing ILE5014 Computer Graphics 10F
Key Ideas of BSP • Assume T2 not cross the plane of T1 • If e and T2 on the same side, T1 won’t block • If e and T2 on different sides, T1 may block ILE5014 Computer Graphics 10F
What if a triangle cross a plane of another triangle? • Break the triangle into three! ILE5014 Computer Graphics 10F
Creating a BSP tree 2 0 2 1 1 3 5b 3 5b 4b 4f 4b 5f 4f 5f 4 -> 4f,4b 0 ILE5014 Computer Graphics 10F
Back-to-Front Render Render(node, view){ if node is a leaf draw this node to the screenelse if the viewpoint is in back of the dividing line { render(front subtree) draw node to screen render(back subtree) } else the viewpoint is in front of the dividing line { render (back subtree) draw node to screen render (front subtree) } ILE5014 Computer Graphics 10F
Back-to-Front Render 0 2 0 2 1 1 3 5b 3 5b 4b 4f 4b 5f 5f 4f 5b 1 4f 3 5f 4b 0 2 ILE5014 Computer Graphics 10F
Back-to-Front Render 0 2 0 2 1 1 3 5b 3 5b 4b 4f 4b 5f 5f 4f 2 0 5b 1 4f 3 5f 4b ILE5014 Computer Graphics 10F
Optimizing BSP Tree 1 2 2 1f 1b • Efficiency of tree traversal is more important than tree construction • Speed determined by the number of nodes • Fewer nodes if less node splitting • Order of adding triangles determines the number of nodes in a BSP • Choose a better ordering from a random collection of permutations ILE5014 Computer Graphics 10F
BSP-based Culling • Pervasively used in first person shooting games. • Doom, quake….etc. • Visibility test • Skip objects that are “occluded”. a screen shot from Doom. ILE5014 Computer Graphics 10F
Image Space Approach ILE5014 Computer Graphics 10F
Image Space Approach • Look at each projector (nm for an nm frame buffer) and find the k closest polygons • Complexity O(nmk) • z-buffer • Ray casting ILE5014 Computer Graphics 10F
z-Buffer Algorithm • The z or depth buffer • stores the depth of the closest object at each pixel found so far • As we render each polygon, compare the depth of each pixel to depth in z buffer • If less, place the shade of pixel in the color buffer and update z buffer ILE5014 Computer Graphics 10F
z-Buffer Algorithm Function setpixel(int i, int j, rgb c, real z) If z > z-buffer(i, j) then z-buffer(i, j) = z screen(i,j) = c ILE5014 Computer Graphics 10F
Interpolation of Z values A’ C’ B’ A C B Projection plane focus ILE5014 Computer Graphics 10F
Interpolation of Z values zt za zb • To fill the polygon on the screen, we only fill the color and estimate the z value “pixel by pixel”. • How to estimate z of in-between pixels ? z1 z2 z3 ILE5014 Computer Graphics 10F
Screen Space vs. 3D Space • Interpolation in screen space • P(m) = P1 + m(P2 – P1) • Interpolation in 3D space • V(n) = V1 + n(V2 – V1) • Py(n) / f = Vy(n) / Vz(n) n ≠ m V1 m P1 P2 V2 n f ILE5014 Computer Graphics 10F
Scan Conversion of Polygon P Suppose plane equation for P is Solving for z, ILE5014 Computer Graphics 10F
Scan Conversion of Polygon P (2) ILE5014 Computer Graphics 10F
Scan Conversion of Polygon P (3) is first z-value on scanline, Consider , next z-value on scanline, ILE5014 Computer Graphics 10F
Scan Conversion of Polygon P (4) In incremental terms, ILE5014 Computer Graphics 10F
Scan Conversion of Polygon P (5) Assume , And note , Therefore, One add (subtract) generates the next ILE5014 Computer Graphics 10F
Incremental Approach • Can efficiently generate z-values incrementally • Can use Bresenham to grow the edges efficiently after direct evaluation at vertices ILE5014 Computer Graphics 10F
Integer Z-buffer • If B bins are used for depth range (n, f) • Bin size △z = (n-f)/B • Smaller △z is desirable • Depth of two objects are indistinguishable if △z is larger than the difference between their real z-values • Increase B • Move n and f closer ILE5014 Computer Graphics 10F
Bin size for z-buffer in world space • Take perspective into account • Differentiating both side • Bin sizes vary in depth • The bin size in world space is ILE5014 Computer Graphics 10F
Bin size for z-buffer in world space • Bin size in the world space increases as depth increases • Objects farther away is more likely to be indistinguishable in depth (same integer z-values) • Maximize n and minimize f for small △zw zw=f ILE5014 Computer Graphics 10F