Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.

Similar presentations


Presentation on theme: "1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai."— Presentation transcript:

1 1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai

2 2 Image space Review: 3D Geometry Pipeline 2 Normalized project space View space World spaceObject space

3 3 3D Rendering Pipeline Modeling transformation lighting Viewing transformation Project transformation Clipping Scan conversion Image

4 4 Scan conversion 3D Rendering Pipeline Modeling transformation lighting Viewing transformation Project transformation Clipping Image Transform into 3D world system Illuminate according to lighting and reflectance Transform into 3D camera coordinate system Transform into 3D normalized project space Clip primitives outside camera’s view Draw pixels (includes texturing, hidden surface, etc.)

5 5 Image space 3D Geometry Pipeline 5 Normalized project space View space World spaceObject space

6 6 Hidden Surfaces

7 7

8 8

9 9 Polygon Mesh Representation

10 10 Hidden Surfaces Removal The goal is to determine which surfaces and parts of surfaces are not visible from a certain viewpoint A.K.A occlusion culling or visible surface determination

11 11 Outline Backface Culling Painter’s algorithm BSP Scanline Z-buffer Ray casting Required reading: section 16-1 to 16-11

12 12 Backface Culling Normalized project space

13 13 Backface Culling view direction Normalized project space

14 14 Backface Culling view direction Normalized project space

15 15 Backface Culling view direction

16 16 Backface Culling view direction, draw polygon

17 17 Backface Culling view direction, cull polygon

18 18 Backface Culling Is this all we have to do?

19 19 Backface Culling Is this all we have to do? No! - Can still have 2 (or more) front faces that map to the same screen pixel

20 20 Backface Culling Is this all we have to do? No! - Can still have 2 (or more) front faces that map to the same screen pixel - Which actually gets drawn?

21 21 Backface Culling Advantages  Improves rendering speed by removing roughly half of polygons from scan conversion Disadvantages  Assumes closed surface with consistently oriented polygons  NOT a true hidden surface algorithm!!!

22 22 Painter’s Algorithm Basic idea: similar to oil painting - draw background first - then most distant object - then nearer object - and so forth

23 23 Painter’s Algorithm Sort polygons according to distance from viewer Draw from back (farthest) to front (nearest) - the entire object Near objects will overwrite farther ones

24 24 Painter’s Example z = 0.7 z = 0.3 z = 0.1 Sort by depth: Green rect Red circle Blue tri z = 0

25 25 Painter’s Algorithm Does anyone see a problem with this?

26 26 Painter’s Algorithm Does anyone see a problem with this? - Objects can have a range of depth, not just a single value - Need to make sure they don’t overlap for this algorithm to work

27 27 Painter’s Algorithm Does anyone see a problem with this? - Objects can have a range of depth, not just a single value - Need to make sure they don’t overlap for this algorithm to work

28 28 Painter’s Algorithm 1. Sort all objects’ z min and z max

29 29 Painter’s Algorithm 1. Sort all objects’ z min and z max 2. If an object is uninterrupted (its z min and z max are adjacent in the sorted list), it is fine

30 30 Painter’s Algorithm 1. Sort all objects’ z min and z max 2. If an object is uninterrupted (its z min and z max are adjacent in the sorted list), it is fine 3. If 2 objects DO overlap 3.1 Check if they overlap in x - If not, they are fine 3.2 Check if they overlap in y - If not, they are fine - If yes, need to split one

31 31 Painter’s Algorithm The splitting step is the tough one - Need to find a plane to split one polygon so that each new polygon is entirely in front of or entirely behind the other - Polygons may actually intersect, so then need to split each polygon by the other

32 32 Painter’s Algorithm The splitting step is the tough one - Need to find a plane to split one polygon so that each new polygon is entirely in front of or entirely behind the other - Polygons may actually intersect, so then need to split each polygon by the other After splitting, you can resort the list and should be fine

33 33 Painter’s Algorithm-Summary Advantages - Simple algorithm for ordering polygons Disadvantages - Splitting is not an easy task - Sorting can also be expensive - Redraws same pixel many times

34 34 Binary Space Partitioning Trees Basic principle: Objects in the half space opposite of the viewpoint do not obscure objects in the half space containing the viewpoint; thus, one can safely render them without covering foreground objects 1 2 3 45 6 7

35 35 Binary Space Partitioning Trees Basic principle: Objects in the half space opposite of the viewpoint do not obscure objects in the half space containing the viewpoint; thus, one can safely render them without covering foreground objects 1 2 3 45 6 7 + -

36 36 Binary Space Partitioning Trees Basic principle: Objects in the half space opposite of the viewpoint do not obscure objects in the half space containing the viewpoint; thus, one can safely render them without covering foreground objects 1 2 3 45 6 7 If we want to draw 5 correctly - we need draw 6 and 7 first, - then draw 5, - then draw 1,2,3,4 + -

37 37 Binary Space Partitioning Trees Basic principle: Objects in the half space opposite of the viewpoint do not obscure objects in the half space containing the viewpoint; thus, one can safely render them without covering foreground objects 1 2 3 45 6 7 If we want to draw 5 correctly - we need draw 6 and 7 first, - then draw 5, - then draw 1,2,3,4 + - We need to do this for every polygon Can we do this more efficiently?

38 38 Binary Space Partitioning Trees Basic principle: Objects in the half space opposite of the viewpoint do not obscure objects in the half space containing the viewpoint; thus, one can safely render them without covering foreground objects 1 2 3 45 6 7 If we want to draw 5 correctly - we need draw 6 and 7 first, - then draw 5, - then draw 1,2,3,4 + - We need to do this for every polygon Can we do this more efficiently? BSP tree

39 39 Binary Space Partition Trees BSP tree: organize all of space (hence partition) into a binary tree - Preprocess: overlay a binary tree on objects in the scene - Runtime: correctly traversing this tree enumerates objects from back to front // similar to painter’s algorithm - Idea: divide space recursively into half-spaces by choosing splitting planes  Splitting planes can be arbitrarily oriented

40 40 Binary Space Partition Trees (1979) BSP tree: organize all of space (hence partition) into a binary tree - Preprocess: overlay a binary tree on objects in the scene - Runtime: correctly traversing this tree enumerates objects from back to front - Idea: divide space recursively into half-spaces by choosing splitting planes  Splitting planes can be arbitrarily oriented

41 41 BSP Trees: Objects 1 2 3 4 5 6 7 8 9

42 42 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 + -

43 43 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 98 5 614 23 Put front objects in the left branch 7 + - -+

44 44 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 98 5 614 23 Put front objects in the left branch 7 + - -+ ? ? - +

45 45 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 98 5 6 Put front objects in the left branch 7 + - -+ 14 23 - + 4

46 46 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 98 5 6 Put front objects in the left branch 7 + - -+ 14 23 - + 9?? -+ 4

47 47 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 98 5 614 23 Put front objects in the left branch 7 -+ - + -+

48 48 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8956 1 3 24 Put front objects in the left branch 7 -+ - + -+ - + - + - +

49 49 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Put front objects in the left branch 79 -+ - + -+ ++ - + -- + - + -

50 50 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Put front objects in the left branch 79 -+ - + -+ ++ - + -- + - + - When to stop the recursion?

51 51 Object Splitting No bunnies were harmed in my example But what if a splitting plane passes through an object?

52 52 Object Splitting No bunnies were harmed in my example But what if a splitting plane passes through an object? - Split the object; give half to each node: Ouch

53 53 Polygons: BSP Tree Construction Split along the plane containing any polygon Classify all polygons into positive or negative half-space of the plane  If a polygon intersects plane, split it into two Recurse down the negative half-space Recurse down the positive half-space

54 54 Binary Space Partition Trees (1979) BSP tree: organize all of space (hence partition) into a binary tree - Preprocess: overlay a binary tree on objects in the scene - Runtime: correctly traversing this tree enumerates objects from back to front - Idea: divide space recursively into half-spaces by choosing splitting planes  Splitting planes can be arbitrarily oriented

55 55 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order?

56 56 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8

57 57 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8->9

58 58 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8->9->7

59 59 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8->9->7->6

60 60 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8->9->7->6->5

61 61 BSP Trees: Objects 1 2 3 4 5 6 7 8 9 8 6 56 1 3 2 24 Correctly traversing this tree enumerates objects from back to front 79 -+ - + -+ ++ - + -- + - + - Traversal order: 8->9->7->6->5->3->4->2->1

62 62 Building a BSP Tree for Polygons Choose a splitting polygon Sort all other polygons as  Front  Behind  Crossing  On Add “front” polygons to front child, “behind” to back child Split “crossing” polygons with infinite plane Add “on” polygons to root/current node Recur

63 63 Building a BSP Tree 12 3 4 5 6 7

64 64 Building a BSP Tree 12 3 4 5 6 7 2,34,5,6,7 1 b

65 65 Building a BSP Tree 12 3 4 5 6 7 2,34,5,6,7 1 b How to divide 2,3,4,5,6,7?

66 66 3 Building a BSP Tree 12 3 4 6 7-2 1 7-2, 6,5-22,4,5-1,7-1 7-1 5-2 5-1 b bf

67 67 3 Building a BSP Tree 12 3 4 6 7-2 1 7-2, 6,5-22,4,5-1,7-1 7-1 5-2 5-1 b bf

68 68 b Building a BSP Tree 12 3 4 6 1 4,5-1 7-2, 6,5-2 2 3 7-1 7-2 7-1 5-2 5-1 b b f f

69 69 Building a BSP Tree 12 3 4 6 1 4 7-2, 6,5-2 5-1 3 7-1 7-2 7-1 5-2 5-1 2 b b b b f f

70 70 Building a BSP Tree 12 3 4 6 4 7-2, 6,5-2 5-1 3 7-1 1 7-2 7-1 5-2 5-1 2 b b b b f f

71 71 Building a BSP Tree 12 3 4 6 4 7-2, 6,5-2 2 5-1 3 7-1 1 7-2 7-1 5-2 5-1 b b b b f f

72 72 4 7-2 Building a BSP Tree 12 3 4 6 2 5-1 3 7-1 6,5-2 1 7-2 7-1 5-2 5-1 b b b b b f f

73 73 6 Building a BSP Tree 12 3 4 6 2 7-2 5-1 3 7-1 4 5-2 1 7-2 7-1 5-2 5-1 b b b b bf f f

74 74 5-2 2 7-2 Building a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f

75 75 5-2 2 7-2 Building a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f

76 76 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f How to traverse the tree?

77 77 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f How to traverse the tree? - draw “back” polygons - draw “on” polygons - draw “front” polygons

78 78 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order: b b b b bf f f

79 79 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order: 6 b b b b b f f

80 80 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order: 6->(5-2) b b b b b f f

81 81 4 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 6 1 7-2 7-1 5-2 5-1 Traversal order: 6->(5-2)->(7-2) b b b b b f f

82 82 3 f 4 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 7-1 6 1 7-2 7-1 5-2 5-1 Traversal order: 6->(5-2)->(7-2)->3 b b b b b f

83 83 3 f 4 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 7-1 6 1 7-2 7-1 5-2 5-1 Traversal order: 6->(5-2)->(7-2)->3->(5-1) b b b b b f

84 84 1 7-1 bf 3 f 4 f 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 6 7-2 7-1 5-2 5-1 Traversal order: 6->(5-2)->(7-2)->3->(5-1)->4->(7-1)->2->1 b b b b

85 85 Rendering with a BSP Tree Interpret the tree relative the position of the viewpoint How to traverse the tree  Draw “back” polygons  Draw “on” polygons  Draw “front” polygons 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b

86 86 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree?

87 87 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree? - No, we use the same tree if objects are static

88 88 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree? - No, we use the same tree if objects are static How can we traverse the tree?

89 89 Rendering with a BSP Tree If eye is in front of plane  Draw “back” polygons  Draw “on” polygons  Draw “front” polygons If eye is behind plane  Draw “front” polygons  Draw “on” polygons  Draw “back” polygons Else eye is on plane  Draw “front” polygons  Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4

90 90 Rendering with a BSP Tree If eye is in front of plane  Draw “back” polygons  Draw “on” polygons  Draw “front” polygons If eye is behind plane  Draw “front” polygons  Draw “on” polygons  Draw “back” polygons Else eye is on plane  Draw “front” polygons  Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4

91 91 Rendering with a BSP Tree If eye is in front of plane  Draw “back” polygons  Draw “on” polygons  Draw “front” polygons If eye is behind plane  Draw “front” polygons  Draw “on” polygons  Draw “back” polygons Else eye is on plane  Draw “front” polygons  Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4

92 92 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

93 93 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b

94 94 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

95 95 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

96 96 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

97 97 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1) 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

98 98 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

99 99 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1) 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + -

100 100 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1)->3 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b

101 101 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1)->3->(7-2)->(5-2)->6 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b

102 102 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b

103 103 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b + - 1

104 104 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b + - 1->?

105 105 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -

106 106 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -

107 107 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -

108 108 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->6 + -

109 109 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->6->?

110 110 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? 1->6->5-2 b b bf f f b b

111 111 5-2 2 7-2 1 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? 1->6->(5-2)->(7-2)->3->4->(5-1)->(7-1)->2 b b bf f f b b

112 112 Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer

113 113 Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer View frustum

114 114 Improved BSP Rendering Take advantage of view direction to cull away polygons behind viewer

115 115 Summary: BSP Trees Pros:  Simple, elegant scheme  No depth comparisons needed  Polygons split and ordered automatically  Works for moving cameras  Only writes to framebuffer (i.e., painters algorithm)

116 116 Summary: BSP Trees Cons:  Computationally intense preprocess stage restricts algorithm to static scenes  Worst-case time to construct tree: O(n 3 )  Splitting increases polygon count  Again, O(n 3 ) worst case  Redraws same pixel many times  Choosing splitting plane not an exact science  Not suitable for moving objects

117 117 Outline Backface Culling Painter’s algorithm BSP Scan line Z-buffer Ray casting Reading: section 16-1 to 16-11


Download ppt "1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai."

Similar presentations


Ads by Google