Collision Detection on the GPU Mike Donovan CIS 665 Summer 2009.

Slides:



Advertisements
Similar presentations
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL CULLIDE: Interactive Collision Detection Between Complex Models in Large Environments using Graphics Hardware.
Advertisements

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
Sven Woop Computer Graphics Lab Saarland University
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Inpainting Assigment – Tips and Hints Outline how to design a good test plan selection of dimensions to test along selection of values for each dimension.
Graphics Pipeline.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development 11/28/
Computer graphics & visualization Collisions. computer graphics & visualization Simulation and Animation – SS07 Jens Krüger – Computer Graphics and Visualization.
2.1. C OLLISION D ETECTION Overview. Collision detection is used within many types of application, e.g. from robotics, through engineering simulations,
Two Methods for Fast Ray-Cast Ambient Occlusion Samuli Laine and Tero Karras NVIDIA Research.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Experiences with Streaming Construction of SAH KD Trees Stefan Popov, Johannes Günther, Hans-Peter Seidel, Philipp Slusallek.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
Collision Detection CSE 191A: Seminar on Video Game Programming Lecture 3: Collision Detection UCSD, Spring, 2003 Instructor: Steve Rotenberg.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
Adapted from: CULLIDE: Interactive Collision Detection Between Complex Models in Large Environments using Graphics Hardware Naga K. Govindaraju, Stephane.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Continuous Collision Detection David Knott COMP 259 class presentation.
Approximate Soft Shadows on Arbitrary Surfaces using Penumbra Wedges Tomas Akenine-Möller Ulf Assarsson Department of Computer Engineering, Chalmers University.
OBBTree: A Hierarchical Structure for Rapid Interference Detection Gottschalk, M. C. Lin and D. ManochaM. C. LinD. Manocha Department of Computer Science,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Collision Detection for Deformable Objects Xin Huang 16/10/2007.
Apex Point Map for Constant-Time Bounding Plane Approximation Samuli Laine Tero Karras NVIDIA.
Ray Space Factorization for From-Region Visibility Authors: Tommer Leyvand, Olga Sorkine, Daniel Cohen-Or Presenter: Alexandre Mattos.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Geometric Computations on GPU: Proximity Queries Avneesh Sud &Dinesh Manocha.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Computer Graphics Shadows
Computer graphics & visualization Collision Detection – Narrow Phase.
Computer Graphics Mirror and Shadows
Shadow Algorithms Ikrima Elhassan.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Visibility Queries Using Graphics Hardware Presented by Jinzhu Gao.
CSE 381 – Advanced Game Programming Quickhull and GJK.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
On a Few Ray Tracing like Algorithms and Structures. -Ravi Prakash Kammaje -Swansea University.
GPU Broad Phase Collision Detection GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from GPU Gems III.
Quick-CULLIDE: Efficient Inter- and Intra- Object Collision Culling using Graphics Hardware Naga K. Govindaraju, Ming C. Lin, Dinesh Manocha University.
12/4/2001CS 638, Fall 2001 Today Managing large numbers of objects Some special cases.
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
Interactive Geometric Computations using Graphics Processors Naga K. Govindaraju UNC Chapel Hill.
Real-time Graphics for VR Chapter 23. What is it about? In this part of the course we will look at how to render images given the constrains of VR: –we.
1 KIPA Game Engine Seminars Jonathan Blow Ajou University December 6, 2002 Day 10.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
Fast BVH Construction on GPUs (Eurographics 2009) Park, Soonchan KAIST (Korea Advanced Institute of Science and Technology)
Binary Space Partitioning Trees Ray Casting Depth Buffering
Hidden Surface Removal
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
Hierarchical Penumbra Casting Samuli Laine Timo Aila Helsinki University of Technology Hybrid Graphics, Ltd.
11/20/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Collision Detection Overview Player-Environment handling.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
Image Processing A Study in Pixel Averaging Building a Resolution Pyramid With Parallel Computing Denise Runnels and Farnaz Zand.
Soft Shadow Volumes for Ray Tracing
CULLIDE: Interactive Collision Detection Between Complex Models in Large Environments using Graphics Hardware Presented by Marcus Parker By Naga K. Govindaraju,
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
Hierarchical Occlusion Map Zhang et al SIGGRAPH 98.
COMPUTER GRAPHICS CHAPTER 38 CS 482 – Fall 2017 GRAPHICS HARDWARE
Real-Time Soft Shadows with Adaptive Light Source Sampling
Real-Time Ray Tracing Stefan Popov.
Hybrid Ray Tracing of Massive Models
2.1. Collision Detection Overview.
Chapter 4.2 Collision Detection and Resolution
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Collision Detection.
Presentation transcript:

Collision Detection on the GPU Mike Donovan CIS 665 Summer 2009

Overview Quick Background CPU Methods CULLIDE RCULLIDE QCULLIDE CUDA Methods

Background Need to find collisions for lots of reasons  Physics engines  Seeing if a projectile hits an object  Ray casting  Game engines  Etc…

Background Broad phase:  Looks at entire scene  Looks at proxy geometry (bounding shapes)  Determines if two objects may intersect  Needs to be very fast

Background Narrow phase:  Looks at pairs of objects flagged by broad phase  Looks at the actual geometry of an object  Determines if objects are truly intersecting  Generally slower

Background Resolution  Compute forces according to the contact points returned from the narrow phase  Can be non trivial if there are multiple contact points  Returns resulting forces to be added to each body

CPU Methods Brute Force  Check every object against every other N(N-1)/2 tests O(N²) Sweep and Prune Average case: O(N log N) Worst case: O(N²) Spatial Subdivisions Average case: O(N log N) Worst case: O(N²)

Sweep and Prune Bounding volume is projected onto x, y, z axis Determine collision interval for each object [b i, e i ] Two objects who’s collision intervals do not overlap can not collide O1O1 O3O3 O2O2 Sorting Axis B1B3E1B2E3E2

Spatial Subdivisions Images from pg 699, 700 GPU Gems III O1O1 O2O2 O3O3 O4O Example

CULLIDE Came out of Dinesh’s group at UNC in 2003 Uses graphics hardware to do a broad- narrow phase hybrid No shader languages

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline Overview Pruning Algorithm Implementation and Results Conclusions and Future Work

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline Overview Pruning Algorithm Implementation and Results Conclusions and Future Work

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overview Potentially Colliding Set (PCS) computation Exact collision tests on the PCS

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Algorithm Object Level Pruning Sub-object Level Pruning Exact Tests GPU based PCS computation Using CPU

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Potentially Colliding Set (PCS) PCS

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Potentially Colliding Set (PCS) PCS

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Outline Problem Overview Overview Pruning Algorithm Implementation and Results Conclusions and Future Work

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Algorithm Object Level Pruning Sub-object Level Pruning Exact Tests

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Visibility Computations Lemma 1: An object O does not collide with a set of objects S if O is fully visible with respect to S Utilize visibility for PCS computation

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL set S Collision Detection using Visibility Computations Fully Visible Object O

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Pruning Lemma 2: Given n objects O 1,O 2,…,O n, an object O i does not belong to PCS if it does not collide with O 1,…,O i-1,O i+1,…,O n Prune objects that do not collide

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Pruning O 1 O 2 … O i-1 O i O i+1 … O n-1 O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Pruning O 1 O 2 … O i-1 O i

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Pruning O i O i+1 … O n-1 O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation Each object tested against all objects but itself Naive algorithm is O(n 2 ) Linear time algorithm Uses two pass rendering approach Conservative solution

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: First Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Render

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: First Pass Fully Visible? Render O1O1

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: First Pass Fully Visible? Render O 1 O 2 Yes. Does not collide with O 1

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL O 1 O 2 … O i-1 O i PCS Computation: First Pass Fully Visible? Render Yes. Does not collide with O 1,O 2,…,O i-1

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: First Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Render Fully Visible?

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: Second Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Render O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: Second Pass Render Fully Visible? O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: Second Pass Render Fully Visible? O n-1 O n Yes. Does not collide with O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: Second Pass Render Fully Visible? O i O i+1 … O n-1 O n Yes. Does not collide with O i+1,…,O n-1,O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation: Second Pass Render Fully Visible? O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Yes. Does not collide with O 1,…,O n-1,O n

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Fully Visible

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS Computation O 1 O 2 O 3 … O i-1 O i O i+1 … O n-2 O n-1 O n O 1 O 3 … O i-1 O i+1 … O n-1

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Example O1O1 O2O2 O3O3 O4O4 Scene with 4 objects O 1 and O 2 collide O 3, O 4 do not collide Initial PCS = { O 1,O 2,O 3, O 4 }

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL O3O3 O1O1 First Pass O2O2 Order of rendering: O 1 O 4 O3O3 Fully Visible O1O1 O4O4 O4O4 Not Fully Visible

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Second Pass O1O1 O3O3 O2O2 O2O2 Fully Visible Order of rendering: O 4 O 1 O4O4 O4O4 Fully Visible O3O3 Not Fully Visible

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL After two passes O1O1 O2O2 O3O3 O4O4 Fully Visible

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Potential Colliding Set O1O1 O2O2 PCS ={O 1,O 2 }

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Algorithm Object Level Pruning Sub-object Level Pruning Exact Tests

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization Each object is composed of sub- objects We are given n objects O 1,…,O n Compute sub-objects of an object O i that overlap with sub-objects of other objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization Our solution Test if each sub-object of O i overlaps with sub-objects of O 1,..O i-1 Test if each sub-object of O i overlaps with sub-objects of O i+1,...,O n Linear time algorithm Extend the two pass approach

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization O 1 O 2 … O i-1 O i O i+1 … O n-1 O n PCS Sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 O i Rendered sub-objects Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 Fully Visible? Rendered sub-objects Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 Fully Visible? Rendered sub-objects Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass Rendered sub-objects O 1 O 2 … O i-1 Fully Visible? Yes. Does not collides with sub-objects of O 1,O 2,…,O i-1 Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass Rendered sub-objects O 1 O 2 … O i-1 Fully Visible? Avoids self-collisions! Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 O i Rendered sub-objects Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: First Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Rendered sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization: Second Pass O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Render sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Overlap Localization O 1 O 2 … O i-1 O i O i+1 … O n-1 O n Sub-objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Potential Colliding Set O1O1 O2O2 PCS = {O 1,O 2 }

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL O1O1 Sub-objects O2O2 PCS = sub-objects of {O 1,O 2 }

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL First Pass Rendering order: Sub-objects of O 1 O 2

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible Not Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible First Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Second Pass Rendering order: Sub-objects of O 2 O 1

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible Second Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible Second Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible Second Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Not Fully Visible Fully Visible Second Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible Second Pass

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Fully Visible After two passes

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL PCS

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Algorithm Object Level Pruning Sub-object level Pruning Exact Tests Exact Overlap tests using CPU

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Visibility Queries We require a query Tests if a primitive is fully visible or not Current hardware supports occlusion queries Test if a primitive is visible or not Our solution Change the sign of depth function

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Visibility Queries Depth function GEQUALLESS All fragments Pass FailPass Fail PassFailPassFail Query not supported Occlusion query Examples - HP_Occlusion_test, NV_occlusion_query

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Bandwidth Analysis Read back only integer identifiers Independent of screen resolution

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Optimizations First use AABBs as object bounding volume Use orthographic views for pruning Prune using original objects

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Advantages No coherence No assumptions on motion of objects Works on generic models A fast pruning algorithm No frame-buffer readbacks

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Limitations No distance or penetration depth information Resolution issues No self-collisions Culling performance varies with relative configurations

Assumptions Makes assumptions that their algorithm will get faster as hardware improves. Luckily they were right

RCULLIDE An improvement on CULLIDE in 2004 Resolves issue of screen resolution precision

Overview A main issue with CULLIDE was the fact that it wasn’t reliable Collisions could easily be missed due to screen resolution

Overview 3 kinds of error associated with visibility based overlap  Perspective error Strange shapes from the transformation  Sampling error Pixel resolution isn’t high enough  Depth buffer precision error If distance between primitives is less than the depth buffer resolution, we will get incorrect results from our visibility query

Reliable Queries The three errors cause the following:  A fragment to not be rasterized  A fragment is generated but not sampled where interference occurs  A fragment is generated and sampled where the interference occurs but the precision of the buffer is not sufficient

Reliable Queries Use “fat” triangles  Generate 2 fragments for each pixel touched by a triangle (no matter how little it is in the pixel)  For each pixel touched by the triangle, the depth of the 2 fragments must bound the depth of all points of the triangle in that pixel Causes method to become more conservative (read: slower) but much more accurate

Minkowski Sum Scary name…easy math A = { (1, 0), (0, 1), (0, −1)} B = { (0, 0), (1, 1), (1, −1)} A + B = { (1, 0), (2, 1), (2, −1), (0, 1), (1, 2), (1, 0), (0, −1), (1, 0), (1, −2)}

Reliable Queries In practice, we use the Minkowski sum of a bounding cube B and the triangle T B = max(2dx, 2dy, 2dz) where dx,y,z are pixel dimensions If uniform supersampling is known to occur on the card, we can reduce the size of B  We need B to cover at least 1 sampling point for the triangle it bounds

Reliable Queries Cubes only work for z-axis projections so in practice use a bounding sphere of radius sqrt(3)p/2

Bounding Offset So far we’ve just dealt with single triangles but we need whole objects This is done using a Union of Object- oriented Bounding Boxes(UOBB)

Algorithm

Improvement over CULLIDE

Performance Still runs faster than CPU implementations 3x slower than CULLIDE due to bounding box rasterization vs triangle rasterization

QCULLIDE Extends CULLIDE to handle self collisions in complex meshes All running in real time

Self Collision Culling Note that only intersecting triangles that don’t share a vertex or edge are considered colliding

Self Collision Culling Algorithm  Include all potentially colliding primitives and PCS where each primitive is a triangle  Perform the visibility test to see if a triangle is penetrating any other  If completely visible, the object is not colliding

Q-CULLIDE Sets  BFV – Objects fully visible in both passes and are pruned from the PCS  FFV – Fully visible in only the first pass  SFV – Fully visible in only the second pass  NFV – Not fully visible in both passes

Q-CULLIDE Properties of sets  FFV and SFV are collision free No object in FFV collides with any other in FFV…same for SFV  If an object is in FFV and is fully visible in the 2 nd pass of the algorithm, we can prune it and vice versa

Algorithm

What’s Happening

Improvement Over CULLIDE

Improvements Over CULLIDE Sends an order of magnitude less collisions to the CPU than CULLIDE

Spatial Subdivision  Partition space into uniform grid  Grid cell is at least as large as largest object  Each cell contains list of each object whose centroid is in the cell  Collision tests are performed between objects who are in same cell or adjacent cells Images from pg 699, 700 GPU Gems III O1O1 O2O2 O3O3 O4O4 Implementation: 1.Create list of object IDs along with hashing of cell IDs in which they reside 2.Sort list by cell ID 3.Traverse swaths of identical cell IDs 4.Perform collision tests on all objects that share same cell ID Example

Parallel Spatial Subdivision  Complications: 1. Single object can be involved in multiple collision tests 2. Need to prevent multiple threads updating the state of an object at the same time Ways to solve this?

Guaranteed Individual Collision Tests  Prove: No two cells updated in parallel may contain the same object that is being updated Constraints 1. Each cell is as large as the bounding volume of the largest object 2. Each cell processed in parallel must be separated by each other cell by at least one intervening cell In 2d this takes _____ number of passes In 3d this takes _____ number of passes 4 8

Example of Parallel Spatial Subdivision O1O1 O2O2 O3O3 O4O O1O1 O2O2 O3O3 O4O

Avoiding Extra Collision Testing 1. Associate each object a set of control bits to test where its centroid resides 2. Scale the bounding sphere of each object by sqrt(2) to ensure the grid cell is at least 1.5 times larger than the largest object Case 1 Case 2

Implementing in CUDA  Store list of object IDs, cell IDs in device memory  Build the list of cell IDs from object’s bounding boxes  Sorting list from previous step  Build an index table to traverse the sorted list  Schedule pairs of objects for narrow phase collision detection

Initialization Cell ID Array OBJ 1 Cell ID 1 OBJ 1 Cell ID 2 OBJ 1 Cell ID 3 OBJ 1 Cell ID 4 OBJ 2 Cell ID 1 OBJ 2 Cell ID 2 OBJ 2 Cell ID 3 OBJ 2 Cell ID 4. Object ID Array OBJ 1 ID, Control Bits OBJ 2 ID, Control Bits.

Construct the Cell ID Array Host Cells (H – Cells) Contain the centroid of the object Phantom Cells (P-Cells) Overlap with bounding volume but do not contain the centroid H-Cell Hash = (pos.x / CELLSIZE) << XSHIFT) | (pos.y / CELLSIZE) << YSHIFT) | (pos.z / CELLSIZE) << ZSHIFT) P PP P HP P PP P-Cells – Test the 3 d -1 cells surrounding the H cell There can be as many as 2 d -1 P cells

Sorting the Cell ID Array  What we want: Sorted by Cell ID H cells of an ID occur before P cells of an ID  Starting with a partial sort H cells are before P cells, but array is not sorted by Cell ID  Solution: Radix Sort Radix Sort ensures identical cell IDs remain in the same order as before sorting.

Sorting Cell Array n n n n n Cell ID Array n n n n 111 n n Sorted Cell ID Array Invalid Cell Home Cell Phantom Cell Object ID Cell ID Legend

Spatial Subdivision Images from pg 699, 700 GPU Gems III O1O1 O2O2 O3O3 O4O Example 1.Assign to each cell the list of bounding volumes whose objects intersect with the cell 2.Perform Collision test only if both objects are in the cell and one has a centroid in the cell

Create the Collision Cell List  Scan sorted cell ID array for changes of cell ID Mark by end of the list of occupants of one cell and beginning of another 1. Count number of objects each collision cell contains and convert them into offsets using scan 2. Create entries for each collision cell in new array 1. Start 2. Number of H occupants 3. Number of P occupants

Create Collision Cell List n n n n 111 n n Sorted Cell ID Array Cell Index & Size Array ID H P ID = Cell index in sorted Cell ID Array H = Number of Home Cell IDs P = Number of Phantom Cell IDs

Traverse Collision Cell List Cell Index & Size Array X p q T 0T 1T 2... T 3T 4 T n Perform Collision Test Per Cell Number of Collisions / Thread Array …