Presentation is loading. Please wait.

Presentation is loading. Please wait.

GPU Broad Phase Collision Detection GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from GPU Gems III.

Similar presentations


Presentation on theme: "GPU Broad Phase Collision Detection GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from GPU Gems III."— Presentation transcript:

1 GPU Broad Phase Collision Detection GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from GPU Gems III

2 Basic Collision Detection  Broad Phase Reviews the whole simulation Looks at coarse view of objects (usually bounding boxes) Determines if objects may intersect Fast  Narrow Phase Reviews objects that may intersect (determined by broad phase) Looks at detailed view of objects Determines if objects actually intersect Slow

3 Current Broad Phase Methods  Brute Force: n objects need n(n-1)/2 collision tests Complexity = O(n 2 )  Sort and Sweep: Average Complexity = O(n log n) Worst-Case Complexity O(n 2 )  Spatial Subdivision: Average Complexity = O(n log n) Worst-Case Complexity O(n 2 )

4 Sort and Sweep  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

5 Sort and Sweep Sorted List: B1 B3 E1 B2 E3 E2 Active Objects: Add an object i to the active objects list when Bi is reached and remove when Ei is reached Check for intersection between object i and all other object in the active objects list at the time Bi is reached Objects to compare against: 1: 2: 3: 1 1 3 3 2 O1O1 O3O3 O2O2 B1B3E1B2E3 E2

6 Spatial Subdivision 1 2 3 4 5 6 7 8 Images from pg 699, 700 GPU Gems III O1O1 O2O2 O3O3 O4O4 1234 5678 Example

7 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?

8 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

9 Example of Parallel Spatial Subdivision O1O1 O2O2 O3O3 O4O4 1212 3434 O1O1 O2O2 O3O3 O4O4 1212 3434

10 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 1212 3434 Case 1 Case 2

11 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

12 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.

13 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

14 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.

15 Sorting Cell Array 010 0 011 1 111 2 101 3 021 4 021 n 020 0 110 2 100 3 011 4 011 n 011 0 100 2 021 n 021 0 000 2 111 n 001 2 022 n 101 2 011 2 010 2... Cell ID Array 000 2 011 n 101 3 001 2 020 0 101 2 010 0 021 4 110 2 010 2 021 n 111 2 011 1 021 0 111 n 011 0 022 n 111 n 011 2 100 2 102 n 011 4 100 3 103 3... Sorted Cell ID Array 011 1 100 2 Invalid Cell Home Cell Phantom Cell 103 3 Object ID Cell ID Legend

16 Spatial Subdivision 1 2 3 4 5 6 7 8 Images from pg 699, 700 GPU Gems III O1O1 O2O2 O3O3 O4O4 1234 5678 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

17 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

18 Create Collision Cell List 000 2 011 n 101 3 001 2 020 0 101 2 010 0 021 4 110 2 010 2 021 n 111 2 011 1 021 0 111 n 011 0 022 n 111 n 011 2 100 2 102 n 011 4 100 3 103 3... Sorted Cell ID Array Cell Index & Size Array 2 1 4 1 4 10 2 1... ID H P ID = Cell index in sorted Cell ID Array H = Number of Home Cell IDs P = Number of Phantom Cell IDs

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

20 Credits  Based upon GPU Gems article Chapter 32  Chapter Author: Scott Le Grand  This presentation was put together without the approval of the author and should only be used for educational purposes

21 Backup

22 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 1 2 3 4 5 6 7 8 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 1234 5678 Example


Download ppt "GPU Broad Phase Collision Detection GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from articles taken from GPU Gems III."

Similar presentations


Ads by Google