0% found this document useful (0 votes)
138 views

Mega Particles Slides

The document discusses the history and basics of particle systems, including how they are simulated on the GPU. It covers stateless and state-preserving particle simulations, algorithms for simulation steps like forces and collisions, sorting particles for rendering, and transferring particle data from textures to geometry.

Uploaded by

_an__
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views

Mega Particles Slides

The document discusses the history and basics of particle systems, including how they are simulated on the GPU. It covers stateless and state-preserving particle simulations, algorithms for simulation steps like forces and collisions, sorting particles for rendering, and transferring particle data from textures to geometry.

Uploaded by

_an__
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Building a Million Particle System

Lutz Latta
Massive Development GmbH

Overview

History of particle systems


Basics of particle system simulation
Particle systems on the GPU
Stateless simulation and rendering
State-preserving physical simulation
Sorting algorithm
Rendering algorithm

History of Particle Systems:

1962
Second video game
ever!
Uses pixel clouds as
explosions
Random motion

Image from online, public domain version of Spacewar!


http://lcs.www.media.mit.edu/groups/el/projects/spacewar/

Spacewar!

History of Particle Systems:


Image from open source Asteroids clone by Justin Irwin
http://www.mirwin.net/

Asteroids

1978
Uses short moving
vectors for
explosions
Probably first
physical particle
simulation in
CG/games

Star Trek II: The Wrath of Kahn

1983
Movie Visual FX:
Planetary fire wall
First CG paper about
particle systems by
William T. Reeves
Today concept still
unaltered!

Images: ACM, used by permission of Association of Computing Machinery


Reeves1983, Particle Systems - Technique for Modeling a Class of Fuzzy Objects

History of Particle Systems:

What is a Particle System (PS)?

Individual mass points moving in 3D space


Forces and constraints define movement
Randomness or structure in some start
values (e.g. positions)
Often rendered as individual primitive
geometry (e.g. point sprites)

Uses of Particle Systems

Explosions

Smoke

Fog

Uses of Particle Systems (cont.)

Weapon FX

Impact FX

Basic Particle System Physics

Particle is a point in 3D space


Forces (e.g. gravity or wind) accelerate a
particle
Acceleration changes velocity
Velocity changes position

Euler Integration

10

Integrate acceleration to velocity:


v=v a t
Integrate velocity to position:
p= p v t

t
a
v
v
p
p

Computationally simple
Needs storage of particle position and
velocity

time step
acceleration
velocity
prev. veloc.
position
prev. pos.

Verlet Integration

Integrate acceleration to position:


2
p=2 p p a t
position two time steps before
p

11

Needs no storage of particle velocity


Time step needs to be (almost) constant
Explicit manipulations of velocity
(e.g. for collision) impossible

Particle Simulation on the GPU

Stateless simulation
Only simple effects
Simulation in vertex shader
Possible on first generation programmable GPUs

State-preserving (iterative) simulation

!
W
NE Simulation with textures and pixel shaders
Only on recent generation GPUs

12

13

No storage of varying
particle data
Evaluation of closed form
function describing
movement/attribute changes
Computed data depends only
on initial values and static
environment description

Image from NVIDIA particle system demo

Stateless Particle Systems

Example of Stateless PS

Position depends on initial position p 0 ,


initial velocity v 0 and gravity g
p t = p 0 v 0 t g t
1
2

Orientation depends on initial orientation 0


and rotation velocity
t =0 t

14

Example of Stateless PS (cont.)

Color and opacity depend on linear


function segments with four keyframes

f t

k1

k2

k0
k3

First segment:

k 1k 0
k 1k 0
f 0 t =
tk 0
t 0 =mtb
t 1t 0
t 1t 0

15

Algorithm of Stateless PS
At particle birth
Upload time of birth and initial
values to dynamic vertex buffer
In extreme cases only a random seed
needs to be uploaded as initial value

At rendering time
Set global function
parameters as vertex
shader constants

Render point sprites/triangles/quads


with particle system vertex shader
16

Now...
...let's talk about some hot new stuff!

17

State-Preserving Simulation

18

Position and velocity stored in textures


From these textures each simulation step
renders into equally sized other textures
Pixel shader performs iterative integration
Position textures are re-interpreted as
vertex data
Rendering of point sprites/triangles/quads

Storage of Particle Data


Position
texture

(x/y/z)

double
buffer

(x/y/z)

Velocity
texture

(x/y/z)

double
buffer

(x/y/z)

Static info
(tob/pt)
per particle:
time of birth (tob),
particle type (pt) ...
19

Double buffers required to


avoid simultaneous rendering
from one texture into itself!

Storage of Particle Data (cont.)

Position and velocity stored in 2D textures


Textures treated as 1D array
Precision: position 32bit FP, velocity 16bit FP
Static per particle information:
Time of birth, type ID, random seed
Not necessarily in a texture, but indices are
the same as in particle textures

20

Algorithm for One Time Step


1. Process birth and death
2. Velocity operations (forces, collisions)
3. Position operations
4. Sorting for alpha blending (optional)
5. Transfer pixel to vertex data
6. Rendering

21

Birth of a Particle/Allocation

Allocation is a deeply serial problem; it


cannot be done efficiently on parallel GPU
Use fast, problem-specific allocator
Important to get compact index range
Perform allocation on the CPU:
Determine next free index
Determine initial particle values
Render initial values as pixel-size points

22

Death of Particles

Processed independently on CPU and GPU


CPU: Free particle index, re-add it to allocator
GPU: Move particles to infinity (or very far away)
P

23

If particles fade out or fall out of view,


this clean-up rarely really needs to be done

Velocity Operations

Update velocity textures with various


operations:
Global forces
Local forces
v
v
Dampening
P
P
Collisions
Flow field
[insert artists' dream operation here]

24

Velocity Ops:

Global and Local Forces

Global forces are position-invariant:


Gravity, wind

Local forces fall off based on distance:


Magnet, orbiting, turbulence, vortex

25

r distance
Fall off with 21 or at hard
r
small epsilon
boundary
Individual particles might scale effect
based on mass, air resistance etc.

V. Ops: Global

and Local Forces (cont.)

Add all forces to one force vector


Convert force to acceleration (F =ma )
identical if all particles have unit mass

wind

gravity

26

magnet

sum of forces

Velocity Ops:
v P

Dampening

v=cv

c constant scale factor

Dampening:
Scale down velocity vector
Simulates slow down in viscous materials

Un-dampening:
Scale up velocity vector
Simulates self-moving objects, e.g. bee swarm

27

Velocity Ops:

Collision

Collision on GPU limited for efficiency:


Primitive objects: sphere, plane, box
Texture-based height fields, i.e. terrain
(might be dynamic!)

Algorithm:
1. Detect collision with expected new position
2. Determine surface normal at approximate
penetration point
3. React on collision, i.e. alter velocity

28

Collision Reaction

Split velocity (relative to collider) into


normal v n and tangential v t component:
v n= vn v

v t =v v n
n

vt
vn
29

Collision Reaction (cont.)

Friction reduces tangential component


Resilience scales reflected normal comp.
Resulting velocity:
v=1 v t v n

v
vt

v
vn

Shows some artifacts (see paper for fix-ups)


30

Collision with Height-Field

Quite efficient on GPU, only 3 shader ops:


Multiply-add particle position into tex. coords.
Look-up height in texture
Compare particle height against texture height
P

Reaction requires surface normal


Look-up from normal map
Or compute from three height samples

31

Position Update
P

Euler integration:

Simply apply velocity (see previous slides)

Verlet integration:
Apply acceleration caused by forces
Apply other simple effects like dampening etc.
Collision is best handled with position
constraints, i.e. move particle outside a sphere
Collision reaction is then stored implicitly in
constraint-based position shift

32

Sorting for Alpha-Blending

Alpha-blended particles show artifacts


when rendered unsorted

Unsorted, wrong order

33

Sorted, right order

Sorting for Alpha-Blending (cont.)

Try first:
Check whether commutative blending
(add, multiply) can be used instead!
Otherwise:
The GPU can sort nowadays...
Put viewer-distance and index into a texture
Sort this texture (at least partially)
Render with indirection over sorted indices

34

Sorting Networks

35

GPU needs parallel sorting algorithm


Check for total order is serial, i.e. expensive
Best to use a data-independent algorithm
Sorting networks always have fixed number
of comparisons
Efficient algorithm: Odd-Even Merge Sort

8 data elements

Odd-Even Merge Sort


7
6
5
4

Arrows mark one


comparison, maybe
with swapping.

3
2
1

Vertical lines separate


rendering passes.

36

Every step increases or at least keeps order!


Allows distributing the sorting over several
frames (high frame-to-frame coherence)

Transfer Pixel to Vertex Data

37

After simulation (and sorting) we need to


transfer particle positions to geometry data
Point sprites allow most efficient transfer:
only one vertex per particle
Triangles or quads need replicated vertices
Several methods to transfer texture data to
vertices exist:

ber-Buffer (also called Super Buffer)

Store any data in graphics card memory


Copy from one buffer (here texture)
to another buffer (here vertex buffer)
texture

copy

vertex stream

Available on current hardware (GFFX, R9xxx)


OpenGL-only, currently not in DirectX
Various OpenGL extensions: ARB_super_buffer,
NV_pixel_buffer_object, NV_pixel_data_range

38

Vertex Textures

Access textures from vertex shaders


Vertex shader actively reads particle positions
static vertex stream
texture

39

read index
read data

vertex
shader

Available in DirectX (VS3.0) and


OpenGL (ARB_vertex_shader/GLSL)
Hardware support right around the corner

Rendering

Render as point sprites or triangles/quads?

Point sprites reduce work for vertex unit


Rotation of point sprites tricky:
requires pixel shader texture rotation
Triangles/quads cause less per-pixel work
You decide!

40

Handle Other Particle Attributes

Up to here we've only discussed the


particle position...
How do we get color, opacity, size,
orientation, texture coords. of particle?
Mix with stateless particle simulation!
Functions of these values have lower complexity
Use closed form functions as in example at the
beginning

41

Point Sprite Rotation

You can't rotate point sprites, as they are


axis-aligned quads
You can however rotate texture coords.
Rasterizer generates tex. coords. [0..1][0..1]
Rotate in pixel shader with 22 matrix
Reduces usable texture
area to inner circle!

42

Multiple Particle Textures

Problem: You cannot change textures while


drawing a sequence of particles
Combine several textures as sub-textures of
one larger texture
Adjust texture coords.
accordingly
For point sprites: Transform
tex. coords. in pixel shader
(comes free with rotation)

43

Demo

...
44

Conclusion

45

Stateless simulation is easily set-up and


has broad hardware support
State-preserving simulation allows more
complex FX, increasing player immersion
Use sorting when necessary it's efficient!
Make particles smaller it's more realistic!
Explore new gameplay uses it's more fun!

Questions

Thanks for their support:


Ingo Frick, Prof. Andreas Kolb,
Sieggi Fleder, Matthias Wloka, Simon Green
Dr. Christoph Luerig, Mark Novozhilov
More info: www.2ld.de/gdc2004/
46

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy