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

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

Acceleration Data Structures

Spatial Data Structures

Accelerating Ray-Tracing

Spatial Data Structures

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

Spatial Data Structures

Spatial Data Structures

Spatial Data Structures

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

Intersection Acceleration

Ray Intersection Acceleration

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

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

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

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

Lecture 2 - Acceleration Structures

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

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

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

Accelerating Ray-Scene Intersection Calculations

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

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

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

Ray Tracing Acceleration Data Structures

Computer Graphics Ray Casting. Matthias Teschner

improving raytracing speed

Acceleration Structures. CS 6965 Fall 2011

Bounding Volume Hierarchies. CS 6965 Fall 2011

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

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

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

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

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

Accelerated Raytracing

Hidden Surface Elimination: BSP trees

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

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

Ray Casting. 3D Rendering. Ray Casting. Ray Casting. Ray Casting. Ray Casting

Lecture 11: Ray tracing (cont.)

Recall: Inside Triangle Test

Ray Tracing Acceleration. CS 4620 Lecture 22

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

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

CPSC GLOBAL ILLUMINATION

Viewing and Ray Tracing. CS 4620 Lecture 4

Advanced Ray Tracing

Viewing and Ray Tracing

Ray Tracing Acceleration. CS 4620 Lecture 20

MSBVH: An Efficient Acceleration Data Structure for Ray Traced Motion Blur

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

Graphics 2009/2010, period 1. Lecture 8: ray tracing

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

CS770/870 Spring 2017 Ray Tracing Implementation

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

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

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Real-Time Voxelization for Global Illumination

Dynamic Bounding Volume Hierarchies. Erin Catto, Blizzard Entertainment

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

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

CS 431/636 Advanced Rendering Techniques

Ray Intersection Acceleration

Geometric Modeling in Graphics

Ray tracing idea. Ray Tracing. Ray tracing algorithm. Plane projection in drawing. CS 465 Lecture 3

Collision and Proximity Queries

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

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

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

Acceleration Data Structures for Ray Tracing

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 13: Reyes Architecture and Implementation. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

SPATIAL DATA STRUCTURES. Jon McCaffrey CIS 565

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

11 - Spatial Data Structures

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

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

Real-time ray tracing

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

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

Accelerating Ray Tracing

Specialized Acceleration Structures for Ray-Tracing. Warren Hunt

Ray Casting. To Do. Outline. Outline in Code. Foundations of Computer Graphics (Spring 2012) Heckbert s Business Card Ray Tracer

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

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

Physically Based Rendering ( ) Intersection Acceleration

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

9. Visible-Surface Detection Methods

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

COMPUTER GRAPHICS COURSE. Ray Tracing

Ray Tracing COMP575/COMP770

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

DiFi: Distance Fields - Fast Computation Using Graphics Hardware

Ray Casting. COS 426, Spring 2015 Princeton University

Collision Detection based on Spatial Partitioning

A Model to Evaluate Ray Tracing Hierarchies

The Traditional Graphics Pipeline

Transcription:

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

Geometric modeling and geometric queries p What point on the mesh is closest to p?

What point on the mesh is closest to p? Conceptually easy: - loop over all triangles - compute closest point to current triangle - keep globally closest point Q: What s the cost? Does halfedge help? What if we have billions of faces? p

Different query: ray-mesh intersection A ray is an oriented line starting at a point Want to know where a ray pierces a surface Why? - GEOMETRY: inside-outside test - RENDERING: visibility, ray tracing - SIMULATION: collision detection Might pierce surface in many places!

Ray: parametric equation origin unit direction point along ray

Intersecting a ray with an implicit surface Recall implicit surfaces: all points x such that f(x) = 0 How do we find points where a ray intersects this surface? we know all points along the ray: r(t) = o + td replace x with r, solve for t Example: unit sphere quadratic formula: d o

Ray-plane intersection Suppose we have a plane N T x = c How do we find intersection with ray r(t) = o + td? Again, replace point x with the ray equation: Solve for t: And plug t back into ray equation:

Ray-triangle intersection Triangle is in a plane... - Compute ray-plane intersection - Q: What do we do now? - A: Why not compute barycentric coordinates of hit point? - If barycentric coordinates are all positive, point in triangle - Not much more to say! Actually, a lot more to say

Ray-triangle intersection Parameterize triangle given by vertices using barycentric coordinates Can think of a triangle as an affine map of the unit triangle 1 v u 1

Ray-triangle intersection Plug parametric ray equation directly into equation for points on triangle: Solve for u, v, t: transforms triangle back to unit triangle in u,v plane, and transforms ray s direction to be orthogonal to plane z y v 1 x 1 u

Ray-scene intersection a first optimization

Ray-axis-aligned-box intersection

Ray-axis-aligned-box intersection tmax Find intersection of ray with all planes of box: tmin Math simplifies greatly since plane is axis aligned (consider x=x0 plane in 2D): Figure shows intersections with x=x0 and x=x1 planes.

Ray-axis-aligned-box intersection Compute intersections with all planes, take intersection of tmin/tmax intervals tmax tmax tmax tmin tmin tmin Note: tmin < 0 Intersections with x planes Intersections with y planes Final intersection result How do we know when the ray misses the box?

Core methods for ray-primitive queries Given primitive p: p.intersect(r) returns value of t corresponding to the point of intersection with ray r p.bbox() returns axis-aligned bounding box of the primitive tri.bbox(): tri_min = min(p0, min(p1, p2)) tri_max = max(p0, max(p1, p2)) return bbox(tri_min, tri_max)

Ray-scene intersection Given a scene defined by a set of N primitives and a ray r, find the closest point of intersection of r with the scene Find the first primitive the ray hits p_closest = NULL t_closest = inf for each primitive p in scene: t = p.intersect(r) if t >= 0 && t < t_closest: t_closest = t p_closest = p Complexity:

Let s look at a simpler problem Take a set of integers S 10 123 20 100 6 25 64 11 200 30 Given a new integer k=18, find the element in S that is closest Sort first: 6 10 11 20 25 30 64 100 123 200 Then what?

How do we organize scene primitives to enable fast ray-scene intersection queries?

Simple case (we ve seen it already) Ray misses bounding box of all primitives in scene O(1) cost: requires 1 ray-box test

Another (should be) simple case Ray hits bounding box, check all primitives O(N) cost

Another (should be) simple case A bounding box of bounding boxes!

Another (should be) simple case A B A C B C There is no reason to stop there!

Bounding volume hierarchy (BVH) Interior nodes: - Represent subset of primitives in scene - Store aggregate bounding box for all primitives in subtree Leaf nodes: - Contain list of primitives 1 2 3 D 4 5 B A 6 7 8 9 E 10 11 1 2 3 D 4 5 B A 6 7 8 9 E 10 11 C Two different BVH organizations of the same scene containing 22 primitives. Leaf node are the same. 12 13 18 19 12 13 18 19 14 15 F 16 17 C 20 21 22 G 14 15 F 16 17 20 21 22 G Q: Which one is better? A A B C B C D E F G 1,2,3 4,5 6,7,8, 9,10,11 12,13,14, 15, 16,17 18,19,20, 21,22 D F E G 1,2,3 4,5 6,7,8, 9,10,11 12,13,14, 15,16,17 18,19,20, 21,22

A less-structured BVH example BVH partitions each node s primitives into disjoints sets - Note: The sets can still be overlapping in space! A A B C C B

Ray-scene intersection using a BVH struct BVHNode { bool leaf; BBox bbox; BVHNode* child1; BVHNode* child2; Primitive* primlist; }; struct ClosestHitInfo { Primitive prim; float min_t; }; child 1 node child 2 void find_closest_hit(ray* ray, BVHNode* node, ClosestHitInfo* closest) { if (!intersect(ray, node->bbox)) return; } if (node->leaf) { for (each primitive p in node->primlist) { (hit, t) = intersect(ray, p); if (hit && t < closest.min_t) { closest.prim = p; closest.min_t = t; } } } else { find_closest_hit(ray, node->child1, closest); find_closest_hit(ray, node->child2, closest); } Hmmm this is still checking all the primitives in the scene.

Ray-scene intersection using a BVH struct BVHNode { bool leaf; BBox bbox; BVHNode* child1; BVHNode* child2; Primitive* primlist; }; struct ClosestHitInfo { Primitive prim; float min_t; }; void find_closest_hit(ray* ray, BVHNode* node, ClosestHitInfo* closest) { child 1 node child 2 if (!intersect(ray, node->bbox) (closest point on box is farther than closest.min_t)) return; } if (node->leaf) { for (each primitive p in node->primlist) { (hit, t) = intersect(ray, p); if (hit && t < closest.min_t) { closest.prim = p; closest.min_t = t; } } } else { find_closest_hit(ray, node->child1, closest); find_closest_hit(ray, node->child2, closest); } What if ray points the other way?

Improvement: front-to-back traversal Invariant: only call find_closest_hit() if ray intersects bbox of node. node void find_closest_hit(ray* ray, BVHNode* node, ClosestHitInfo* closest) { if (node->leaf) { for (each primitive p in node->primlist) { (hit, t) = intersect(ray, p); if (hit && t < closest.min_t) { closest.prim = p; closest.min_t = t; } } } else { (hit1, min_t1) = intersect(ray, node->child1->bbox); (hit2, min_t2) = intersect(ray, node->child2->bbox); child 1 child 2 } } NVHNode* first = (min_t1 <= min_t2)? child1 : child2; NVHNode* second = (min_t1 <= min_t2)? child2 : child1; find_closest_hit(ray, first, closest); if (second child s min_t is closer than closest.min_t) find_closest_hit(ray, second, closest); Front to back traversal. Traverse to closest child node first. Why?

Another type of query: any hit Sometimes it s useful to know if the ray hits ANY primitive in the scene at all (don t care about distance to first hit) bool find_any_hit(ray* ray, BVHNode* node) { if (!intersect(ray, node->bbox)) return false; } if (node->leaf) { for (each primitive p in node->primlist) { (hit, t) = intersect(ray, p); if (hit) return true; } else { return ( find_closest_hit(ray, node->child1, closest) find_closest_hit(ray, node->child2, closest) ); } Traversal order should attempt to maximize chance of any primitive being hit!

Bounding volume hierarchy (BVH) 1 2 6 7 1 2 6 7 3 D 4 5 B 8 9 E 10 11 3 D 4 5 8 9 E 10 11 12 13 A 18 19 B 12 13 A C 18 19 Two different BVH trees. Which one is better? 14 15 F 16 17 C 20 21 22 G 14 15 F 16 17 20 21 22 G

For a given set of primitives, there are many possible BVHs Q: how many ways are there to partition N primitives into two groups? A: 2 N -2 So, how do we build a high-quality BVH tree?

How would you partition these triangles into two groups?

What about these?

Intuition about a good partition? Partition into child nodes with equal numbers of primitives Minimize overlap between children, avoid empty space

What are we really trying to do? A good partitioning minimizes the cost of finding the closest intersection of a ray with primitives in the node. If a node is a leaf node (no partitioning): Where is the cost of ray-primitive intersection for primitive i in the node. (Common to assume all primitives have the same cost)

Cost of making a partition The expected cost of ray-node intersection, given that the node s primitives are partitioned into child sets A and B is: is the cost of traversing an interior node (e.g., load data, bbox check) and and are the costs of intersection with the child nodes are probabilities ray intersects bbox of child node Primitive count is a common approximation for child node costs: Where:

Estimating probabilities For a given direction, the number of rays that hits an object is proportional to the projected area

Estimating probabilities For rays with endpoint at fixed distance, probability that a ray hits object is proportional to the solid angle subtended by its surface

Estimating probabilities For convex objects and rays with endpoints that are far away, probability that a ray hits object is approximately proportional to surface area

Estimating probabilities For convex object A inside convex object B, the probability that a random ray that hits B also hits A is given by the ratio of the surface areas SA and SB of these objects. Surface area heuristic (SAH): Assumptions of the SAH (may not hold in practice): - Rays are randomly distributed - Rays are not occluded

Implementing partitions Constrain search for good partitions to axis-aligned spatial partitions - Choose an axis - Choose a split plane on that axis - Partition primitives by the side of splitting plane their centroid lies

Efficiently implementing partitioning Efficient approximation: split spatial extent of primitives into B buckets (B is typically small: B < 32) b0 b1 b2 b3 b4 b5 b6 b7 For each axis: x,y,z: initialize buckets For each primitive p in node: b = compute_bucket(p.centroid) b.bbox.union(p.bbox); b.prim_count++; For each of the B-1 possible partitioning planes evaluate SAH Execute lowest cost partitioning found (or make node a leaf)

Troublesome cases All primitives with same centroid (all primitives end up in same partition) All primitives with same bbox (ray often ends up visiting both partitions)

Primitive-partitioning acceleration B C

Primitive-partitioning acceleration structures vs. space-partitioning structures Primitive partitioning (bounding volume hierarchy): partitions node s primitives into disjoint sets (but sets may overlap in space) Space-partitioning (grid, K-D tree) partitions space into disjoint regions (primitives may be contained in multiple regions of space)

Uniform grid Partition space into equal sized volumes ( voxels ) Each grid cell contains primitives that overlap voxel. (very cheap to construct acceleration structure) Walk ray through volume in order - Very efficient implementation possible (think: 3D line rasterization) - Only consider intersection with primitives in voxels the ray intersects

What should the grid resolution be? Too few grids cell: degenerates to bruteforce approach Too many grid cells: incur significant cost traversing through cells with empty space

Heuristic Choose number of voxels ~ total number of primitives (constant prims per voxel, assuming uniform distribution) Intersection cost:

Non-uniform distribution of geometric detail requires adaptive grids [Image credit: Pixar]

K-D trees Recursively partition space via axis-aligned planes - Interior nodes correspond to spatial splits (still correspond to spatial volume) - Node traversal can proceed in front-to-back order (unlike BVH, can terminate search after first hit is found*). D A B C D E B C F E F A

Challenge: objects overlap multiple nodes Want node traversal to proceed in front-to-back order so traversal can terminate search after first hit found D A B C 2 D E F B 1 C Triangle 1 overlaps multiple nodes. Ray hits triangle 1 when in highlighted leaf cell. But intersection with triangle 2 is closer! (Haven t traversed to that node yet) E F A Solution: require primitive intersection point to be within current leaf node. (primitives may be intersected multiple times by same ray *)

Quad-tree / octree Like uniform grid: easy to build (don t have to choose partition planes) Has greater ability to adapt to location of scene geometry than uniform grid. But lower intersection performance than K-D tree (only limited ability to adapt) Quad-tree: nodes have 4 children (partitions 2D space) Octree: nodes have 8 children (partitions 3D space)

Summary of accelerating geometric queries: choose the right structure for the job Primitive vs. spatial partitioning: - Primitive partitioning: partition sets of objects - Bounded number of BVH nodes, simpler to update if primitives in scene change position - Spatial partitioning: partition space - Traverse space in order (first intersection is closest intersection), may intersect primitive multiple times Adaptive structures (BVH, K-D tree) - More costly to construct (must be able to amortize construction over many geometric queries) - Better intersection performance under non-uniform distribution of primitives Non-adaptive accelerations structures (uniform grids) - Simple, cheap to construct - Good intersection performance if scene primitives are uniformly distributed Many, many combinations thereof