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

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

Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

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

Bounding Volume Hierarchies

Collision and Proximity Queries

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

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

Collision Detection with Bounding Volume Hierarchies

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

Intersection Acceleration

Collision Detection. Pu Jiantao.

Lesson 05. Mid Phase. Collision Detection

Real-Time Collision Detection for Dynamic Virtual Environments

Spatial Data Structures

Spatial Data Structures

Computer Graphics Ray Casting. Matthias Teschner

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

Acceleration Data Structures

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

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

Ray Tracing Acceleration. CS 4620 Lecture 20

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

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

Collision Detection. Jane Li Assistant Professor Mechanical Engineering & Robotics Engineering

improving raytracing speed

Ray Tracing Acceleration. CS 4620 Lecture 22

Overview. Collision Detection. A Simple Collision Detection Algorithm. Collision Detection in a Dynamic Environment. Query Types.

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

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

Spatial Data Structures

11 - Spatial Data Structures

Spatial Data Structures

Dynamic Collision Detection

Spatial Data Structures

Geometry proxies (in 2D): a Convex Polygon

References. Additional lecture notes for 2/18/02.

Overview. Collision detection. Collision detection. Brute force collision detection. Brute force collision detection. Motivation

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

Collision detection. Piotr Fulma«ski. 1 grudnia

Spatial Data Structures and Acceleration Algorithms

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

Computer Graphics. - Spatial Index Structures - Philipp Slusallek

Efficient Collision Detection Using a Dual Bounding Volume Hierarchy

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

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

CAB: Fast Update of OBB Trees for Collision Detection between Articulated Bodies

Collision Detection. Motivation - Dynamic Simulation ETH Zurich. Motivation - Path Planning ETH Zurich. Motivation - Biomedical Simulation ETH Zurich

Collision detection. Piotr Fulma«ski. 19 pa¹dziernika Wydziaª Matematyki i Informatyki, Uniwersytet Šódzki, Polska

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

CS 431/636 Advanced Rendering Techniques

Ray Tracing Acceleration Data Structures

Recall: Inside Triangle Test

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

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

Collision Detection based on Spatial Partitioning

Speeding up your game

Bounding Volume Hierarchies. CS 6965 Fall 2011

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

Advanced Ray Tracing

Spatial Data Structures and Acceleration Algorithms

Technical Section. Tribox bounds for three-dimensional objects

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

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

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

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

Acceleration Structures. CS 6965 Fall 2011

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

Universiteit Leiden Computer Science

Collision Detection of Triangle Meshes using GPU

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

Accelerated Raytracing

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

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

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

CMSC 425: Lecture 10 Geometric Data Structures for Games: Index Structures Tuesday, Feb 26, 2013

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

Speeding Up Ray Tracing. Optimisations. Ray Tracing Acceleration

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

Jane Li. Assistant Professor Mechanical Engineering Department, Robotic Engineering Program Worcester Polytechnic Institute

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

Virtual Reality in Assembly Simulation

INFOMAGR Advanced Graphics. Jacco Bikker - February April Welcome!

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

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

Accelerating Ray-Tracing

Accelerating Ray Tracing

Lecture 4 - Real-time Ray Tracing

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

Virtual Reality & Physically-Based Simulation

CS535 Fall Department of Computer Science Purdue University

Collision handling: detection and response

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

Efficient Collision Detection Using Bounding Volume Hierarchies of k-dops Λ

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

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

Improved Collision Detection in StarLogo Nova S.B., C.S. MIT, S.B., Math MIT, 2014

Lecture 11: Ray tracing (cont.)

CSE 167: Introduction to Computer Graphics Lecture #18: More Effects. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CS 4649/7649 Robot Intelligence: Planning

Transcription:

Part 7: Collision Detection Virtuelle Realität Wintersemester 2007/08 Prof. Bernhard Jung Overview Bounding Volumes Separating Axis Theorem Using Bounding Volume Hierarchies Efficient Collision Detection for Several Hundreds of Objects Further Reading Akenine-Möller & Haines. Real-Time Rendering. 2nd edition. AK Peters. 2002. Chapters 13 + 14 Free collision detection software http://www.cs.unc.edu/~geom/collide/index.shtml http://www.cs.unc.edu/~geom/v_collide/ 1

Collisions: In General Without collision detection (CD), it is practically impossible to e.g., games, movie production tools Three major parts Collision detection: do objects collide? Collision determination: where? Collision response This lecture: collision detection + determination Collision response involves physically-based animation Use rays for simple applications Use Bounding Volume Hierarchies (BVHs) to test two complex objects against each other But what if several hundreds of objects? Typical Bounding Volumes Sphere Box Axis-aligned Bounding Box (AABB) Oriented (OBB) k-dop "discrete oriented polytype" generalizes AABB (in 3D): AABB = 6-DOP Different tightness and different costs for intersection testing 2

k-dops source: Unreal developer network http://udn.epicgames.com/two/collisiontutorial Simple Tests: Ray/Box Intersection Boxes and spheres often used as bounding volumes also: "hit-boxes" in games hit-box (wikipedia) A slab is the volume between two parallel planes: A 3D box is the logical intersection of three slabs (2 in 2D): BOX 3

Simple Tests: Ray/Box Intersection (2) Intersect the 2 planes of each slab with the ray Ray: r(t)=o+td (o origin, d direction) max t y min t x min t y max t x Keep max of t min and min of t max If t min < t max then we got an intersection Special case when ray parallel to slab Simple Tests: Sphere-Sphere trivial: r2 if distance of centers > sum of radii then disjoint r1 c1 d c2 4

Simple Tests: AABB-AABB trivial: project boxes to axes if no overlap in any of {x,y,z}-axes then disjoint ("separating axis") Simple Tests: k-dop k-dop generalizes AABB-AABB intersection test project bounding volumes to k/2 axes disjoint if not overlapping on at least one ("separating") axis for moderate values of k, e.g. k=18, an order of magnitude faster than OBB-OBB intersection testing min min min min 5

Separating Axis Theorem (SAT) Summary: Given two convex shapes, if we can find an axis along which the projection of the two shapes does not overlap, then the shapes don't overlap Concretely: Two convex polyhedrons, A and B, are disjoint if any of the following axes separate the objects: An axis orthogonal to a face of A An axis orthogonal to a face of B An axis formed from the cross product of one edge from each of A and B axis faces A and B overlap on this axis SAT example: Triangle-AABB (2D case) Box is axis-aligned test x, y axes Triangle: two edges parallel to x, y test axis perpendicular to the one non-aligned edge http://www.harveycartel.org/ 6

SAT example: Triangle-Box Box is axis-aligned 1) test the axes that are orthogonal to the faces of the box That is, x, y, and z here: no overlap in x disjoint Triangle-Box with SAT (2) Assume that they overlapped on x, y, z Must continue testing 2) Axis orthogonal to face of triangle axis Triangle seen from side here: overlap in selected axis must continue testing 7

Triangle-Box with SAT (3) If still no separating axis has been found 3) Test axis: t=e box x e triangle Example: x-axis from box: e box =(1,0,0) e triangle =v 1 -v 0 Test all such combinations If there is at least one separating axis, then the objects do not collide Else they do overlap OBB OBB with SAT Project to 15 potential separating axes: 3 from object-1 x 1, y 1, z 1 3 from object-2 x 2, y 2, z 2 9 from combinations of edges from two objects x 1 x 2 x 1 y 2 x 1 z 2 y 1 x 2 can stop testing when first separating axis is found potential separating axis 8

Rules of Thumb for Intersection Testing Acceptance and rejection test Try them early on to make a fast exit Postpone expensive calculations if possible Use dimension reduction E.g. 3 one-dimensional tests instead of one complex 3D test, or 2D instead of 3D Share computations between objects if possible Do timing comparisons Dynamic Separating Axis Theorem (advanced topic) SAT: tests one axis at a time for overlap Same with DSAT, but: Need to adjust the projection on the axis so that the interval moves on the axis as well Need to test same axes as with SAT Same criteria for overlap/disjoint: If no overlap on axis => disjoint If overlap on all axes => objects overlap 9

For many, many objects Test BV (bounding volume) of each object against BV of other object Works for small sets, but not very clever Reason assume moving n objects number of tests in naïve approach: if m static objects, then: n nm + 2 n = n( n 1) / 2 = O( n 2 2 ) there are smarter ways, e.g. sweep-and-prune (last part of lecture) Collision detection with rays Imagine a car is driving on a road sloping upwards Could test all triangles of all wheels against road geometry For certain applications, we can approximate, and still get a good result Idea: approximate a complex object with a set of rays 10

CD with rays, cont d Put a ray at each wheel Compute the closest intersection distance, t, between ray and road geometry If t=0, then car is on the road If t>0, then car is flying above road If t<0, then car is plowing deep in the road Use values of t to compute a simple collision response Another simplification Sometimes 3D can be turned into 2D operations Example: maze A human walking in maze, can be approximated by a circle Test circle against lines of maze Or even better, move walls outwards with circle radius test center of circle against moved walls 11

A collision detection system for accurate detection and for many objects covered here: pruning and exact CD Simulation is how objects move General Hierarchical Collision Detection Model is represented as a hierarchy of some kind of bounding volumes A hierarchy that is commonly used is a data structure called a k-ary tree typical BVHs: binary trees At each internal node, there is a BV that encloses all of its children in its volume At each leaf there are one or more primitives (e.g. triangles) 12

Hierarchy Building Three ways: Bottom-up by combining a number of primitives and finding a BV for them Top-down by finding a BV for all primitives of the model, then divide-and-conquer is applied Incremental tree-insertion starts with an empty tree and then all other primitives and their BVs are added one at a time to this tree Insertion point should be selected so that the total tree volume increase is minimized OBBTree Hierarchy Building OBBTree: binary tree with each internal node holding an OBB and each external node holding only one triangle top-down hierarchy building approach is divided into finding a tight-fitting OBB and splitting this along one axis of the OBB details see (Akenine-Möller&Haines, 2002) 13

Pseudo code for BVH against BVH Pseudocode deals with 4 cases: 1) Leaf against leaf node 2) Internal node against internal node 3) Internal against leaf 4) Leaf against internal Comments on pseudocode The code terminates when it finds the first triangle pair that collided collision detection Simple to modify code to continue traversal and put each pair in a list collision determination Reasonably simple to include rotations for objects as well Note that if we use AABB for both BVHs, then the AABB-AABB test becomes a AABB-OBB test 14

Tradeoffs Cost parameters for collision detection: Choice of BV Sphere, AABB, OBB, k-dop In general, the tighter BV, the slower test Less tight BV, gives more triangle-triangle tests in the end Model rotation may requires updates of AABB, k-dop not: OBB, sphere Cost function: k-dop update due to rotation Multiple Objects CD: Pruning Why needed? Consider several hundreds of rocks tumbling down a slope Include a first rough but simple test on whether objects can potentially collide This system is often called First-Level CD We execute this system because we want to execute the 2 nd system less frequently Assume high frame-to-frame coherency Means that object is close to where it was previous frame Reasonable 15

Sweep-and-prune algorithm [by Ming Lin] Assume objects may translate and rotate Then we can find a minimal cube (AABB), which is guaranteed to contain object for all rotations alternatively, may use bounding spheres Do collision overlap three times One for x, y, and z-axes Let s concentrate on one axis at a time Each cube on this axis is an interval, from s i to e i, where i is cube number Sweep-and-prune algorithm Sort all s i and e i into a list Traverse list from start to end When an s is encountered, mark corresponding interval as active in an active_interval_list When an e is encountered, delete the interval in active_interval_list All intervals in active_interval_ list are overlapping! 16

Sweep-and-prune algorithm Sorting is expensive (on unsorted lists): O(n log n) But, exploit frame-to-frame coherency! a.k.a. "temporal" coherence the list is not expected to change much Therefore, re-sort with insertion-sort (for nearly sorted lists O(n) ) Expected time complexity for sorting: O(n) Frame t Frame t+1 (object 2 moved) Sweep-and-prune algorithm Keep a Boolean for each pair of intervals If all Booleans for all three axes are true objects overlap Expected time complexity of complete sweep-and-prune algorithm: O(n+k) where k is the number of pairwise overlaps Frame t Frame t+1 (object 2 moved) 17

Collision Detection Conclusions Very important part of games! Many different algorithms to choose from Trend: hardware-acceleration (GPU) e.g. CULLIDE, UNC, 2003, http://gamma.cs.unc.edu/cullide/ 18