250 likes | 373 Views
Building a Particle System. References: 1. Gamasutra article by Van der Berg 2. Particle System API by McAllister 3. Explosion.c. Particle System (PS) Gallery. Performance and Requirement.
E N D
Building a Particle System References: 1. Gamasutra article by Van der Berg 2. Particle System API by McAllister 3. Explosion.c
Performance and Requirement • Keep in mind: a PS greatly increases the number of polygon per frame (one particle: four vertices & 2 triangles) • Perform as few memory operations (allocation/release) as possible • Use a flag to mark a particle dead or respawn • Ability to link PS within the hierarchy of other geometry (smoke out of a cigarette)
Data Structure Reference 1 contains all other details
Explosion • A simple particle system demo for explosion effects (particles and debris) • Observe how particle evolves and how debris rotates
Particle System API (McAllister) • API used in some academic projects • Design modeled after OpenGL • Design goals: • Run-time efficiency • Flexibility: create effects from simple building blocks (gravity, bounce, …) • Scalable simulation quality • Easy to learn
Particle Position Velocity Color Alpha Size Age Secondary position Secondary velocity Particle group A set of particles acted upon by the same forces API applies to the current group Action Functions modify the attributes of particles in the current group Currently has 27 actions (some are physically related) Building blocks for special effects API Description
ActionList Actions compiled (similar to displaylist) Actions in Use
API state (color, velocity, size, …) pSource: create new particles Domain: a uniform mechanism for specifying a region of three-space pColorD: a region of color space pVelocityD: a region of vector space A variety of shapes: PDSphere, PDPlane, … Specified by 9 or fewer floats Attributes and Domains
Newton’s law Use Euler’s method with user-specified step size dt Particle Simulation
Design a PS that suits your needs • Starting pos • Breaking pos • Timeline: ADSR envelope • Color attributes • Rendering style • Dynamics
PAPI (v.210) You need VC80! Uses freeglut
GenParticleGroups P_group_count Max_particles (similar to display list) CurrentGroup Current particle group all actions and commands apply SetMaxParticles GetGroupCount # of particles in the group GetParticlePointer Expose internal storage of particles (avoid copying for higher performance) Example: ParticleContext_t P
Gravity Move (vel, rotvel) Update pos, orient (up vector) P.Source (rate, dom) Particles to add per unit time P.Sink (inOrOut, dom) Kill particles w.r.t dom Bounce (friction, resilience, cutoff, dom) Sphere, rectangle, triangle disc, plane Color (rgb); Color(dom) Translate pos into color Velocity (dom) … ParticleContext_t P
pDomain • Blob, Box, Cone, Cylinder, Disc, Line, Plane, Point, Rectangle, Sphere, Triangle