Transcript
Page 1: Spatial Data Structures and Acceleration Algorithms

Spatial Data Structures and AccelerationAlgorithms

� Real-time Rendering Performance Goals

� Spatial Structures

◦ Bounding Volume Hierarchies (BVH)

◦ Binary Space Partioning(BSP) Trees, Octrees

◦ Scene Graphs

� Culling Techniques

◦ Backface Culling

◦ View Frustum, Portal Culling

◦ Occlusion Culling

� Level of Detail Rendering

ITCS 4010/5010:Game Engine Design 1 Spatial Structures/ Acceleration Algorithms

Page 2: Spatial Data Structures and Acceleration Algorithms

Real-Time Rendering Performance Goals

� High frame rate (60-85 fps)

� High resolution (1600 by 1200)

� More realistic objects : no upper limit, Boeing 777 model - 500Mpolygons!

� Spatial data structures, culling techniques and LOD rendering worktowards these goals.

ITCS 4010/5010:Game Engine Design 2 Spatial Structures/ Acceleration Algorithms

Page 3: Spatial Data Structures and Acceleration Algorithms

Spatial Data Structures

� Data structures that organize geometry in 2D or 3D or higher

� The goal is faster processing

� Needed for most speed-up techniques

� Primary Applications: Games, movie production rendering tools per-mitting

◦ Faster real-time rendering, intersection testing, collision detec-tion, ray tracing, global illumination

ITCS 4010/5010:Game Engine Design 3 Spatial Structures/ Acceleration Algorithms

Page 4: Spatial Data Structures and Acceleration Algorithms

Spatial Data Structures

� Organize geometry into some type of a hierarchy

� In general, parents enclose the children’s (geometry) extents.

� Performance Advantage: Generally from O(n) to O(lg n)

� Construction is expensive, done as preprocess.

ITCS 4010/5010:Game Engine Design 4 Spatial Structures/ Acceleration Algorithms

Page 5: Spatial Data Structures and Acceleration Algorithms

Spatial Data Structures: Why?

� Example: Want to pick the object user clicks on (shoot a monster,move towards an object)

� A hierarchcy can be used to improve performance of spatialqueries:

◦ Test the root first

◦ Descend recursively as needed

◦ Terminate traversal when possible

ITCS 4010/5010:Game Engine Design 5 Spatial Structures/ Acceleration Algorithms

Page 6: Spatial Data Structures and Acceleration Algorithms

Bounding Volume Hierarchies (BVH)

� Most common bounding volumes (BVs): Sphere, Boxes (Axis-aligned (AABB) and Oriented OBB)

� The BV does not contibute to the rendered image – rather, enclosesan object

� Data Structure is a k-ary tree

◦ Leaf nodes have geometry

◦ Internal nodes have at most k children

◦ Internal nodes BV encloses all geometry in its subtree

ITCS 4010/5010:Game Engine Design 6 Spatial Structures/ Acceleration Algorithms

Page 7: Spatial Data Structures and Acceleration Algorithms

Tree Structures

� Height of tree, h: longest path from root to leaf

� Balanced Tree: All leaves at height h or h + 1

� Height of balanced tree with n nodes: lgk n

� k = 2 (binary tree) is most common, also k = 4, 8, quadtrees andoctrees.

ITCS 4010/5010:Game Engine Design 7 Spatial Structures/ Acceleration Algorithms

Page 8: Spatial Data Structures and Acceleration Algorithms

Building a BVH

� Example: Axis-aligned BB, top-down approach

� Split along longest axis

ITCS 4010/5010:Game Engine Design 8 Spatial Structures/ Acceleration Algorithms

Page 9: Spatial Data Structures and Acceleration Algorithms

Building a BVH:Termination Criteria

� Bounding Volume is empty

� When only one primitive (e.g. triangle) is inside BV

� Less than n (user defined) primitives is inside BV

� When recursion level l has been reached

ITCS 4010/5010:Game Engine Design 9 Spatial Structures/ Acceleration Algorithms

Page 10: Spatial Data Structures and Acceleration Algorithms

Binary Space Partitioning Trees

� Pioneered by Sutherland, advanced by Naylor (1978)

� Idea: Recursive subdivision of space:

◦ Divide space with a planes

◦ Sort geometry into the space it belongs

◦ Resulting ordering is view independent

◦ The earliest games to use BSP trees : Doom (early 90s)

◦ Applications: visible surface determination, ray tracing, collisiondetection

◦ Two types: Axis-aligned, Polygon alighned

ITCS 4010/5010:Game Engine Design 10 Spatial Structures/ Acceleration Algorithms

Page 11: Spatial Data Structures and Acceleration Algorithms

Axis-Aligned BSP Tree

� Partitioning planes are aligned with the principal axes, X, Y, Z

ITCS 4010/5010:Game Engine Design 11 Spatial Structures/ Acceleration Algorithms

Page 12: Spatial Data Structures and Acceleration Algorithms

Axis-Alighned BSP Tree

� Each internal node holds a partitioning plane

� Leaf nodes hold geometry

� Different from Bounding Volume Hierarchy:

◦ Encloses entire space and provides sorting (approximate)

◦ The BV hierarchy can be constructed in any way (no sort), useany BV

ITCS 4010/5010:Game Engine Design 12 Spatial Structures/ Acceleration Algorithms

Page 13: Spatial Data Structures and Acceleration Algorithms

Using an Axis-Alighned BSP Tree

� Test the planes against view point, starting from the root.

� Continue on the ”far” side to sort front to back

� Rough sorting order.

ITCS 4010/5010:Game Engine Design 13 Spatial Structures/ Acceleration Algorithms

Page 14: Spatial Data Structures and Acceleration Algorithms

Polygon (Plane)-Aligned BSP Tree

� Partitioners are aligned with polygon faces

� Provides an exact sorting order

� Ordering can be generated in near real-time for any viewing position;no z-buffer required

ITCS 4010/5010:Game Engine Design 14 Spatial Structures/ Acceleration Algorithms

Page 15: Spatial Data Structures and Acceleration Algorithms

Polygon (Plane)-Aligned BSP Tree

� Continuous Space Representation.

� Represents geometry with hyperplanes.

� Convex decomposition of space by recursive subdivision.

� Internal nodes contain discontinuities(planes), leaf nodes representconvex regions.

a

outb

out

in

in

c

d

out

a

d

b

c

in

in

Viewer

ITCS 4010/5010:Game Engine Design 15 Spatial Structures/ Acceleration Algorithms

Page 16: Spatial Data Structures and Acceleration Algorithms

Polygon Aligned BSP Tree: Tree Construction

a

d

b

c

in

in

ITCS 4010/5010:Game Engine Design 16 Spatial Structures/ Acceleration Algorithms

Page 17: Spatial Data Structures and Acceleration Algorithms

a

d

b

c

in

in

a

out

ITCS 4010/5010:Game Engine Design 17 Spatial Structures/ Acceleration Algorithms

Page 18: Spatial Data Structures and Acceleration Algorithms

a

d

b

c

in

in

a

outb

out

ITCS 4010/5010:Game Engine Design 18 Spatial Structures/ Acceleration Algorithms

Page 19: Spatial Data Structures and Acceleration Algorithms

a

d

b

c

in

in

a

outb

out

in

c

ITCS 4010/5010:Game Engine Design 19 Spatial Structures/ Acceleration Algorithms

Page 20: Spatial Data Structures and Acceleration Algorithms

a

d

b

c

in

in

a

outb

out

in

in

c

d

out

ITCS 4010/5010:Game Engine Design 20 Spatial Structures/ Acceleration Algorithms

Page 21: Spatial Data Structures and Acceleration Algorithms

Determining Visible Surface using the BSPTree

a

outb

out

in

in

c

d

out

a

d

b

c

in

in

Viewer

� Paint faces back to front , as faces in front cannot obscure those thatare behind.

� Classification is performed recursively, resulting in generating a pri-ority order of faces, for a given viewer position.

� The BSP tree is independent of viewer location, so long as the ob-jects

ITCS 4010/5010:Game Engine Design 21 Spatial Structures/ Acceleration Algorithms

Page 22: Spatial Data Structures and Acceleration Algorithms

Octrees

� Similar to axis-aligned BSP trees, but subdivision is done simultane-ously along all 3 dimensions

� 2D variant is the quadtree, shown above:

� In 3D each square (or rectangle) becomes a box, and 8 children

ITCS 4010/5010:Game Engine Design 22 Spatial Structures/ Acceleration Algorithms

Page 23: Spatial Data Structures and Acceleration Algorithms

Octrees

� Expensive to rebuild (as are BSPs)

� Loose octrees: a relaxation to avoid problems

� Octrees can be used to

◦ Speed up ray tracing

◦ Faster picking

◦ Culling techniques

◦ Are not used that often in real-time contexts

ITCS 4010/5010:Game Engine Design 23 Spatial Structures/ Acceleration Algorithms

Page 24: Spatial Data Structures and Acceleration Algorithms

Scene Graphs

� Bounding Volume Hierarchies have 2 advantages, (1) Simple to un-derstand, (2) Simple to implement

� BVHs store only geometry

� Scene Graph is an extended BVH with lights, textures, transforms,and more.

ITCS 4010/5010:Game Engine Design 24 Spatial Structures/ Acceleration Algorithms

Page 25: Spatial Data Structures and Acceleration Algorithms

Scene Graphs

� Scene Graphs add structure to environments

� Instancing (hierarchical modeling) makes this structure graph (ratherthan a tree)

� Originally introduced in SGI Inventor, followed by VRML, Java3D,etc.

� Scene Graph Traversal: top to bottom, left to right

ITCS 4010/5010:Game Engine Design 25 Spatial Structures/ Acceleration Algorithms

Page 26: Spatial Data Structures and Acceleration Algorithms

ITCS 4010/5010:Game Engine Design 26 Spatial Structures/ Acceleration Algorithms


Recommended