Title: CSCE 441: Computer Graphics Hidden Surface Removal
1CSCE 441 Computer Graphics Hidden Surface Removal
2Review 3D Geometry Pipeline
View space
World space
Object space
Normalized project space
Image space
2
33D Rendering Pipeline
Modeling transformation
lighting
Viewing transformation
Project transformation
Clipping
Scan conversion
Image
43D Rendering Pipeline
Modeling transformation
Transform into 3D world system
Illuminate according to lighting and reflectance
lighting
Transform into 3D camera coordinate system
Viewing transformation
Transform into 3D normalized project space
Project transformation
Clip primitives outside cameras view
Clipping
Draw pixels (includes texturing, hidden surface,
etc.)
Scan conversion
Image
53D Geometry Pipeline
View space
World space
Object space
Normalized project space
Image space
5
6Hidden Surfaces
7Hidden Surfaces
8Hidden Surfaces
9Polygon Mesh Representation
10Hidden 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
11Outline
- Backface Culling
- Painters algorithm
- BSP
- Scanline
- Z-buffer
- Ray casting
- Required reading section 16-1 to 16-11
12Backface Culling
Normalized project space
13Backface Culling
Normalized project space
view direction
14Backface Culling
Normalized project space
view direction
15Backface Culling
view direction
16Backface Culling
, draw polygon
view direction
17Backface Culling
, cull polygon
view direction
18Backface Culling
- Is this all we have to do?
19Backface Culling
- Is this all we have to do? No!
- Can still have 2 (or more) front faces that map
to the same screen pixel
20Backface 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?
21Backface 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!!!
22Painters Algorithm
- Basic idea similar to oil painting
- - draw background first
- - then most distant object
- - then nearer object
- - and so forth
23Painters Algorithm
- Sort polygons according to distance from viewer
- Draw from back (farthest) to front (nearest)
- - the entire object
- Near objects will overwrite farther ones
24Painters Example
Sort by depth Green rect Red circle Blue tri
25Painters Algorithm
- Does anyone see a problem with this?
26Painters 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 dont overlap for this
algorithm to work
27Painters 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 dont overlap for this
algorithm to work
28Painters Algorithm
- Sort all objects zmin and zmax
29Painters Algorithm
- Sort all objects zmin and zmax
- If an object is uninterrupted (its zmin and zmax
are adjacent in the sorted list), it is fine
30Painters Algorithm
- Sort all objects zmin and zmax
- If an object is uninterrupted (its zmin and zmax
are adjacent in the sorted list), it is fine - 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
31Painters 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
32Painters 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
33Painters 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
34Binary 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
6
4
5
7
1
3
2
35Binary 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
-
6
4
5
7
1
3
2
36Binary 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
-
6
4
5
7
If we want to draw 5 correctly - we need draw
6 and 7 first, - then draw 5, - then draw
1,2,3,4
1
3
2
37Binary 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
-
6
4
5
7
If we want to draw 5 correctly - we need draw
6 and 7 first, - then draw 5, - then draw
1,2,3,4
1
3
2
We need to do this for every polygon Can we do
this more efficiently?
38Binary 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
-
6
4
5
7
If we want to draw 5 correctly - we need draw
6 and 7 first, - then draw 5, - then draw
1,2,3,4
1
3
2
We need to do this for every polygon Can we do
this more efficiently? BSP tree
39Binary 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 painters algorithm - - Idea divide space recursively into half-spaces
by choosing splitting planes - Splitting planes can be arbitrarily oriented
40Binary 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
41BSP Trees Objects
9
8
7
6
5
4
1
2
3
42BSP Trees Objects
9
-
8
7
6
5
4
1
2
3
43BSP Trees Objects
Put front objects in the left branch
-
9
-
8
7
6
9
8
5
6
1
4
2
3
7
5
4
1
2
3
44BSP Trees Objects
Put front objects in the left branch
-
9
-
8
7
6
9
8
5
6
1
4
2
3
7
-
5
4
?
?
1
2
3
45BSP Trees Objects
Put front objects in the left branch
-
9
-
8
7
6
9
8
5
6
7
-
5
4
1
4
2
3
4
1
2
3
46BSP Trees Objects
Put front objects in the left branch
-
9
-
8
7
6
9
8
5
6
7
-
-
5
4
1
4
2
3
9
?
?
4
1
2
3
47BSP Trees Objects
Put front objects in the left branch
-
9
8
7
6
-
-
5
4
9
8
5
6
1
4
2
3
7
1
2
3
48BSP Trees Objects
Put front objects in the left branch
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
9
5
6
2
4
7
49BSP Trees Objects
Put front objects in the left branch
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
50BSP Trees Objects
Put front objects in the left branch
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
When to stop the recursion?
51Object Splitting
- No bunnies were harmed in my example
- But what if a splitting plane passes through an
object?
52Object 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
53Polygons 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
54Binary 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
55BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order?
56BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8
57BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8-gt9
58BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8-gt9-gt7
59BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8-gt9-gt7-gt6
60BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8-gt9-gt7-gt6-gt5
61BSP Trees Objects
Correctly traversing this tree enumerates objects
from back to front
-
9
8
7
6
-
-
5
4
1
-
-
-
1
2
3
3
8
5
6
6
2
-
-
2
4
7
9
Traversal order 8-gt9-gt7-gt6-gt5-gt3-gt4-gt2-gt1
62Building 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
63Building a BSP Tree
6
7
3
5
1
2
4
64Building a BSP Tree
6
7
3
5
1
2
4
1
b
2,34,5,6,7
65Building a BSP Tree
6
7
3
5
1
2
4
1
b
2,34,5,6,7
How to divide 2,3,4,5,6,7?
66Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-2, 6,5-2
2,4,5-1,7-1
67Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-2, 6,5-2
2,4,5-1,7-1
68Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2, 6,5-2
b
f
4,5-1
2
69Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-2, 6,5-2
7-1
b
f
4
2
b
5-1
70Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2, 6,5-2
b
f
4
2
b
5-1
71Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2, 6,5-2
b
f
4
2
b
5-1
72Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6,5-2
2
b
5-1
73Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
b
f
5-1
5-2
74Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
b
f
5-2
5-1
75Building a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
b
f
5-2
5-1
76Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
How to traverse the tree?
b
b
f
4
6
2
b
f
5-2
5-1
77Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
How to traverse the tree? - draw back
polygons - draw on polygons - draw front
polygons
b
b
f
4
6
2
b
f
5-2
5-1
78Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
b
f
Traversal order
5-2
5-1
79Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6
5-2
5-1
80Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6-gt(5-2)
5-2
5-1
81Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
b
f
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6-gt(5-2)-gt(7-2)
5-2
5-1
82Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6-gt(5-2)-gt(7-2)-gt3
5-2
5-1
83Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6-gt(5-2)-gt(7-2)-gt3-gt(5-1)
5-2
5-1
84Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 6-gt(5-2)-gt(7-2)-gt3-gt(5-1)-gt4-gt(7-
1)-gt2-gt1
5-2
5-1
85Rendering 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
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
5-2
5-1
86Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
b
f
7-1
7-2
Do we need to build a new tree?
b
b
f
4
6
2
b
f
5-2
5-1
87Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
b
f
7-1
7-2
Do we need to build a new tree? - No, we use
the same tree if objects are static
b
b
f
4
6
2
b
f
5-2
5-1
88Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
b
f
7-1
7-2
Do we need to build a new tree? - No, we use
the same tree if objects are static How can we
traverse the tree?
b
b
f
4
6
2
b
f
5-2
5-1
89Rendering 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
-
6
4
5
7
1
3
2
5
b
f
6,7
1,2,3,4
90Rendering 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
-
6
4
5
7
1
3
2
5
b
f
6,7
1,2,3,4
91Rendering 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
-
6
4
5
7
1
3
2
5
b
f
6,7
1,2,3,4
92Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
-
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order
5-2
5-1
93Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1
5-2
5-1
94Different View Points?
6
-
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1
5-2
5-1
95Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
-
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1
5-2
5-1
96Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
-
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2
5-2
5-1
97Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
-
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2-gt(7-1)
5-2
5-1
98Different View Points?
6
7-2
5-2
3
-
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2-gt(7-1)-gt4
5-2
5-1
99Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
-
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2-gt(7-1)-gt4-gt(5-1)
5-2
5-1
100Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2-gt(7-1)-gt4-gt(5-1)-gt3
5-2
5-1
101Different View Points?
6
7-2
5-2
3
7-1
5-1
1
2
4
1
b
3
f
b
7-1
7-2
b
b
f
4
6
2
f
b
Traversal order 1-gt2-gt(7-1)-gt4-gt(5-1)-gt3-gt(7-2)-gt
(5-2)-gt6
5-2
5-1
102Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
5-2
5-1
103Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
-
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1
5-2
5-1
104Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
-
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt?
5-2
5-1
105Rendering with a BSP Tree
6
-
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt?
5-2
5-1
106Rendering with a BSP Tree
-
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt?
5-2
5-1
107Rendering with a BSP Tree
-
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt?
5-2
5-1
108Rendering with a BSP Tree
-
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt6
5-2
5-1
109Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order?
Traversal order? 1-gt6-gt?
5-2
5-1
110Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order? 1-gt6-gt5-2
5-2
5-1
111Rendering with a BSP Tree
6
7-2
5-2
3
7-1
5-1
1
2
4
1
1
b
3
f
b
7-1
7-2
f
b
b
4
6
2
b
f
Traversal order? 1-gt6-gt(5-2)-gt(7-2)-gt3-gt4-gt(5-1)-gt
(7-1)-gt2
5-2
5-1
112Improved BSP Rendering
- Take advantage of view direction to cull away
polygons behind viewer
113Improved BSP Rendering
- Take advantage of view direction to cull away
polygons behind viewer
View frustum
114Improved BSP Rendering
- Take advantage of view direction to cull away
polygons behind viewer
115Summary 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)
116Summary BSP Trees
- Cons
- Computationally intense preprocess stage
restricts algorithm to static scenes - Worst-case time to construct tree O(n3)
- Splitting increases polygon count
- Again, O(n3) worst case
- Redraws same pixel many times
- Choosing splitting plane not an exact science
- Not suitable for moving objects
117Outline
- Backface Culling
- Painters algorithm
- BSP
- Scan line
- Z-buffer
- Ray casting
- Reading section 16-1 to 16-11