Bounding Volume Hierarchies. CS 6965 Fall 2011

Similar documents
Acceleration Structures. CS 6965 Fall 2011

Acceleration Data Structures

Intersection Acceleration

Spatial Data Structures

Spatial Data Structures

Spatial Data Structures

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

Spatial Data Structures

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

Spatial Data Structures

To Shading and Beyond. CS 6965 Fall 2011

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

Ray Tracing Acceleration Data Structures

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

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

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

Ray Tracing Acceleration. CS 4620 Lecture 22

Accelerated Raytracing

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

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

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

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

improving raytracing speed

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

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

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

Ray Tracing Acceleration. CS 4620 Lecture 20

Ray Intersection Acceleration

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

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

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

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

Lecture 2 - Acceleration Structures

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

Accelerating Ray-Tracing

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

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

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

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

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

Accelerating Ray-Scene Intersection Calculations

CS535 Fall Department of Computer Science Purdue University

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

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

Accelerating Ray Tracing

Computer Graphics. Bing-Yu Chen National Taiwan University

Ray Intersection Acceleration

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

Hidden Surface Elimination: BSP trees

Recall: Inside Triangle Test

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

Advanced Ray Tracing

Bounding Volume Hierarchies

11 - Spatial Data Structures

More Hidden Surface Removal

CS 6620 Shading. Steve Parker Peter Shirley

A Model to Evaluate Ray Tracing Hierarchies

Acceleration Data Structures for Ray Tracing

Advanced 3D-Data Structures

Physically Based Rendering ( ) Intersection Acceleration

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

CS 431/636 Advanced Rendering Techniques

Geometric Structures 2. Quadtree, k-d stromy

Culling. Computer Graphics CSE 167 Lecture 12

Lecture 11: Ray tracing (cont.)

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

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

Computer Graphics Ray Casting. Matthias Teschner

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

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

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

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

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

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

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Computer Graphics II

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

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

Collision and Proximity Queries

9. Visible-Surface Detection Methods

Ray Casting. COS 426, Spring 2015 Princeton University

COMPUTER GRAPHICS COURSE. Ray Tracing

kd-trees Idea: Each level of the tree compares against 1 dimension. Let s us have only two children at each node (instead of 2 d )

VIII. Visibility algorithms (II)

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

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

kd-trees for Volume Ray-Casting

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

Geometry proxies (in 2D): a Convex Polygon

Lecture 4 - Real-time Ray Tracing

Speeding up your game

Collision Detection with Bounding Volume Hierarchies

Spatial Data Structures and Acceleration Algorithms

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

קורס גרפיקה ממוחשבת 2010/2009 סמסטר א' Rendering 1 חלק מהשקפים מעובדים משקפים של פרדו דוראנד, טומס פנקהאוסר ודניאל כהן-אור

Sung-Eui Yoon ( 윤성의 )

Dynamic Bounding Volume Hierarchies. Erin Catto, Blizzard Entertainment

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

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

CEng 477 Introduction to Computer Graphics Fall 2007

Transcription:

Bounding Volume Hierarchies

2

Heightfield 3

C++ Operator? #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } stackoverflow.com/questions/1642028/what-is-the-name-of-this-operator 4

C++ Operator? That's not an operator -->. That's two separate operators, -- and >. Your post is decrementing x and then comparing x and 0 with the > operator To better understand, the statement could be as follows: while( (x--) > 0 ) 5

Program 2 6

Backwards Lighting 7

Light Direction Compute hit position (P = O + tv ) Call primitive to get normal (N ) (normalized) costheta = N V if (costheta < 0) normal =-normal Color light = scene.ambient*ka foreach light source get C L and L dist= L L, L n = L cosphi = N L n if(cosphi > 0) if(!intersect with 0 < t < dist) light += C L *(Kd * cosphi) result=light*surface color 8 costheta > 0 Means N and V are on opposite sides Should flip the normal costheta < 0 Means N and V are on the same side Keep the normal

Library Calls Show up as something like this: ERROR: undefined symbol: dso_handle failed to add instruction: ORI line 54 assembler returned an error, exiting This one was fixed by removing global variables Use #define or keep things locally 9

We do have this one! Change this line: To this line: Memset @${LINKERDIR}/ln.py rt.s > ${TRAXOUTPUT} @${LINKERDIR}/ln.py rt.s ${LIBDIR}/memset.s > ${TRAXOUTPUT} 10

Inheritance _ZTV8gpSphere: #.long 0 #.long _ZTI8gpSphere #.long _ZNK8gpSphere17intersectDetailedERK12RayPrimitiveR18IntersectionRecord #.long _ZNK8gpSphere14intersectQuickERK12RayPrimitive #.size _ZTV8gpSphere, 16 We can t handle these in simhwrt yet 11

Calling Convention 12

Calling Convention 13

Common Problems void draw_line(const int& framebuffer, const int& width, const Vector& V1, const Vector& V2, const int& max_pixel) { int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; int dx = x0 - x1; if (dx < 0) dx = -dx; int dy = y0 - y1 if (dy < 0) dy = -dy; int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; int e2; while (x0!= x1 y0!= y1) { 14

Common Problems int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; trax_printi(x0); trax_printi(x1); trax_printi(y0); trax_printi(y1); int dx = x0 - x1; if (dx < 0) dx = -dx; int dy = y0 - y1 if (dy < 0) dy = -dy; int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; int e2; trax_printi(err); 15

Common Problems int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; trax_printi(x0); trax_printi(x1); trax_printi(y0); trax_printi(y1); int dx = x0 - x1; if (dx < 0) dx = -dx; int dy = y0 - y1 if (dy < 0) dy = -dy; int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; trax_printi(dx); trax_printi(dy); int err = dx - dy; int e2; 16

Common Problems int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; trax_printi(x0); trax_printi(x1); trax_printi(y0); trax_printi(y1); int dx = x0 - x1; if (dx < 0) dx = -dx; int dy = y0 - y1 if (dy < 0) dy = -dy; trax_printi(dx); trax_printi(dy); int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; int e2; 17

Common Problems trax_printi(x0); trax_printi(x1); trax_printi(y0); trax_printi(y1); int dx = x0 - x1; if (dx < 0) dx = -dx; // dx = abs(dx) int dy = y0 - y1 if (dy < 0) dy = -dy; // dy = abs(dy) trax_printi(dx); trax_printi(dy); 18

Common Problems trax_printi(x0); trax_printi(x1); trax_printi(y0); trax_printi(y1); int dx = x0 - x1; if (dx < 0) dx = -dx; // dx = abs(dx) int dy = y0 - y1 if (dy < 0) dy = -dy; // dy = abs(dy) trax_printi(dx); trax_printi(dy); // Write it a different way int dx = x0 > x1? x0 - x1 : x1 - x0; int dy = y0 > y1? y0 - y1 : y1 - y0; 19

Common Problems Before void draw_line(const int& framebuffer, const int& width, const Vector& V1, const Vector& V2, const int& max_pixel) { int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; int dx = x0 - x1; if (dx < 0) dx = -dx; int dy = y0 - y1 if (dy < 0) dy = -dy; int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; int e2; while (x0!= x1 y0!= y1) { 20 After void draw_line(const int& framebuffer, const int& width, const Vector& V1, const Vector& V2, const int& max_pixel) { int x0 = V1[0]; int x1 = V2[0]; int y0 = V1[1]; int y1 = V2[1]; int dx = x0 > x1? x0 - x1 : x1 - x0; int dy = y0 > y1? y0 - y1 : y1 - y0; int sx, sy; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; int err = dx - dy; int e2; while (x0!= x1 y0!= y1) {

Box: easy Bounding boxes bounds = Min(p1, p2), Max(p1, p2) P2 Sphere: bounds = C-Vector(radius, radius,radius) C+Vector(radius, radius, radius) P1 C 21

Bounding Boxes Triangle: bounds = Min(p1,p2,p3), Max(p1,p2,p3) P1 Plane infinite bounds P2 You may want to consider removing planes from your renderer at this point Or keep them outside of your accel structures P3 22

Bounding boxes Disc/Ring: C x ± rad N 2 2 y + N z N = 1 Similar for y/z Group: Union of object bounding boxes min of mins max of maxs 23

Uses for bounding boxes Quick reject for expensive primitives To fill in grid cells Directly in Bounding Volume Hierarchy or similar 24

Bounding Volume Hierarchy Observe that intersection is like a search We know that searching is O(n) for unsorted lists but O(log n) for sorted lists How do we sort objects from all directions simultaneously? 25

Bounding volume hierarchy Organize objects into a tree Group objects in the tree based on spatial relationships Each node in the tree contains a bounding box of all the objects below it 26

BVH traversal At each level of the tree, intersect the ray with the bounding box miss: ray misses the entire subtree hit: recurse to both children 27

BVH traversal At each level of the tree, intersect the ray with the bounding box miss: ray misses the entire subtree hit: recurse to both children 28

BVH traversal At each level of the tree, intersect the ray with the bounding box miss: ray misses the entire subtree hit: recurse to both children 29

BVH traversal At each level of the tree, intersect the ray with the bounding box miss: ray misses the entire subtree hit: recurse to both children 30

BVH optimizations Stop if the current T value is closer than the BVH node 31

BVH optimizations Stop if the current T value is closer than the BVH node Traverse down side of tree that is closer to origin of the ray first 32

BVH optimizations Stop if the current T value is closer than the BVH node Traverse down side of tree that is closer to origin of the ray first Three or more way split 33

Building a BVH Determining optimal BVH structure is NP-hard problem Heuristic approaches: Cost models (minimize volume or surface area) Spatial models Top down Bottom up Categories of approaches: 34 okay bad okay

Median cut BVH Top down approach: construction Sort objects by position on axis cycle through x,y,z use center of bounding box Insert tree node with half of objects on left and half on right 35

Weghorst BVH construction Bottom up construction Add objects one at a time to tree Insert to subtree that would cause smallest increase to area 36

Weghorst BVH construction Bottom up construction Add objects one at a time to tree Insert to subtree that would cause smallest increase to area 37

Weghorst BVH construction Bottom up construction Add objects one at a time to tree Insert to subtree that would cause smallest increase to area 38

Weghorst BVH construction Bottom up construction Add objects one at a time to tree Insert to subtree that would cause smallest increase to area 39

k-d tree Recursively divide space in half Alternate coordinate axes Cycle through axes or store axis split in each node What do you do with objects split by the plane? Hard part: where do you split in each dimension? 40

BSP tree Like a k-d tree where splitting planes can be arbitrarily located Hard part: where do you split in each dimension? Harder part: how do you orient each plane? More storage/computation, tighter bounds 41

BSP/k-d tree tradeoffs Build is NP-hard problem Traversal is quick Heuristic approaches are always used Storage can be lower than BVH or grid 42

K-d traversal Keep track of intervals on ray: min: 0 max: Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 43

K-d traversal Keep track of intervals on ray: Compute t of split plane If t < min: goto far child If t > max: goto near child Min: 0 Max: Otherwise: goto both children with updated intervals 44

K-d traversal Keep track of intervals on ray: 1 2 Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 45 Min: 0 Max: Split: 1.0 Stack: 1 New min: 0 New max: 1.0

K-d traversal Keep track of intervals on ray: Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 46 3 4 Min: 0 Max: 1.0 Split: 1.3 Stack: 1 New min: 0 New max: 1.0

K-d traversal Keep track of intervals on ray: 5 6 Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 47 Min: 0 Max: 1.0 Split: 0.4 Stack: 1 5 New min: 0 New max: 0.4

K-d traversal Keep track of intervals on ray: 7 8 Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 48 Min: 0.4 Max: 1.0 Split: 0.7 Stack: 1 8 New min: 0.4 New max: 0.6

K-d traversal Keep track of intervals on ray: 7 8 Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 49 Min: 0.7 Max: 1.0 Split: Stack: 1 New min: 0.4 New max: 0.6

K-d traversal 9 10 Keep track of intervals on ray: Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 50 Min: 1.0 Max: Split: 1.5 Stack: 10 New min: 1.0 New max: 1.5

K-d traversal Keep track of intervals on ray: 11 12 Compute t of split plane If t < min: goto far child If t > max: goto near child Otherwise: goto both children with updated intervals 51 Min: 1.0 Max: 1.5 Split: 1.4 Stack: 10 11 New min: 1.0 New max: 1.4

K-d tree build Optimal solution is NP-hard Cost model based (better) Cost of traversal Cost of intersection Probability of hit Spatial median split (a little like octree) Object median split (makes balanced trees) 52

Havran 01: K-d tree build Start with bounding box of scene Select split plane along each axis Recurse Start with spatial median Move toward bounding box of child nodes Stop if node contains 2-3 objects Stop if depth > max (20-30) Backtrack Combine children with identical content 53

Acceleration Structure Summary Most common: Grid, Hierarchical Grid, k-d tree, BVH Grid based: P time deterministic build Grid resolution tradeoff Tree based: NP hard build Heuristic approaches 54

Update SimHWRT svn up make./update.sh This one will take a while 55