Download presentation
Presentation is loading. Please wait.
1
Cornell CS 468Andrew Butts 1 Implementing Particle Systems CS 468 Spring 2004 Andrew Butts
2
Cornell CS 468Andrew Butts 2 What’s going on? Just integrate the particle equations of motion. P’ = V V’ = A = F/m All the fun is in computing F… And in rendering!
3
Cornell CS 468Andrew Butts 3 Simulation Loop PA 4 Requires this loop: Initialize/Emit particles Run integrator (evaluate derivatives) Update particle states Render Repeat!
4
Cornell CS 468Andrew Butts 4 System states Every particle has a state s s = (position, velocity, mass, age, color, …) p and v are the only ones that must vary with time The entire system state is S S = (p1, v1, p2, v2, p3, v3, …) Each p and v is a 3-vector Can think of S as just a vector in 6n dimensions P, V, A, and F are 3n-vectors
5
Cornell CS 468Andrew Butts 5 System states 2.5 ways to implement Particle object array Intuitive. Store all particle attributes in one place Only need to deal with Particle objects Clean implementation if we pick just one integration scheme System state array Store 6n vector S as an array of doubles Simplifies the integrator interface Or transform back and forth
6
Cornell CS 468Andrew Butts 6 Integration How do we implement an integrator? Write a black-box that works on any G function Takes an initial value G at time t, a function G’(value, time) and timestep h. Returns G(t+h). The integrator can be completely separate from the particle representations. If your system has complex forces, repeated G’ evaluations become the bottleneck
7
Cornell CS 468Andrew Butts 7 Integration Euler Method S(t+h) = S(t) + h*S’( S(t), t ) What’s S’ ? S’ = (P’, V’) = (V, A) = (V, F/m) Simple to implement Requires only one evaluation of S’ Simple enough to be coded directly into the simulation loop Error is O(h)
8
Cornell CS 468Andrew Butts 8 Integration Midpoint Method S(t+h) = S(t) + h*S( S m, t+h/2) S m = S(t) + 0.5h * S’( S(t), t ) A little less simple… Must compute S’ twice Must keep temporary system state arrays Error is O(h 2 )
9
Cornell CS 468Andrew Butts 9 Integration Numerical Explosion Can combat error with smaller timesteps at additional computational cost Plagues “stiff” systems with forces prone to oscillation Why’s it called explosion? Demo! (Andrew’s Euler cloth explooodes!) Implicit integration schemes deal with stiff systems Are somewhat painful to implement
10
Cornell CS 468Andrew Butts 10 The Derivative Function How to implement the S’ function Want V and A Know V is just the particle’s current velocity A = F/m. Evaluate forces here.
11
Cornell CS 468Andrew Butts 11 Forces A = F/m Particle masses won’t change But need to evaluate F at every time step. The force on one particle may depend on the positions of all the others
12
Cornell CS 468Andrew Butts 12 Forces Typically, have multiple independent forces. For each force, add its contribution to each particle. Need a force accumulator variable per particle Or accumulate force in the acceleration variable, and divide by m after all forces are accumulated
13
Cornell CS 468Andrew Butts 13 Forces Example forces Earth gravity, air resistance Springs, mutual gravitation Force fields Wind Attractors/Repulsors Vortices
14
Cornell CS 468Andrew Butts 14 Forces Earth Gravity f = -9.81*(particle mass in Kg)*Y Drag f = -k*v Uniform Wind f = k
15
Cornell CS 468Andrew Butts 15 Forces Simple Random Wind After each timestep, add a random offset to the direction Noisy Random Wind Acts within a bounding box Define a grid of random directions in the box Trilinear interpolation to get f After each timestep, add a random offset to each direction and renormalize
16
Cornell CS 468Andrew Butts 16 Forces Attractors/Repulsors Special force object at position x Only affects particles within a certain distance Within the radius, distance-squared falloff if |x-p| < d v = (x-p)/|x-p| f = ±k/|x| 2 * x else f = 0 Use the regular grid optimization from lecture
17
Cornell CS 468Andrew Butts 17 Emitters What is it?! Object with position, orientation Regulates particle “birth” and “death” Usually 1 per particle system More than 1 can make controlling particle death inconvenient
18
Cornell CS 468Andrew Butts 18 Emitters Regulating particles At “birth,” reset the particle’s parameters Free to set them arbitrarily! For “death,” a few possibilities If a particle is past a certain age, reset it. Keep an index into the particle array, and reset a group of K particles at each timestep. Should allocate new particles only once! Recycle their objects or array positions.
19
Cornell CS 468Andrew Butts 19 Emitters Fountain Given the emitter position and direction, we have a few possibilities: Choose particle velocity by jittering the direction vector Choose random spherical coordinates for the direction vector Demo http://www.delphi3d.net/download/vp_sprite.zip
20
Cornell CS 468Andrew Butts 20 Rendering Spheres are easy but boring. Combine points, lines, and alpha blending for moderately interesting effects. Render oriented particle meshes Store rotation info per-particle Keep meshes facing “forward” along their paths Can arbitrarily pick “up” vector
21
Cornell CS 468Andrew Butts 21 Rendering Render billboards Want to represent particles by textures Should always face the viewer Should get smaller with distance Want to avoid OpenGL’s 2d functions
22
Cornell CS 468Andrew Butts 22 Rendering Render billboards (one method) Draws an image-plane aligned, diamond-shaped quad Given a particle at p, and the eye’s basis (u,v,w), draw a quad with vertices: q0 = eye.u q1 = eye.v q2 = -eye.u q3 = -eye.v Translate it to p Will probably want alpha blending enabled for smoke, fire, pixie dust, etc. See the Red Book for more info.
23
Cornell CS 468Andrew Butts 23 Simulation Loop Recap A recap of the loop: Initialize/Emit particles Run integrator (evaluate derivatives) Update particle states Render Repeat! Particle Illusion Demo
24
Cornell CS 468Andrew Butts 24 Resources The Big One www.google.com Numerical Recipes - more on integration www.library.cornell.edu/nr/ ParticleIllusion Demos www.wondertouch.com Physically Based Modeling Notes http://www.pixar.com/companyinfo/research/pb m2001/index.htmlhttp://www.pixar.com/companyinfo/research/pb m2001/index.html
25
Cornell CS 468Andrew Butts 25 Adaptive Stepsize Goal: improve stability without destroying performance Define a measure for “step success” Springs: Has any spring stretched more than 10% during this step? If the step was unsuccessful, Roll back and try with half the stepsize Else if the last 2 steps were successful, Try doubling the stepsize
26
Cornell CS 468Andrew Butts 26 Particle-Object Collision Detection With very simple objects, this is easy Plane: Test the sign of (x-p) n Box: Check six planes! Jon Moon’s Head: Cast ray from p to some outside point. If it intersects Jon Moon an odd number of times, p is inside. Relies on having a CLOSED object! Should accelerate intersection with a grid or octree
27
Cornell CS 468Andrew Butts 27 Collision Response If the step carried a particle into an object, A few possibilities: Accurate: Solve for t at impact and roll the simulation back. –Must process collisions in chronological order –Might iterate forever! Hack: Don’t even bother rolling back! Teleport the particle to the surface of the object Add a response force Bounce, slide…
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.