Title: Spatial Data Structures and Culling Techniques
1Spatial Data Structures and Culling Techniques
CIS 781 winter 2005
Han-Wei Shen
2Spatial Data Structures
- Used to organize geometry in n-dimensional space
(2 and 3D are of this courses interest) - For accelerating queries culling, ray tracing
intersection tests, collision detection - They are mostly hierarchy by nature
- Topics
- Bounding Volume Hierarchies (BVH)
- Binary Space Partitioning Trees (BSP trees)
- Octrees
3Bounding Volume Hierarchies
- Bounding Volume (BV) a volume that encloses a
set of objects - The idea is to use a much similar geometric shape
for quick tests (frustum culling for example) - Easy to compute, as tight as possible
-
- AABB, Sphere easy to compute, but poor fit
(read section 13.3)
4Bounding Volume Hierarchies
- Each node has a bounding volume that encloses the
geometry in the entire subtree - The actual geometry is contained in the leaf node
- Three types of methods bottom-up, insertion, and
top-down
root
leaves
(read section 14.3.1)
5Binary Space Partitioning (BSP) Trees
- Main purpose depth sorting
- Consisting of a dividing plane, and a BSP tree on
each side of the dividing plane (note the
recursive definition) - The back to front traversal order can be decided
right away according to where the eye is
back to front A-gtP-gtB
P
BSP A
BSP B
back to front A-gtP-gtB
6BSP Trees (contd)
- Two possible implementations
Axis-Aligned BSP
Polygon-Aligned BSP
Intersecting?
7Axis-Aligned BSP Trees
- Starting with an AABB
- Recursively subdivide into small boxes
- One possible strategy cycle through the axes
(also called k-d trees)
D
E
B
2
1b
1a
A
C
0
Q objects intersect the boundaries?
8Polygon-Aligned BSP Trees
- The original BSP idea
- Choose one divider at a time any polygon
intersect with the plane has to be split - Done recursively until all polygons are in the
BSP trees - The back to front traversal can be done exact
- The dividers need to be chosen carefully so that
a balanced BSP tree is created
F
B
C
A
D
E
result of split
9Octrees
- Similar to Axis-Aligned BSP trees
- Each node has eight children
- A parent has 8 (2x2x2) children
- Subdivide the space until the
- number of primitives within
- each leaf node is less than a
- threshold
- Objects are stored in the leaf
- nodes
10Visibility Culling
- Back face culling
- View-frustrum culling
- Detail culling
- Occlusion culling
11View-Frustum Culling
- Done in the application stage
- Remove objects that are outside the viewing
frustum - Can use BVH, BSP, Octrees
12View-Frustum Culling
- Often done hierarchically to save time
In-order, top-down traversal and test
13Detail Culling
- A technique that sacrifices quality for speed
- Base on the size of projected BV if it is too
small, discard it. - Also often done
- hierarchically
Always helps to create a hierarchical structure,
or scene graph.
14Occlusion Culling
- Discard objects that are occluded
- Z-buffer is not the smartest algorithm in the
world (particularly for high depth- - complexity scenes)
- We want to avoid processing invisible objects
15Occlusion Culling (2)
- G input graphics data
- Or occlusion hint
- Things needed
- Algorithms for isOccluded()
- Or?
- Fast update Or
OcclusionCulling (G) Or empty For each object
g in G if (isOccluded(g, Or)) skip g
else render (g) update (Or) end
End
16Hierarchical Visibility
- One example of occlusion culling techniques
- Object-space octree
- Primitives in an octree node are hidden if the
octree node (cube) is hidden - A octree cube is hidden if its 6 faces are hidden
polygons - Hierarchical visibility test
17Hierarchical Visibility
- From the root of octree
- View-frustum culling
- Scan conversion each of the 6 faces and perform
z-buffering - If all 6 faces are hidden, discard the entire
node and sub-branches - Otherwise, render the primitives inside and
traverse the front-to-back children recursively -
A conservative algorithm why?
18Hierarchical Visibility
- Scan conversion the octree faces can be expensive
cover a large number of pixels (overhead) - How can we reduce the overhead?
- Goal quickly conclude that a large polygon is
hidden - Method use hierarchical z-buffer !
19Hierarchical Z-buffer
- An image-space approach
- Create a Z-pyramid
1 value
¼ resolutin
½ resolution
Original Z-buffer
20Hierarchical Z-buffer (2)
?
21Hierarchical Z-buffer (3)
Isoccluded(g, Zp) near z nearZ(BV(g))
if (near Z behind Zp_root.z) return true
else return ( Isoccluded(g,Zp.c0)
Isoccluded(g,Zp.c1)
Isoccluded(g,Zp.c2)
Isoccluded(g,Zp.c3) ) end
22Hierarchical Z-buffer (4)
update
Cull_or_Render (OctreeNode N) if (isOccluded
(N, Zp) then return for each primitive p in
N render and update Zp end for
each child node C of N in front-to-back order
Cull_or_Render( C ) end
23Portal Culling
- The following slides are taken from Prof. David
Luebkes class web site at U. of Virginia
24Portal Culling
- Goal walk through architectural models
(buildings, cities, catacombs) - These divide naturally into cells
- Rooms, alcoves, corridors
- Transparent portals connect cells
- Doorways, entrances, windows
- Notice cells only see other cells through portals
25Cells Portals
26Cells Portals
- Idea
- Create an adjacency graph of cells
- Starting with cell containing eyepoint, traverse
graph, rendering visible cells - A cell is only visible if it can be seen through
a sequence of portals - So cell visibility reduces to testing portal
sequences for a line of sight
27Cells Portals
A
D
E
F
C
B
G
H
E
A
B
C
D
F
G
H
28Cells Portals
A
D
E
F
C
B
G
H
E
A
B
C
D
F
G
H
29Cells Portals
A
D
E
F
C
B
G
H
E
A
B
C
D
F
G
H
30Cells Portals
A
D
E
F
C
B
G
H
E
A
B
C
D
F
G
H
31Cells Portals
A
D
E
F
C
B
G
H
E
A
B
C
D
F
G
H
32Cells Portals
A
D
E
?
F
C
B
G
H
E
A
B
C
D
F
G
?
H
33Cells Portals
A
D
E
X
F
C
B
G
H
E
A
B
C
D
F
G
X
H
34Cells Portals
- View-independent solution find all cells a
particular cell could possibly see - C can only see A, D, E, and H
A
D
E
H
35Cells Portals
- View-independent solution find all cells a
particular cell could possibly see - H will never see F
A
D
E
C
B
G
36Cells and Portals
- Question How can we detect the cells that are
visible from a given viewpoint? - Idea (textbook pp 366)
- Set the view box (P) as the entire screen
- Compare the portal (B) to the neighbor cell (C)
against the current view box P - If B outside P the neighbor cell C cannot be
seen - Otherwise the neighbor cell C is visible
- New view box P intersection of P and the portal
B - For each neighbor of C, depth first traverse the
adjacency graph of C and recurse
37Example