1 / 67

Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University. Hidden-Surface Removal. Back-Face Culling The Depth-Sort Algorithm Binary Space-Partitioning Trees The z-Buffer Algorithm Visible-Surface Ray Tracing (Ray Casting) Space S ubdivision A pproaches.

martha-byrd
Download Presentation

Computer Graphics

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. Computer Graphics Bing-Yu ChenNational Taiwan University

  2. Hidden-Surface Removal • Back-Face Culling • The Depth-Sort Algorithm • Binary Space-Partitioning Trees • The z-Buffer Algorithm • Visible-Surface Ray Tracing(Ray Casting) • Space SubdivisionApproaches

  3. Hidden-Surface Removal=Visible-Surface Determination • Determining what to render at each pixel. • A point is visible if there exists a direct line-of-sight to it, unobstructed by another other objects (visible surface determination). • Moreover, some objects may be invisible because there are behind the camera, outside of the field-of-view, too far away (clipping) or back faced (back-face culling).

  4. Hidden Surfaces: why care? • Occlusion: Closer (opaque) objects along same viewing ray obscure more distant ones. • Reasons for removal • Efficiency: As with clipping, avoid wasting work on invisible objects. • Correctness: The image will look wrong if we don’t model occlusion properly.

  5. x B A C D E F H z G Back-Face Culling = Front Facing

  6. v1 N v2 V v3 Back-Face Culling = Front Facing • use cross-product to get the normal of the face (not the actual normal) • use inner-product to check the facing

  7. Clipping (View Frustum Culling) view frustum occlusion back face eye view frustum

  8. List-Priority Algorithms • The Painter’s Algorithm • The Depth-Sort Algorithm • Binary Space-Partitioning Trees

  9. The Painter’s Algorithm • Draw primitives from back to front need for depth comparisons.

  10. The Painter’s Algorithm • for the planes with constant z • not for real 3D, just for 2½D • sort all polygons according to the smallest (farthest) z coordinate of each • scan convert each polygon in ascending order of smallest z coordinate (i.e., back to front)

  11. The Depth-Sort Algorithm • sort all polygons according to the smallest (farthest) z coordinate of each • resolve any ambiguities that sorting may cause when the polygons’z extents overlap, splitting polygons if necessary • scan convert each polygon in ascending order of smallest z coordinate (i.e., back to front)

  12. y y x R Q P P Q Q P z x Overlap Cases x

  13. Binary Space-Partitioning Trees • An improved painter’s algorithm • Key observation: T3 T1 T5 T2 T4

  14. - + T1 T3 Binary Space-Partitioning Trees T2 T3 T1 T2

  15. - - + + T1 T2 T3 Binary Space-Partitioning Trees T1 T3 T2

  16. a A c B b Splitting triangles a A c B b

  17. BSP Tree Construction BSPtree makeBSP(L: list of polygons) { if (L is empty) { return the empty tree; } Choose a polygon P from L to serve as root; Split all polygons in L according to P return new TreeNode ( P, makeBSP(polygons on negative side of P), makeBSP(polygons on positive side of P)) } • Splitting polygons is expensive! It helps to choose P wisely at each step. • Example: choose five candidates, keep the one that splits the fewest polygons.

  18. BSP Tree Display void showBSP(v: Viewer, T: BSPtree) { if (T is empty) return; P = root of T; if (viewer is in front of P) { showBSP(back subtree of T); draw P; showBSP(front subtree of T); } else { showBSP(front subtree of T); draw P; showBSP(back subtree of T); } } 2D BSP demo

  19. Binary Space-Partitioning Trees • Same BSP tree can be used for any eye position, constructed only once if the scene if static. • It does not matter whether the tree is balanced. However, splitting triangles is expensive and try to avoid it by picking up different partition planes.

  20. BSP Tree 6 5 9 7 10 8 1 11 2 4 3

  21. BSP Tree 6 1 5 outside ones inside ones 9 7 10 8 1 11 2 4 3

  22. BSP Tree 6 1 5 5 6 7 8 9 10 11 2 3 4 9 7 10 8 1 11 2 4 3

  23. BSP Tree 1 6 5 5 9b 9 6 7 9a 10 11a 8 9b 11b 7 10 11b 8 9a 1 11 11a 2 4 3

  24. BSP Tree 6 5 1 5 2 9b 9 7 8 3 6 10 11b 8 9a 1 9b 7 4 11 11a 2 9a 11b 4 10 3 11a

  25. BSP Tree 6 5 1 5 2 9b 9 7 8 3 10 11b 6 8 9a 1 9b 7 4 11 11a 2 9a 11b 4 point 10 3 11a

  26. BSP Tree Traversal 6 5 1 9b 5 2 9 7 10 11b 8 3 6 8 9a 1 9b 7 4 11 11a 2 9a 11b 4 point 3 10 11a

  27. BSP Tree Traversal 6 5 1 9b 5 2 9 7 10 11b 8 3 6 8 9a 1 9b 7 4 11 11a 2 9a 11b 4 point 3 10 11a

  28. The z-Buffer Algorithm • Resolve depths at the pixel level • Idea: add Z to frame buffer, when a pixel is drawn, check whether it is closer than what’s already in the frame buffer

  29. + = = + The z-Buffer Algorithm

  30. The z-Buffer Algorithm void zBuffer() { int pz; for (each polygon) { for (each pixel in polygon’s projection) { pz=polygon’s z-value at (x,y); if (pz>=ReadZ(x,y)) { WriteZ(x,y,pz); WritePixel(x,y,color); } } } }

  31. y z1 y1 zp za zb Scan line ys y2 z2 y3 z3 The z-Buffer Algorithm

  32. z-Buffer: Example color buffer depth buffer

  33. The z-Buffer Algorithm • Benefits • Easy to implement • Works for any geometric primitive • Parallel operation in hardware • independent of order of polygon drawn • Limitations • Memory required for depth buffer • Quantization and aliasing artifacts • Overfill • Transparency does not work well

  34. Ray Tracing = Ray Casting select center of projection and window on viewplane; for (each scan line in image) { for (each pixel in scan line) { determine ray from center of projection through pixel; for (each object in scene) { if (object is intersected and is closest considered thus far) record intersection and object name; } set pixel’s color to that at closest object intersection; } }

  35. Center ofprojection Window Ray Casting

  36. Ray Casting (Appel, 1968)

  37. Ray Casting (Appel, 1968)

  38. Ray Casting (Appel, 1968)

  39. Ray Casting (Appel, 1968)

  40. Ray Casting (Appel, 1968) direct illumination

  41. Spatial Partitioning

  42. R C A B Spatial Partitioning

  43. 1 A B 3 2 Spatial Partitioning

  44. Space SubdivisionApproaches Uniform grid K-d tree

  45. Space SubdivisionApproaches Quadtree (2D) Octree (3D) BSP tree

  46. Uniform Grid

  47. Preprocess scene Find bounding box Uniform Grid

  48. Preprocess scene Find bounding box Determine grid resolution Uniform Grid

  49. Preprocess scene Find bounding box Determine grid resolution Place object in cell if its bounding box overlaps the cell Uniform Grid

  50. Preprocess scene Find bounding box Determine grid resolution Place object in cell if its bounding box overlaps the cell Check that object overlaps cell (expensive!) Uniform Grid

More Related