Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.

Similar presentations


Presentation on theme: "Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals."— Presentation transcript:

1 Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 8

2 ILE5014 Computer Graphics 10F 2 Outline Backface culling BSP tree Z-buffer

3 ILE5014 Computer Graphics 10F 3 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”.

4 ILE5014 Computer Graphics 10F 4 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

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

6 ILE5014 Computer Graphics 10F 6 Backface Culling View

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

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

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

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

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

12 ILE5014 Computer Graphics 10F 12 Painter’s Algorithm Render polygons in a back to front order so that polygons behind others are simply painted over Depth sort method

13 ILE5014 Computer Graphics 10F 13 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

14 ILE5014 Computer Graphics 10F 14 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

15 ILE5014 Computer Graphics 10F 15 Difficult Cases cyclic overlap penetration

16 ILE5014 Computer Graphics 10F 16 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

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

18 ILE5014 Computer Graphics 10F 18 Why do we use BSP trees? Hidden surface removal – A back-to-front painter’s algorithm Partition space with Binary Spatial Partition (BSP) Tree

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

20 ILE5014 Computer Graphics 10F 20 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

21 ILE5014 Computer Graphics 10F 21 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

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

23 ILE5014 Computer Graphics 10F 23 Creating a BSP tree 0 0 1 1 2 2 3 3 4 -> 4f,4b 4f 4b 4f4b 5f 5b 5f 5b

24 ILE5014 Computer Graphics 10F 24 Back-to-Front Render Render(node, view){ if node is a leaf draw this node to the screen else 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) }

25 ILE5014 Computer Graphics 10F 25 0 0 1 1 2 2 3 3 4f 4b 4f4b 5f 5b 5f 5b 5b  1  4f  3  5f  4b  0  2 Back-to-Front Render

26 ILE5014 Computer Graphics 10F 26 0 0 1 1 2 2 3 3 4f 4b 4f4b 5f 5b 5f 5b 2  0  5b  1  4f  3  5f  4b Back-to-Front Render

27 ILE5014 Computer Graphics 10F 27 Optimizing BSP Tree 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 2 1b1f 1 2

28 ILE5014 Computer Graphics 10F 28 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.

29 ILE5014 Computer Graphics 10F 29 Image Space Approach

30 ILE5014 Computer Graphics 10F 30 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

31 ILE5014 Computer Graphics 10F 31 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

32 ILE5014 Computer Graphics 10F 32 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

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

34 ILE5014 Computer Graphics 10F 34 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 ? z1z1 z2z2 z3z3 zaza zbzb ztzt Interpolation of Z values

35 ILE5014 Computer Graphics 10F 35 Interpolation in screen space – P(m) = P 1 + m(P 2 – P 1 ) Interpolation in 3D space – V(n) = V 1 + n(V 2 – V 1 ) – P y (n) / f = V y (n) / V z (n) P1P1 P2P2 V1V1 V2V2 m n n ≠ m Screen Space vs. 3D Space f

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

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

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

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

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

41 ILE5014 Computer Graphics 10F 41 Incremental Approach Can efficiently generate z-values incrementally Can use Bresenham to grow the edges efficiently after direct evaluation at vertices

42 ILE5014 Computer Graphics 10F 42 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

43 ILE5014 Computer Graphics 10F 43 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

44 ILE5014 Computer Graphics 10F 44 Recall Perspective Projection

45 ILE5014 Computer Graphics 10F 45 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 △ z w z w =f

46 ILE5014 Computer Graphics 10F 46 Scan-Line Algorithm Can combine shading and hidden surface removal through scan line algorithm


Download ppt "Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals."

Similar presentations


Ads by Google