spatial data structures jason goffeney, 4/26/2006 from real time rendering

32
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Upload: arline-george

Post on 26-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Spatial Data Structures

Jason Goffeney, 4/26/2006

from

Real Time Rendering

Page 2: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Material Recipes

• As previously mentioned there are several different components used in the creation of a material for an object– Ambient– Diffuse– Specular– Shininess– Emissive

Page 3: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Material RecipesUse Shininess value times 128

Page 4: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Spatial Data Structures

• One of the important topics for performing real time graphics applications are data structures for efficient queries to do:

– Graphics Culling

– Intersection Testing

Page 5: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Spatial Data Structure

• Spatial Data Structures organize geometry in some n - dimensional space (generally 2 or 3 but can work in higher dimensional space).

• The list is the simplest data structure and fairly slow for large data sets but reasonable for smaller ones.

Page 6: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Spatial Data Structures

• Most spatial data structures are hierarchical as a tree like structure nested and recursive.

• Searching a list is O(n) while searching a tree is O(log n).

• Usually constructing a spatial data structure is fairly slow and is done as preprocessing.

Page 7: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Spatial Data Structures

• There are several types of spatial data structures:– Bounding Volume Hierarchies– BSP Trees– Octrees– Scene Graphs

Page 8: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

• The most common bounding volume is the bounding box.

• Other common types are sphere and cylinders.

• The idea is that the bounding volume is simpler than the more complex shapes it contains.

Page 9: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

• A Bounding Volume Hierarchy (BVH) is the most common kind of spatial data structure for rendering real-time 3-d scenes.

• Each object in a scene is bound by a volume and then groups of objects are bounded and eventually the entire scene is bounded.

Page 10: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

Simple Scene of Objects Tree of Objects

Root

Page 11: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

• For a tree where each node has k children then the height of the tree is logk n where n is the number of nodes in the tree.

• A binary tree is the simplest choice but a higher number of children per node can give slightly better results.

Page 12: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

• In the example of ray casting you search each subtree recursively.

If a child node is not hitthen skip the rest of itssubtree

If the ray hits the outer volume checkeach the children

Page 13: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Bounding Volume Hierarchies

• Speed up comes from simple intersection tests with bounding volumes and also from culling subtrees

• If objects move around then first check is it still fits in its current bounding volume. Otherwise remove it and change the parent bounding volume and drop the node in the root of the tree and reinsert it.

Page 14: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

• These trees are created by using a plane to split space into two pieces and sorting the geometry into each side.

• There are two flavors of BSP trees.– Axis-Aligned– Polygon-Aligned

Page 15: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

• Axis-Aligned BSP Tree– The whole scene is enclosed in an axis-

aligned bounding box (AABB).– The idea is to subdivide that box into smaller

and smaller boxes.– For each split an axis is chosen and a plane

perpendicular to that axis is generated that divides the space into two boxes

Page 16: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

0 0

0

1a

1b

1a

1b

2

Page 17: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

0

1a

1b

2

0

1a 1b

2

Page 18: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

• Axis-Aligned BSP Tree– Space is usually split until some criteria has

been reached (height of tree)– One of the strategies of splitting is to rotate

through the axes each turn. – One of the benefits of the BSP tree is that it

provides a rough front to back sorting based on the position of the viewer.

Page 19: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

0

1a

1b

2

• Traverse the tree by first moving down the subtreesdefined by the side of the plane the user is one.

• For plane 0 is the viewer’s x position > x0?

- Yes, so take right subtree.

• For plane 1b is viewer’s y position > y1b? - No, so take the left subtree.

• Test against objects in that subtree and go back toparent if no collision.

x0

y1ay1b

x2

Page 20: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

• Polygon-Aligned BSP Trees– In this version a polygon from the scene is

chosen and the plane it lies in becomes the splitting plane.

– The other polygons in the scene are divided by the plane and any polygons the plane intersects are cut by the plane

Page 21: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

A AB

C

AB

CF

G

D

E

A

B C

D E F G

Page 22: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

• Polygon-Aligned BSP Trees– Constructing this kind of tree is very

expensive and is general done and then saved in a file.

– Traversing this tree based on the position of the camera will provide a strict back to front (or front to back) sorting of the polygons

Page 23: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Binary Space Partitioning Trees

AB

CF

G

D

E

A

B C

D E F G

• Determine which side of the plane thecamera lies on by a point/plane comparison

• The polygon set on the far side of the plane isis beyond the near side set

• From the far side set again do the comparison and determine the far side of its splitting plane

• Back to front order is for this example is:F - G- A - D - B- E

• This does not tell which polygon is closest butwhich polygon occludes (hides) another polygon.

Page 24: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Octrees

• Similar to an AA-BSP tree a box is split simultaneously along all 3 axes and the split point is in the center of the box creating 8 new boxes.

• Enclose the entire space in an AABB and split until you meet a stopping criteria.

• The 2D version of the octree is the quadtree.

Page 25: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Octrees

Objects that cross boundaries are either:• Split• Stored in multiple nodes• Stored in the largest box that contains it

Page 26: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graphs

• BVHs, BSP tree and Octrees all use some sort of tree to partition space and store geometry.

• Scene graphs are higher level structures that that are augmented with textures, transforms, levels-of-detail, material properties, light sources, etc.

Page 27: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graphs

• Every graphics application has some sort of scene graph even if it is a root node with a set of children to display.

• A node in a scene graph often has a bounding volume while leaves store geometry.

• A leaf may contain an entire spatial data structure (such as a BSP Tree) to encode the geometry.

Page 28: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graphs

• Transformations can be placed in any internal node and effects the entire subtrees of that node.

Draw the star Save the current matrix

Apply a rotation Draw Planet One Save the current matrix

Apply a second rotation Draw Moon ADraw Moon B

Reset the matrix we saved Draw Planet two Save the current matrix

Apply a rotation Draw Moon C Draw Moon D

Reset the matrix we saved Reset the matrix we saved

Page 29: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graphs

• A single leaf node can have multiple parents.

Car Chassis

Transform Transform Transform Transform

Wheel

Page 30: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graph

• Maintenance– The most intuitive method is to alter a scene

graph through a GUI (Maya, 3DMax)– Otherwise design a scripting “language” to

insert and delete nodes from the graph

Page 31: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

Scene Graphs

• Open Source Scene Graphs:– Open Scene Graph– Open SG

• These are two semi-competing scene graphs which have somewhat specialized.

Page 32: Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering

References

• Tomas Akenine-Moller and Eric Haines. Real Time Rendering. 2nd Edition. A. K. Peters. 2002.

• http://www.gamedev.net/reference/programming/features/scenegraph/