Title: Particle System Design
1Particle System Design
2The Challenge
- Particle systems vary so much
- But want some code reuse
- Option 1 parameterization
- Option 2 inheritance
- Option 3 subroutine library
- Lets look at actual systems
3Look for Custom Code
- Motion
- Rendering
- Orientation
- Interparticle Force
- Color
- Spawning
- Emitters
- Any of these could use custom code
4Parameterization
- Simply not general enough
5Inheritance
- Inheritance is usuallyhelpful for code reuse.
- But in the case of particles,
- want to inherit motion from here,
- want to inherit rendering from there,
- want to inherit spawning from that,
- Inheritance doesnt work that way.
6Subroutine Library
- Each system is itsown module, however,
- Library provides
- routines for rendering
- routines for calculating motion
- routines for spawning
- etc
- Lets design this library
7Rendering Routines
- Render camera-aligned quads
- pos, size, color, tex, theta, blend
- Render soft trails
- ie, for jet engine exhaust
- or, for sparks from a grinder
- Render each particle as 3D model
8Soft Trails
- For each point along trailgenerate two
side-points.
9Soft Trails
- For each point along trailgenerate two
side-points.
10Soft Trails
- For each point along trailgenerate two
side-points.
for each point P eye vector from cam to P
lineseg1 one of two segments connected to P
lineseg2 two of two segments connected to P
v1 cross(lineseg1,eye) v2
cross(lineseg2,eye) if (dot(v1,v2) lt 0) v2
-v2 v normalize(average(v1,v2))
sidepoint1 P v sidepoint2 P v
11Particle Motion
- Two ways to do it
- Option 1 Timestep simulation.
- Calculate acceleration
- Position Velocity
- Velocity Acceleration
- Option 2 Closed form equations.
- Particle.X f(t)
- Particle.Y g(t)
- Why not always use timesteps?
12Why closed form I
- Can be hardware accelerated.
- Example simple fountain.
struct vertex float3 startpos float3
initialvelocity float lifespan vertex
shader globals float3 gravity float
currentTime
13Why closed form II
- Can use prerecorded paths.
- float positionX1024
- float positionY1024
- Can add several prerecorded paths
- multiple circles
- wiggle parabola
- Can transform prerecorded path
- smoke example
- Library should contain many paths.
14Why Timestepped
- Particles that bounce.
- or, interact with world in other ways.
- simply cant do this in closed form.
- Decouple frame rate from renderer.
- This should be a class in your library.
ps.elapsed GetClock() ps.createtime timesteps
(int)(ps.elapsed / ps.framerate) while
(timesteps gt ps.timesteps) ps.update() ps.tim
esteps 1
15Data Structures
- Every particle systemneeds some form of particle
list. - But, it seems every system has different particle
attributes. - pos, vel, accel, theta, direction, age,history,
color, rand seed, opacity, lifespan,size,
texture, 3D mesh, quat, etc, etc... - My solution
class particlearray int array_size int
array_fill float3 pos float3 vel
float3 accel ...