34
GPU Particles Jason Lubken 1

GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

GPU ParticlesJason Lubken

1

Page 2: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

ParticlesNvidia CUDA SDK

2

Page 3: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

ParticlesNvidia CUDA SDK

3

Page 4: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

SPHSmoothed Particle Hydrodynamics

Nvidia PhysX SDK

4

Page 5: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

SPHSmoothed Particle Hydrodynamics

Nvidia PhysX SDK

5

Page 6: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Advection, Wind Fields& Weather Effects

GPU RainfallPierre Rousseau, Vincent Jolivet, Djamchild Ghazanfarpour 2008

6

Page 7: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Problem

Problem: CPU - GPU communication is too slow for particles

Move everything to the GPU

Problem: Manage computation & storage for potentially O(n2) particle interactions

Optimize & tune

7

Page 8: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Papers

UberFlow: A GPU-Based Particle Engine

Peter Kipfer, Mark Segal, Rüdiger Westermann

Fast N-Body Simulation with CUDA

Lars Nyland, Mark Harris, Jan Prins

8

Page 9: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

9

Page 10: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

10

Page 11: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Particle Creation

Encode particle properties in one or more textures

Position (RGB)

Creation time (A)

Velocity (RGB)

Type (A)

Cycle particle regeneration using modulo

11

Page 12: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

12

Page 13: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Particle Movement:Euler Integration

Iterative

Storage:

Velocity × 2

Position × 2

Update:

v = v’ + a ⋅ ∆t

p = p’ + v ⋅ ∆t

13

Page 14: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

14

Page 15: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Sorting for Depth

Assign an id to each particle

Compute distance to viewer

Bitonic sort on distance --retain id--

Move position & velocity storage

15

Page 16: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Assigning Ids

Problem: After sorting, find a particle’s original location in a large texture using only a single float id

Distance between consecutive float values is not constant

Millions of particles > 65,536 particles

One bit of exponent is not enough

Precompute the texture of unique ids on the CPU

16

Page 17: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

17

Page 18: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Adding Sorting Keys

Problem: Resolve collisions without O(n2) comparisons

Construct spacial keys

Like: x/g2 + y/g + z

First use aligned cells

Then use staggered cells

Resolve collisions

18

Page 19: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Particle creation

Particle movement

Particle sorting for depth or particle interaction

(Optional) Particle interaction

Boundary enforcement

Rendering

19

Page 20: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

Rotation & rotational velocity

Particle types

Surface normal

Color

Shape

Wind field

20

Page 21: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

21

Page 22: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

UberFlow

22

Page 23: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Papers

UberFlow: A GPU-Based Particle Engine

Peter Kipfer, Mark Segal, Rüdiger Westermann

Fast N-Body Simulation with CUDA

Lars Nyland, Mark Harris, Jan Prins

23

Page 24: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

N-Body Simulation

All particles effect one another directly

Brute force without spacial partitioning: O(n2)

Simplification using far-field effects possible

No collision detection

Integration problems with close proximity & high force

Eplison check & different integrator used

24

Page 25: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Force Computation

fij = G ( (mi mj) / |rij|2 ) ⋅ ( rij / |rij| )

mi & mj are mass

r is distance between particle i and particle j

G is gravitational constant

First term is force

Second term is direction

25

Page 26: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Force Optimization

CPU does half the computation

Leapfrog-Vertlet integration

Smoother than Euler integration

Particle positions & acceleration needed --no velocity texture lookup--

Remove mi from computation

Work to overcome integration problems at close proximity also removes fii

26

Page 27: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Summation Optimization

Tile computation of gravitational force

Loop unrolling 32 body-body interaction

Split rows for small N

27

Page 28: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

N-Body Simulation

28

Page 29: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

N-Body Simulation

29

Page 30: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Ideas

UberFlow

“Clever” use of ids seems computationally intensive

How do you tune this?

N-Body Simulation

Force splatting to alpha buffer

Particle control from CPU using small texture

30

Page 31: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

References

UberFlow: A GPU-Based Particle Engine 2004, Peter Kipfer, Mark Segal, Rüdiger Westermann 2004 http://wwwcg.in.tum.de/Research/Publications/UberFLOW

Fast N-Body SImulation with CUDA, Lars Nyland, Mark Harris, Jan Prins 2008 http://http.developer.nvidia.com/GPUGems3/gpugems3_ch31.html (GPU Gems 3)

Everything About Particle Effects, Lutz Lata 2007 http://www.2ld.de/gdc2007/

Broad Phase Collision Detection with CUDA, Scott Le Grand 2008 http://http.developer.nvidia.com/GPUGems3/gpugems3_ch32.html (GPU Gems 3)

31

Page 32: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Particle Movement

Closed or Parametric Form

Vertlet Integration

Euler Integration

Others

32

Page 33: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Particle Movement:Vertlet Integration

Iterative

Storage:

Position × 3

Update:

p = 2p’ - p’’ + a ⋅ ∆t2

33

Page 34: GPU Particles - Penn Engineeringcis565/LECTURE2010/Particles GPU.pdfparticles Move everything to the GPU Problem: Manage computation & storage for potentially O(n2) particle interactions

Particle Movement: Closed or Parametric Form

Stateless

Storage:

Position x 2

Velocity

Update:

p = po + vot + ½a ⋅ t2

34