Computer Graphics. - Spatial Index Structures - Philipp Slusallek

Similar documents
Computer Graphics. - Ray-Tracing II - Hendrik Lensch. Computer Graphics WS07/08 Ray Tracing II

Ray Tracing Performance

SPATIAL DATA STRUCTURES. Jon McCaffrey CIS 565

Spatial Data Structures

Spatial Data Structures

Acceleration Data Structures

Parallel Physically Based Path-tracing and Shading Part 3 of 2. CIS565 Fall 2012 University of Pennsylvania by Yining Karl Li

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Acceleration. Welcome!

Ray Tracing. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Spatial Data Structures

Spatial Data Structures

Accelerating Ray-Tracing

Accelerated Raytracing

Spatial Data Structures

Acceleration Structures. CS 6965 Fall 2011

Ray Tracing Acceleration Data Structures

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

Announcements. Written Assignment2 is out, due March 8 Graded Programming Assignment2 next Tuesday

Ray Tracing Acceleration. CS 4620 Lecture 20

Intersection Acceleration

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Topics. Ray Tracing II. Intersecting transformed objects. Transforming objects

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

Ray Tracing with Spatial Hierarchies. Jeff Mahovsky & Brian Wyvill CSC 305

Ray Tracing: Intersection

CPSC / Sonny Chan - University of Calgary. Collision Detection II

Chapter 11 Global Illumination. Part 1 Ray Tracing. Reading: Angel s Interactive Computer Graphics (6 th ed.) Sections 11.1, 11.2, 11.

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Topics. Ray Tracing II. Transforming objects. Intersecting transformed objects

EDAN30 Photorealistic Computer Graphics. Seminar 2, Bounding Volume Hierarchy. Magnus Andersson, PhD student

Spatial Data Structures. Steve Rotenberg CSE168: Rendering Algorithms UCSD, Spring 2017

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Scene Management. Video Game Technologies 11498: MSc in Computer Science and Engineering 11156: MSc in Game Design and Development

Ray Intersection Acceleration

Anti-aliased and accelerated ray tracing. University of Texas at Austin CS384G - Computer Graphics

Recall: Inside Triangle Test

Acceleration Data Structures. Michael Doggett Department of Computer Science Lund university

Ray Tracing III. Wen-Chieh (Steve) Lin National Chiao-Tung University

Accelerating Ray Tracing

Ray Tracing Acceleration. CS 4620 Lecture 22

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

Computer Graphics. Bing-Yu Chen National Taiwan University

Acceleration. Digital Image Synthesis Yung-Yu Chuang 10/11/2007. with slides by Mario Costa Sousa, Gordon Stoll and Pat Hanrahan

Acceleration Data Structures for Ray Tracing

Using Bounding Volume Hierarchies Efficient Collision Detection for Several Hundreds of Objects

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

improving raytracing speed

Ray Genealogy. Raytracing: Performance. Bounding Volumes. Bounding Volume. Acceleration Classification. Acceleration Classification

Lecture 2 - Acceleration Structures

COMP 175: Computer Graphics April 11, 2018

Ray Intersection Acceleration

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Logistics. CS 586/480 Computer Graphics II. Questions from Last Week? Slide Credits

Advanced Ray Tracing

Questions from Last Week? Extra rays needed for these effects. Shadows Motivation

CS 431/636 Advanced Rendering Techniques

Speeding up your game

Ray-tracing Acceleration. Acceleration Data Structures for Ray Tracing. Shadows. Shadows & Light Sources. Antialiasing Supersampling.

Spatial Data Structures and Acceleration Algorithms

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

In the previous presentation, Erik Sintorn presented methods for practically constructing a DAG structure from a voxel data set.

The Traditional Graphics Pipeline

Homework 1: Implicit Surfaces, Collision Detection, & Volumetric Data Structures. Loop Subdivision. Loop Subdivision. Questions/Comments?

Spatial Data Structures and Acceleration Algorithms

B-KD Trees for Hardware Accelerated Ray Tracing of Dynamic Scenes

Reading Ray Intersection Chapter 2: Geometry and Transformations Acceleration Covers basic math and PBRT implementation: read on your own

Collision and Proximity Queries

CS 563 Advanced Topics in Computer Graphics Culling and Acceleration Techniques Part 1 by Mark Vessella

Specialized Acceleration Structures for Ray-Tracing. Warren Hunt

Spatial Data Structures and Speed-Up Techniques. Ulf Assarsson Department of Computer Science and Engineering Chalmers University of Technology

l Without collision detection (CD), it is practically impossible to construct e.g., games, movie production tools (e.g., Avatar)

The Traditional Graphics Pipeline

Solid Modeling. Thomas Funkhouser Princeton University C0S 426, Fall Represent solid interiors of objects

Bounding Volume Hierarchies. CS 6965 Fall 2011

VIII. Visibility algorithms (II)

Today. Acceleration Data Structures for Ray Tracing. Cool results from Assignment 2. Last Week: Questions? Schedule

The Traditional Graphics Pipeline

Improving Memory Space Efficiency of Kd-tree for Real-time Ray Tracing Byeongjun Choi, Byungjoon Chang, Insung Ihm

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

Determination (Penentuan Permukaan Tampak)

Lecture 11 - GPU Ray Tracing (1)

Comparison of hierarchies for occlusion culling based on occlusion queries

Real-Time Rendering (Echtzeitgraphik) Dr. Michael Wimmer

Collision Detection. These slides are mainly from Ming Lin s course notes at UNC Chapel Hill

Lecture 4 - Real-time Ray Tracing

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

SAH guided spatial split partitioning for fast BVH construction. Per Ganestam and Michael Doggett Lund University

Advanced 3D-Data Structures

Dynamic Bounding Volume Hierarchies. Erin Catto, Blizzard Entertainment

Computer Graphics Ray Casting. Matthias Teschner

Real Time Ray Tracing

Lecture 11: Ray tracing (cont.)

Lecture 17: Solid Modeling.... a cubit on the one side, and a cubit on the other side Exodus 26:13

Hello, Thanks for the introduction

EFFICIENT BVH CONSTRUCTION AGGLOMERATIVE CLUSTERING VIA APPROXIMATE. Yan Gu, Yong He, Kayvon Fatahalian, Guy Blelloch Carnegie Mellon University

Wed, October 12, 2011

Subdivision Of Triangular Terrain Mesh Breckon, Chenney, Hobbs, Hoppe, Watts

Point Cloud Filtering using Ray Casting by Eric Jensen 2012 The Basic Methodology

Transcription:

Computer Graphics - Spatial Index Structures - Philipp Slusallek

Overview Last lecture Overview of ray tracing Ray-primitive intersections Today Acceleration structures Bounding Volume Hierarchies (BVH) Grids Octrees K-D trees Ray bundles 2

Acceleration Strategies Tracing rays in O(n) is too expensive Need hundreds of millions rays per second Scenes consist of millions of triangles Faster ray-primitive intersection algorithms Do not reduce asymptotical complexity, just a constant Reduce complexity through pre-sorting data Spatial index structures Dictionaries for ray tracing Eliminate intersection candidates Can reduce complexity to O(log n) Theoretical worst case still O(n) highly unlikely Tracing of continuous bundles of rays Exploit coherence of neighboring rays, amortize cost among them Frustum tracing, cone tracing, beam tracing,... 3

Spatial Index Structures Motivation: Fewer candidates that need to be tested for intersections Approaches Spatial partitioning (Hierarchically) partition of space or objects Binary space partitions (BSP), K-D trees, Octrees Bounding volume hierarchies (BVH) Grids, hierarchies of grids Directional partitioning (not very useful) 5D partitioning (space and direction, once a big hype) Close to pre-compute visibility for all points and all directions Easily causes memory problems for the index 4

SPATIAL PARTITIONING 5

Aggregate Objects Object that holds groups of objects Stores bounding volume and pointers to children Useful for instancing and Bounding Volume Hierarchies (BVH) pointers 6

Bounding Volumes Observation Bound geometry with BV Only compute intersection with children if ray hits BV Sphere Very fast intersection computation Often inefficient because too large Axis-aligned bounding box (AABB) Very simple intersection computation (min-max) Sometimes too large Non-axis-aligned box A.k.a. oriented bounding box (OBB) Often better fit Fairly complex computation Slabs Pairs of half spaces Fixed number of orientations/axes: e.g. x+y, x-y, etc. Pretty fast computation Becomes more costly for 3D 7

Bounding Volume Hierarchy Definition Hierarchical partitioning of the set of objects BVHs form a tree structure Each inner node stores a volume enclosing all sub-trees Each leaf stores a volume and pointers to objects All nodes are aggregate objects Object partitioning Usually every object appears exactly once in the tree Can also allow for multiple instancing of objects or subtrees Need to store a transformation ( later) 8

Bounding Volume Hierarchy Hierarchy of groups of objects 9

BVH Traversal (1) Accelerate ray tracing By eliminating intersection candidates Traverse the tree Only if root node is intersected by the ray 10

BVH Traversal (2) Accelerate ray tracing By eliminating intersection candidates Traverse the tree Consider only objects in nodes intersected by the ray 11

BVH Traversal (3) Accelerate ray tracing By eliminating intersection candidates Traverse the tree Cheap traversal instead of costly intersection Skip 2nd child if (non-overlapping) intersection found in 1st child 12

BVH Traversal (4) Accelerate ray tracing By eliminating intersection candidates Traverse the tree Cannot stop in cases like this!! 13

Object vs. Space Partitioning BVHs partition objects into groups They are still a spatial index structure Next: Space partitioning Subdivide space in regions Organize them in a structure (tree or table) 14

Uniform Grids Definition Regular partitioning of space into equal-size cells Each cell holds a reference to all the objects overlapping the cell Bounding box of the grid For each object Compute object bounding box Expand grid bounding box Resolution Want number of cells in O(n) Resolution in each dimension Usually d: diagonal (vector) n: number of objects v: volume of the bounding box : density (user-defined) 15

Uniform Grid Construction For each object: Compute bounding box Determine (conservative) lattice coordinates of the box For each cell within the 3D lattice range Add object reference to cell lx hx hy ly 16

Uniform Grid Construction V2 For each object: Compute bounding box Determine lattice coordinates of the box For each cell within the 3D lattice range Add object reference to cell only if the object intersects cell boundary Optimization: Check if whether an object intersects a given grid cell / AABB. 17

Uniform Grid Traversal 3D DDA (modified Bresenham algorithm, more later) Find lattice coordinates of starting cell From intersection point with box if ray starts outside From camera position if inside Loop: For each primitive in current cell Check if ray intersects the primitive If closest (positive) hit along the ray so far, record hit If closest hit recorded is inside cell, then exit loop Step to next cell in the structure Exit loop if grid boundary is reached 18

Uniform Grid Traversal Mailboxing Single primitive can be inserted in many cells Avoid multiple intersections Keep track of intersection tests Per-object cache of ray IDs Problem with concurrent access Per-ray cache of object IDs Data local to a ray 19

Nested Grids Problem: Teapot in a stadium Uniform grids cannot adapt to local density of objects Nested Grids Hierarchy of uniform grids Each cell has a (potentially different) grid in itself Cells of uniform grid (colored by # of intersection tests) Same for two-level grid 20

Octrees and Quadtrees Octree (3D) Hierarchical space partitioning Each inner node contains 8 equally sized voxels Split in the middle In 2D: Quadtree Adaptive subdivision Adjust depth to local scene complexity (e.g. # of objects in cell) 21

BSP Trees Definition Binary Space Partition Tree (BSP) Recursively split space with planes Arbitrary split positions Arbitrary orientations Often used for visibility computation E.g. in games (Doom) Enumerating objects in back to front order 22

kd-trees Definition Axis-Aligned Binary Space Partition Tree Recursively split space with axis-aligned planes Arbitrary split positions X, Y or Z orientations 23

kd-tree Example (1) 24

kd-tree Example (2) A A 25

kd-tree Example (3) B A B A 26

kd-tree Example (4) B A B A L1 L2 27

kd-tree Example (5) B A B C A L1 L2 C 28

kd-tree Example (6) B A B C A L1 L2 D L3 D C 29

kd-tree Example (7) B A B C A L1 L2 D L3 D L4 L5 C 30

kd-tree Traversal Front-to-back traversal Traverse child nodes in order along rays Termination criterion As soon as surface intersection is found (in current cell) Maintain manual stack of sub-trees to traverse More efficient than recursive function calls 31

kd-tree Traversal (1) B A B C A L1 L2 D L3 D L4 L5 C Current: Stack: A 32

kd-tree Traversal (2) B A B C A L1 L2 D L3 D L4 L5 C Current: B Stack: C 33

kd-tree Traversal (3) B A B C A L1 L2 D L3 D L4 L5 C Current: L2 Stack: C 34

kd-tree Traversal (4) B A B C A L1 L2 D L3 D L4 L5 C Current: Stack: C 35

kd-tree Traversal (5) B A B C A L1 L2 D L3 D L4 L5 C Current: Stack: C 36

kd-tree Traversal (6) B A B C A L1 L2 D L3 D L4 L5 C Current: D Stack: L3 37

kd-tree Traversal (7) B A B C A L1 L2 D L3 D L4 L5 C Current: L4 Stack: L5 L3 38

kd-tree Traversal (8) B A B C A L1 L2 D L3 D L4 L5 C Current: Stack: L5 L3 39

kd-tree Traversal (9) B A B C A L1 L2 D L3 D L4 L5 C Current: Result: Stack: L5 L3 40

kd-tree Properties kd-trees Split space instead of sets of objects Split into disjoint and fully covering regions Adaptive Can handle the Teapot in a Stadium well Compact representation Relatively little memory overhead per node Node stores: Split location (1D), child pointer (to both children), Axis-flag (often merged into pointer) Can be compactly stored in 8 bytes But replication of objects in (possibly) many nodes Can greatly increase memory usage Cheap traversal One subtraction, multiplication, decision, and fetch But many more cycles due to dependencies & HW pipelines 41

Overview: kd-trees Construction Adaptive Compact Cheap traversal 42

Building kd-trees Given: Axis-aligned bounding box ( cell ) List of geometric primitives (triangles?) in box Core operation: Pick an axis-aligned plane to split the box into two parts Sift geometry into two batches (left/right, some redundancy) Recurse Termination criteria! 43

Intuitive kd-tree Building Split axis Round-robin; largest extent Split location Middle of extent or median of geometry (balanced tree) Termination Target # of primitives, limited tree depth 44

Intuitive Hack kd-tree Building Split axis Round-robin; largest extent Split location Middle of extent; median of geometry (balanced tree) Termination Target # of primitives, limited tree depth All of these techniques are NOT very clever :-) 45

Building good kd-trees What split do we really want? Clever idea: the one that makes ray tracing cheapest Write down an expression of cost and minimize it Cost optimization What is the cost of tracing a ray through a cell? Fixed cost per tree node Plus probability of hitting left child Given that I have hit current node Times cost of left child Same for the right node Cost(cell) = traversalcost + Prob(hit L hit P) * Cost(L) + Prob(hit R hit P) * Cost(R) 46

Splitting with Cost in Mind 47

Split in the Middle Makes the L & R probabilities equal Pays no attention to the L & R costs 48

Split at the Median Makes the L & R costs equal Pays no attention to the L & R probabilities 49

Cost-Optimized Split Automatically and rapidly isolates complexity Produces large chunks of (almost) empty space 50

Building good kd-trees Need the probabilities Assume uniform directional distribution of rays Probability turns out to be proportional to surface area (SA) Area of outer surface of bounding box (not its volume) Need the child cell costs Simple triangle count works great (rough approx.) Surface Area Heuristic (SAH) Important!! Cost(cell) = traversalcost + Prob(hit L hit P) * Cost(L) + Prob(hit R hit P) * Cost(R) = traversalcost + SA(L)/SA(P) * TriCount(L)*intersectionCost + SA(R)/SA(P) * TriCount(R)*intersectionCost 51

Termination Criteria When should we stop splitting? Another clever idea: When splitting isn t helping any more. Use the cost estimates in your termination criteria Threshold of cost improvement Stretch decision over multiple levels, to avoid local minima Threshold of cell size Absolute probability so small there s no point 52

Building good kd-trees Basic build algorithm Pick an axis, or optimize across all three Build a set of candidates (split locations) Based on BBox of triangles (in/out events) or Cost function is linear in between, so min/max must be at edge Predefined locations (fixed (small) number of bins) For large N the SAH is typically very smooth Sort the triangle events or bin them Binning can be done in constant time Walk through candidate planes to find minimum cost split Sift objects (while doing the computation for next level!!) Streaming operation!! Characteristics of the tree you re looking for Deep and thin Depth often 30 and more A few objects per leaf Big empty cells 53

Building kd-trees quickly Very important to build good trees first Otherwise you have no basis for comparison Don t give up cost optimization! Use the math, Luke Luckily, lots of flexibility Axis picking ( hack pick vs. full optimization) Candidate picking (bboxes, exact; binning, sorting) Termination criteria ( knob controlling tradeoff) 54

Fast Ray Tracing w/ kd-trees Adaptive Compact Cheap traversal 56

What s in a Node? A kd-tree internal node needs: Am I a leaf? Split axis Split location Pointers to children 57

Compact (8-byte) Nodes kd-tree node can be packed into 8 bytes Leaf flag + split axis 2 bits Split location 32-bit float Always two children, put them side-by-side One 32-bit pointer 58

Compact (8-byte) Nodes kd-tree node can be packed into 8 bytes Leaf flag + split axis 2 bits Split location 32-bit float Always two children, put them side-by-side One 32-bit pointer So close! Sweep those 2 bits under the rug Merge them into the lower bits of the pointer 59

No Bounding Box! kd-tree node corresponds to an AABB Doesn t mean it has to contain one 6 floats: 24 bytes 4X explosion (!) 60

Memory Layout Cache lines are much bigger than 8 bytes! Advantage of compactness lost with poor layout Pretty easy to do something reasonable Building depth first, watching memory allocator Use the idea of treelets Small parts of the tree that are generated and stored together Can have optimized layout (less/no pointers) Can be stored in one cache line (efficient traversal) 61

Fast Ray Tracing w/ kd-trees Adaptive Compact Cheap traversal 63

kd-tree Traversal Operation Maintain on a (manual) stack Entry and exit distance to node (t_near and t_far) Plus node still to be traversed Three cases t_split >= t_far Go only to near node t_near < t_split < t_far Go to both t_split <= t_near Go only to far node Near and far depend on direction of ray! 64

kd-tree Traversal: Inner Loop given(node, t_near, t_far) while (! node.isleaf() ) { } t_split = ( split_location - ray->p[split_axis] ) * ray_iv[split_axis] if (t_split <= t_near) continue with (far_child, t_near, t_far) if (t_split >= t_far) continue with (near_child, t_near, t_far) if (hit both children) push (far_child, t_split, t_far) onto stack continue with (near_child, t_near, t_split) // hit far child only // hit near child only ray_iv is inverse of (normalized) direction vector (length along ray to do go one unit along that axis) 65

Optimize Your Inner Loop kd-tree traversal is the most critical kernel It happens about a zillion times It s tiny Sloppy coding will show up Optimize, optimize, optimize Remove recursion and minimize stack operations Other standard tuning & tweaking 66

Summary: Exploit Advantages Adaptive You have to build a good tree Build a cost-optimized kd-tree w/ the surface area heuristic Compact At least use the compact node representation: use 8-byte nodes You can t be fetching whole cache lines every time Lay out your memory in a cache-friendly way Cheap traversal No sloppy inner loops! (one subtract, one multiply!) 67

Can it go faster? How do you make fast code go faster? Parallelize it! Not covered here 68

Bounding Volume Hierarchies Today: Best Known Method (BKM) Traversal a bit more expensive (handling of overlap of BVs) Building BVHs can be much faster Using streaming construction (based on binary splits and SAH) Often used to rebuild BVHs for entire dynamic objects per frame 69

DIRECTIONAL APPROACHES 70

Directional Partitioning Applications Useful only for rays that start from a single point Camera Point light sources Preprocessing of visibility Requires scan conversion of geometry For each object locate where it is visible Expensive and linear in # of objects Generally not used for primary rays GPUs can do this very efficiently Variation: Light buffer Lazy and conservative evaluation Store occluder that was found in directional structure Test entry first for next shadow test 71

Ray Classification Partitioning of space and direction [Arvo & Kirk 87] Roughly pre-computes visibility for the entire scene What is visible from each point in each direction? Very costly preprocessing, cheap traversal Improper trade-off between preprocessing and run-time Memory hungry, even with lazy evaluation Seldom used in practice 72