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

Similar documents
Lecture 2 - Acceleration Structures

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

Lecture 4 - Real-time Ray Tracing

Acceleration Data Structures

Spatial Data Structures

Spatial Data Structures

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

Ray Tracing Acceleration Data Structures

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

Spatial Data Structures

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

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

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

Spatial Data Structures

Intersection Acceleration

Accelerated Raytracing

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

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

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

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

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

Accelerating Ray-Tracing

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

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

Spatial Data Structures

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

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

Advanced Ray Tracing

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

CS 431/636 Advanced Rendering Techniques

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

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

Acceleration Data Structures for Ray Tracing

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

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

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

Row Tracing with Hierarchical Occlusion Maps

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

Recall: Inside Triangle Test

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

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

Lecture 11: Ray tracing (cont.)

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

Accelerating Ray Tracing

Ray Intersection Acceleration

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

improving raytracing speed

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 8: Data-Oriented Design. Welcome!

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

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

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

Ray Intersection Acceleration

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

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

Bounding Volume Hierarchies. CS 6965 Fall 2011

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

Ray Tracing Acceleration. CS 4620 Lecture 20

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

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

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

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

INFOGR Computer Graphics

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

Lecture 11 - GPU Ray Tracing (1)

Two Optimization Methods for Raytracing. W. Sturzlinger and R. F. Tobler

Real Time Ray Tracing

Computer Graphics Ray Casting. Matthias Teschner

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

Ray Tracing Acceleration. CS 4620 Lecture 22

Ray Tracing: Intersection

Acceleration Structures. CS 6965 Fall 2011

Holger Dammertz August 10, The Edge Volume Heuristic Robust Triangle Subdivision for Improved BVH Performance Holger Dammertz, Alexander Keller

Advanced 3D-Data Structures

COMP 175: Computer Graphics April 11, 2018

Exploiting Local Orientation Similarity for Efficient Ray Traversal of Hair and Fur

Dynamic Bounding Volume Hierarchies. Erin Catto, Blizzard Entertainment

Ray Tracing Performance

VIII. Visibility algorithms (II)

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

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

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

Soft Shadow Volumes for Ray Tracing with Frustum Shooting

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

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

Cross-Hardware GPGPU implementation of Acceleration Structures for Ray Tracing using OpenCL

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

CS 465 Program 5: Ray II

CS535 Fall Department of Computer Science Purdue University

Sung-Eui Yoon ( 윤성의 )

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

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

SPATIAL DATA STRUCTURES. Jon McCaffrey CIS 565

Fast BVH Construction on GPUs

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

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

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

Transcription:

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

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 4 High-speed Ray Tracing Ray Tracing Needful things Whitted-style ray tracing: 1 primary ray per pixel 1 shadow ray per pixel per light Optional: rays for reflections & refraction Estimate: 10 rays per pixel 1M pixels (~1280x800) 30 fps 300Mrays/s How does one intersect 300Mrays/s on a 3Ghz CPU? Easy: use no more than 10 cycles per ray.

INFOGR Lecture 11 Acceleration 5 High-speed Ray Tracing Actually We have 8 cores (so 80 cycles) Executing AVX code (so 640 cycles) Plus 20% gains from hyperthreading (768 cycles). But really Assuming we get a linear increase in performance for the number of cores and AVX, how do we intersect thousands of triangles in 768 cycles?

INFOGR Lecture 11 Acceleration 6 High-speed Ray Tracing Optimization 1. Measure: performance & scalability 2. High level optimizations: improve algorithmic complexity 3. Low level optimization: instruction level & threadlevel parallelism, caching 4. GPGPU More in the master course Optimization & Vectorization.

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 8 High-speed Ray Tracing Optimization: reduce algorithmic complexity Complexity: number of ray/primitive intersections = pixels * paths per pixel * average path length * primitives = 1M * 1 * 2 * 1M

INFOGR Lecture 11 Acceleration 9 Acceleration Structures Option 1: Use a grid. Each grid cell has a list of primitives that overlap it. The ray traverses the grid, and intersects only primitives in the grid cells it visits. Problems: Many primitives will be checked more than once. It costs to traverse the grid. How do we chose grid resolution? What if scene detail is not uniform?

INFOGR Lecture 11 Acceleration 10 Acceleration Structures Option 2: Use a nested grid. We use fewer cells. Each grid cell that overlaps multiple primitives has a smaller grid in it. The ray rapidly traverses empty space, and checks the nested grids when needed. Problems: How do we chose grid resolutions? Is this the optimal way to traverse space?

INFOGR Lecture 11 Acceleration 11 Acceleration Structures Option 3: Use an octree. We start with a bounding box of the scene; The box is recursively subdivided in 8 equal boxes as long as it contains more than X primitives. Problems: What if all the detail is exactly in the centre of the scene? Splitting in 8 boxes: is that the optimal subdivision?

INFOGR Lecture 11 Acceleration 12 Acceleration Structures Option 4: Use an kd-tree. We start with a bounding box of the scene; Using arbitrary axis-aligned planes, we recursively cut it in two halves as long as it contains more than X primitives. Problems: Primitives may end up in multiple leaf nodes. How hard is it to build such a tree?

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 15 BVH Option 5: Use a bounding volume hierarchy. root left right top bottom top bottom

INFOGR Lecture 11 Acceleration 16 BVH The Bounding Volume Hierarchy BSPs, grids, octrees and kd-trees are examples of spatial subdivisions. The BVH is of a different category: it is an object partitioning scheme: Rather than recursively splitting space, it splits collections of objects. primitive array + splitplane = primitives in left child primitives in right child

INFOGR Lecture 11 Acceleration 17 BVH The Bounding Volume Hierarchy Sorting an array of elements based on a value: BVH is very similar to QuickSort. In the BVH construction algorithm, the split plane position is the pivot. primitive array + splitplane = primitives in left child primitives in right child

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: data structure struct BVHNode { BVHNode* left; BVHNode* right; aabb bounds; bool isleaf; vector<primitive*> primitives; }; // 4 or 8 bytes // 4 or 8 bytes // 2 * 3 * 4 = 24 bytes //? //?

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: construction void ConstructBVH( Primitive* primitives ) { BVHNode* root = new BVHNode(); root->primitives = primitives; root->bounds = CalculateBounds( primitives ); root->isleaf = true; root->subdivide(); } void BVHNode::Subdivide() { if (primitives.size() < 3) return; this.left = new BVHNode(), this.right = new BVHNode(); split bounds in two halves, assign primitives to each half this.left->subdivide(); this.right->subdivide(); this.isleaf = false; }

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: construction primitive array primitive index array 0 1 2 N-3 N-2 N-1 indices of primitives in left child indices of primitives in right child first count first count Construction consequences: Construction happens in place: primitive array is constant, index array is changed Very similar to Quicksort (split plane = pivot) Data consequences: Primitive list for node becomes offset + count No pointers! No pointers? (what about left / right?)

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: data structure struct BVHNode { BVHNode* left; BVHNode* right; aabb bounds; bool isleaf; vector<primitive*> primitives; }; 0 1 2 struct BVHNode { uint left; // 4 bytes uint right; // 4 bytes aabb bounds; // 24 bytes bool isleaf; // 4 bytes uint first; // 4 bytes uint count; // 4 bytes }; // -------- // 44 bytes BVH node pool

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: data structure struct BVHNode { union // 4 bytes { uint left; uint first; }; aabb bounds; // 24 bytes uint count; // 4 bytes }; // -------- // 32 bytes struct BVHNode { uint left; // 4 bytes uint right; // 4 bytes aabb bounds; // 24 bytes bool isleaf; // 4 bytes uint first; // 4 bytes uint count; // 4 bytes }; // -------- // 44 bytes

Ray Tracing for Games Acceleration Structures Bounding Volume Hierarchy: data structure struct BVHNode { float3 bmin; uint leftfirst; // bounds: minima // or a union // bounds: maxima float3 bmax; uint count; // leaf if 0 }; // -------- // 32 bytes

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 25 BVH Traversal BVH Traversal Algorithm: Starting with the root: If the node is a leaf node: Intersect triangles. Else: If the ray intersects the left child AABB: Traverse left child If the ray intersects the right child AABB: Traverse right child How efficient is this? In this case: we check every AABB, but we only try to intersect one red sphere. (total: 8 tests)

INFOGR Lecture 11 Acceleration 26 BVH Traversal BVH Efficiency The number of nodes in a BVH is at most 2N 1. Example: 16 8 + 8 (4 + 4) + (4 + 4) ((2+2) + (2+2))+((2+2) + (2+2)) 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1 In this case, we get from the root to a leaf in 5 steps, or: log 2 N + 1. For 1024 primitives, we get to a leaf in 11 steps. For 1M primitives, we get to a leaf in 21 steps. 1 2 4 8 16 ------ 31

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 28 Optimizing Construction How do we construct a good BVH? What is a good BVH? One that minimizes the number of ray/primitive intersections, and the number of ray/aabb intersections.

INFOGR Lecture 11 Acceleration 29 Optimizing Construction BVH Quality A good BVH minimizes the number of intersections. Concrete: Q bvh = Where: N 1 P AABB (C AABB + N tri C tri ) Probability of hitting an AABB with an arbitrary ray: Proportional to the surface area of the AABB. N is the number of BVH nodes; P AABB is the probability of a ray hitting the AABB; C AABB is the cost of a ray intersecting the AABB; N tri is the number of triangles in the node; C tri is the cost of intersecting a triangle.

Ray Tracing for Games Binned BVH Construction Surface Area Heuristic (Or: what is the best way to slice a bunny?)

Ray Tracing for Games Binned BVH Construction Cost: N left * A left + N right * A right Select the split with the lowest cost.

INFOGR Lecture 11 Acceleration 32 Optimizing Construction Surface Area Heuristic We construct a BVH by minimizing the cost after each split, i.e. we use the split plane position and orientation that minimizes the cost function: C split = N left A left + N right Arig ht The split is not made at all if the best option is more expensive than not splitting, i.e. C nosplit = N A This provides a natural termination criterion for BVH construction.

INFOGR Lecture 11 Acceleration 33 Optimizing Construction Efficiency of the Surface Area Heuristic A BVH constructed with the Surface Area Heuristic is typically twice as efficient as a tree constructed with naïve midpoint subdivision.

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Lecture 11 Acceleration 35 Fast Traversal root left right left right left right left right left right

INFOGR Lecture 11 Acceleration 36 Fast Traversal Ray Packet Traversal Primary rays for a small square of pixels tend to travel the same BVH nodes. We can exploit this by explicitly traversing ray packets.

INFOGR Lecture 11 Acceleration 37 Fast Traversal Packet Traversal Algorithm: Starting with the root: If the node is a leaf node: Intersect triangles. Else: If any ray intersects the left child AABB: Traverse left child If any ray intersects the right child AABB: Traverse right child

INFOGR Lecture 11 Acceleration 38 Fast Traversal Ray Packet Traversal Quickly determining if any ray intersects a node: Test the first one. If it intersects, we re done. Else: Test if the AABB is outside the frustum encapsulating the packet. If it misses, we re done. Else: Brute force test all rays. The first one that hits the AABB will be the ray we check first while processing the child nodes.

INFOGR Lecture 11 Acceleration 39 Fast Traversal Ray Packet Traversal Efficiency Using the packet traversal approach, we can very efficiently traverse large packets of rays that travel roughly in the same direction. For primary rays, this can be 32x faster than single ray traversal. Note that this requires the rays in the packet to traverse a similar set of BVH nodes. The ray packet must be coherent (as opposed to divergent). Ray coherence can be expressed as the extend to which rays in a packet travel the same nodes, or: coherence = #rays in packet average #rays intersecting a node Combined with an efficient BVH, we now have the performance needed for real-time ray tracing.

Today s Agenda: High-speed Ray Tracing Acceleration Structures The Bounding Volume Hierarchy BVH Construction BVH Traversal Optimizing Construction High-speed Traversal

INFOGR Computer Graphics J. Bikker - April-July 2015 - Lecture 9: Ground Truth END of Acceleration next lecture: Shading Models