Docsity

Spatial Data Structures for Ray Tracing: Lecture Notes, Exercises of Data Structures and Algorithms

Toggle sidebar
bg1
1
1
Jernej Barbic
University of Southern California
CSCI 420 Computer Graphics
Lecture 17
Spatial Data Structures
Hierarchical Bounding Volumes
Regular Grids
Octrees
BSP Trees
[Ch. 10.12]
2
Ray Tracing Acceleration
• Faster intersections
– Faster ray-object intersections
• Object bounding volume
• Efficient intersectors
– Fewer ray-object intersections
• Hierarchical bounding volumes (boxes, spheres)
• Spatial data structures
• Directional techniques
• Fewer rays
– Adaptive tree-depth control
– Stochastic sampling
• Generalized rays (beams, cones)
3
Spatial Data Structures
• Data structures to store geometric information
• Sample applications
– Collision detection
– Location queries
– Chemical simulations
– Rendering
• Spatial data structures for ray tracing
– Object-centric data structures (bounding volumes)
– Space subdivision (grids, octrees, BSP trees)
– Speed-up of 10x, 100x, or more
4
Bounding Volumes
• Wrap complex objects in simple ones
• Does ray intersect bounding box?
– No: does not intersect enclosed objects
– Yes: calculate intersection with enclosed objects
• Common types:
Axis-aligned
Bounding
Box (AABB)
Oriented
Bounding
Box (OBB)
Sphere Convex Hull
6-dop
5
Selection of Bounding Volumes
• Effectiveness depends on:
– Probability that ray hits bounding volume, but not
enclosed objects (tight fit is better)
– Expense to calculate intersections with bounding
volume and enclosed objects
• Amortize calculation of bounding volumes
• Use heuristics
good
bad
6
Hierarchical Bounding Volumes
• With simple bounding volumes, ray casting still
requires O(n) intersection tests
• Idea: use tree data structure
– Larger bounding volumes contain smaller ones etc.
– Sometimes naturally available (e.g. human figure)
– Sometimes difficult to compute
• Often reduces complexity to O(log(n))
pf3
pf4
pf5

Partial preview of the text

Download Spatial Data Structures for Ray Tracing: Lecture Notes and more Exercises Data Structures and Algorithms in PDF only on Docsity!

1 Jernej Barbic University of Southern California CSCI 420 Computer Graphics Lecture 17

Spatial Data Structures

Hierarchical Bounding Volumes Regular Grids Octrees BSP Trees [Ch. 10.12] 2

Ray Tracing Acceleration

  • Faster intersections
    • Faster ray-object intersections
      • Object bounding volume
      • Efficient intersectors
    • Fewer ray-object intersections
      • Hierarchical bounding volumes (boxes, spheres)
      • Spatial data structures
      • Directional techniques
  • Fewer rays
    • Adaptive tree-depth control
    • Stochastic sampling
  • Generalized rays (beams, cones) 3

Spatial Data Structures

  • Data structures to store geometric information
  • Sample applications
    • Collision detection
    • Location queries
    • Chemical simulations
    • Rendering
  • Spatial data structures for ray tracing
    • Object-centric data structures (bounding volumes)
    • Space subdivision (grids, octrees, BSP trees)
    • Speed-up of 10x, 100x, or more 4

Bounding Volumes

  • Wrap complex objects in simple ones
  • Does ray intersect bounding box?
    • No: does not intersect enclosed objects
    • Yes: calculate intersection with enclosed objects
  • Common types: Axis-aligned Bounding Box (AABB) Oriented Bounding Box (OBB) Sphere 6-dop Convex Hull 5

Selection of Bounding Volumes

  • Effectiveness depends on:
    • Probability that ray hits bounding volume, but not enclosed objects (tight fit is better)
    • Expense to calculate intersections with bounding volume and enclosed objects
  • Amortize calculation of bounding volumes
  • Use heuristics good bad 6

Hierarchical Bounding Volumes

  • With simple bounding volumes, ray casting still requires O(n) intersection tests
  • Idea: use tree data structure
    • Larger bounding volumes contain smaller ones etc.
    • Sometimes naturally available (e.g. human figure)
    • Sometimes difficult to compute
  • Often reduces complexity to O(log(n))

7

Ray Intersection Algorithm

  • Recursively descend tree
  • If ray misses bounding volume, no intersection
  • If ray intersects bounding volume, recurse with enclosed volumes and objects
  • Maintain near and far bounds to prune further
  • Overall effectiveness depends on model and constructed hierarchy 8

Spatial Subdivision

  • Bounding volumes enclose objects, recursively
  • Alternatively, divide space (as opposed to objects)
  • For each segment of space, keep a list of intersecting surfaces or objects
  • Basic techniques: Uniform Spatial Sub Quadtree/Octree^ kd-tree^ BSP-tree 9

Grids

  • 3D array of cells (voxels) that tile space
  • Each cell points to all intersecting surfaces
  • Intersection algorithm steps from cell to cell 10

Caching Intersection points

  • Objects can span multiple cells
  • For A need to test intersection only once
  • For B need to cache intersection and check next cell for any closer intersection with other objects
  • If not, C could be missed (yellow ray) A B C 11

Assessment of Grids

  • Poor choice when world is non-homogeneous
  • Grid resolution:
    • Too small: too many surfaces per cell
    • Too large: too many empty cells to traverse
    • Can use algorithms like Bresenham’s for efficient traversal
  • Non-uniform spatial subdivision more flexible
    • Can adjust to objects that are present 12

Outline

  • Hierarchical Bounding Volumes
  • Regular Grids
  • Octrees
  • BSP Trees

19

Building a BSP Tree

  • Use hidden surface removal as intuition
  • Using line 1 or line 2 as root is easy Line 3^ Line 2 Line 1 Viewpoint 1 1 2 3 B A C D a BSP tree using 2 as root A B D C 3 2 of space it implies^ the subdivision 20

Splitting of surfaces

  • Using line 3 as root requires splitting Line 2a Line 3 Line 1 Viewpoint 1 2b 2a Line 2b 3 21

Building a Good Tree

  • Naive partitioning of n polygons yields O( n^3 ) polygons (in 3D)
  • Algorithms with O(n^2 ) increase exist
    • Try all, use polygon with fewest splits
    • Do not need to split exactly along polygon planes
  • Should balance tree
    • More splits allow easier balancing
    • Rebalancing? 22

Painter’s Algorithm with BSP Trees

  • Building the tree
    • May need to split some polygons
    • Slow, but done only once
  • Traverse back-to-front or front-to-back
    • Order is viewer-direction dependent
    • What is front and what is back of each line changes
    • Determine order on the fly 23

Details of Painter’s Algorithm

  • Each face has form Ax + By + Cz + D
  • Plug in coordinates and determine
    • Positive: front side
    • Zero: on plane
    • Negative: back side
  • Back-to-front: inorder traversal, farther child first
  • Front-to-back: inorder traversal, near child first
  • Do backface culling with same sign test
  • Clip against visible portion of space (portals) 24

Clipping With Spatial Data Structures

  • Accelerate clipping
    • Goal: accept or reject whole sets of objects
    • Can use an spatial data structures
  • Scene should be mostly fixed
    • Terrain fly-through
    • Gaming Hierarchical bounding volumes Octrees viewing frustrum

25

Data Structure Demos

  • BSP Tree construction http://symbolcraft.com/graphics/bsp/index.html
  • KD Tree construction http://donar.umiacs.umd.edu/quadtree/points/kdtree.html 26

Real-Time and Interactive Ray Tracing

  • Interactive ray tracing via space subdivision http://www.cs.utah.edu/~reinhard/egwr/
  • State of the art in interactive ray tracing http:// www.cs.utah.edu/~shirley/irt/ 27

Summary

  • Hierarchical Bounding Volumes
  • Regular Grids
  • Octrees
  • BSP Trees