1 / 43

Hidden Surface Elimination

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).

grazia
Download Presentation

Hidden Surface Elimination

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. Hidden Surface Removal • Object-space approach: use pairwise testing between polygons (objects) • Worst case complexity O(n2) for n polygons ILE5014 Computer Graphics 10F

  5. Backface Culling View ILE5014 Computer Graphics 10F

  6. Back Face Culling: Object Space v v z v v ILE5014 Computer Graphics 10F

  7. Back Face Culling: Object Space Visible: v v z ILE5014 Computer Graphics 10F

  8. Back Face Culling Test • For Object Space look at sign of • For Image Space look at sign of ILE5014 Computer Graphics 10F

  9. Back Face Culling: Image Space z ILE5014 Computer Graphics 10F

  10. Back Face Culling: Image Space z Visible: ILE5014 Computer Graphics 10F

  11. 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

  12. 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

  13. 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

  14. Difficult Cases cyclic overlap penetration ILE5014 Computer Graphics 10F

  15. 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

  16. Octree http://www.imagico.de/fast_iso/patch.html ILE5014 Computer Graphics 10F

  17. 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

  18. A Simple Example top view The plane of A separates B and C from D, E and F ILE5014 Computer Graphics 10F

  19. 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

  20. 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

  21. What if a triangle cross a plane of another triangle? • Break the triangle into three! ILE5014 Computer Graphics 10F

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. Image Space Approach ILE5014 Computer Graphics 10F

  29. Image Space Approach • Look at each projector (nm for an nm frame buffer) and find the k closest polygons • Complexity O(nmk) • z-buffer • Ray casting ILE5014 Computer Graphics 10F

  30. 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

  31. 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

  32. Interpolation of Z values A’ C’ B’ A C B Projection plane focus ILE5014 Computer Graphics 10F

  33. 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

  34. 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

  35. Scan Conversion of Polygon P Suppose plane equation for P is Solving for z, ILE5014 Computer Graphics 10F

  36. Scan Conversion of Polygon P (2) ILE5014 Computer Graphics 10F

  37. Scan Conversion of Polygon P (3) is first z-value on scanline, Consider , next z-value on scanline, ILE5014 Computer Graphics 10F

  38. Scan Conversion of Polygon P (4) In incremental terms, ILE5014 Computer Graphics 10F

  39. Scan Conversion of Polygon P (5) Assume , And note , Therefore, One add (subtract) generates the next ILE5014 Computer Graphics 10F

  40. 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

  41. 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

  42. 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

  43. 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

More Related