mplementing Particle Systems in OpenGL

advertisement
Implementing Particle Systems in OpenGL
1
Information Goal
• What is a Particle System?
• What constitutes a Particle System?
• How an OpenGL code is constructed to generate a particle
system?
• Performance in Particle System
2
Sample Particle System
Water
Fire and Smoke
3
What is a Particle System?
• A particle system - collection of many minute particles that
together represent a fuzzy object. (fog,explosions,water,dust
etc)
• Particles are generated into a system, move and change from
within the system, and die from the system.
• 1983,William T. Reeves
Star Trek, The Wrath of Khan 1982
• Realized conventional modeling for
creating objects with smooth,
well-defined surfaces wouldn't do
the trick
• Natural phenomenon- better modeled as
a system of particles – behave within
a set of dynamic rules.
4
Particle Systems differ in three ways from
normal representations
• An object is represented as a cloud of primitives particles that
define its volume and not as surface elements like polygons
• A particle system is not a static entity; its particles change form
and move. Particles are created and destroyed.
• An object represented by a particle system is not deterministic,
its shape and form is not completely specified. (Stochastic
processes)
5
Advantages:
• Particle(point) simplest surface representation then polygon
(same time, complex image). Simple –Easily Motion blur
• Model definition – procedural & random numbers(Design time less)
• Model “Alive” objects. Surface based modeling –no complex
dynamics
Basic Model of Particle Systems:
•
•
•
•
•
•
For each frame of an animation sequence
New particles are generated
Each new particle - own set of attributes
Particles - existed for a predetermined time are destroyed
Remaining particles - transformed and moved according to their
dynamic attributes
Remaining particles is rendered
Procedural –Any computational model describe object dynamics
6
Particle Phases:
Generation, Dynamics, and Death.
• Generation : generated randomly with a shape that may change
attributes –initial value, fixed or stochastic process
•Particle Dynamics : particle attributes change over time. (color, position)
Particle attributes functions of time or other attributes
Example- position dependent on velocity and time
•Extinction – age and lifetime attributes deal with length of existence
Age – Time a particle has been alive. It is “0” when particle created
Lifetime – Max time the particle can live
if age matches lifetime –destroyed
There can be other criteria for destroying particles
7
Particle attributes:
For each new particle
• initial position
• initial velocity (speed and direction)
• initial size
• initial color
• initial transparency
• shape
• lifetime
The generation shape describes the initial direction of new particles.
Position in 3d define its origin,2 angles of rotation giving orientation,
Generation shape –new particles placed.
8
Particle Structure:
Struct Particle
{
float pInitial ;
float vInitial ;
float tInitial ;
float acceleration;
float pFinal ;
float color ;
float size ;
float globalTime;
float time;
// Initial Position
// Initial Velocity
// Time when particle was created
// Particle acceleration
// Final Position
// Particle color
// Particle size
//Global time
// Relative time or age
}
Particle system behave according to simple vector kinematic equations
from physics.
9
Computing Particle Attributes:
Global time is “0”,incremented
How long a particle is active? float time = globalTime - tInitial;
Final Position :
float pFinal = pInitial + vInitial * t + 0.5 * acceleration * t * t;
Color and size functions of time (Random)
Xnew = Xold + Vold * Time change;
Vnew = Vold + a * Time change;
F = ma;
10
The basic process is:
Emitter
Random
Number
Generator
Update
Render
11
Emitter:
• Acts as source of particles and its position determine where they
are generated.
• Controls number of particles, direction and other global settings
Update:
• Particles attributes are updated. If Dead removed from emitter.
• Functions define behavior of particles as they move through the scene
Render:
• How particles are displayed on screen? Points, Polygons around the
points ,then apply textures(Billboard),3D model or Point Sprites.
Point sprites assigns texture coordinates for each
corner vertex, alter the particle appearance from
Square to any textured image.
12
Particle Manager
• It is used to control many particle systems
• In charge for creating, releasing, updating and rendering systems.
• Array of pointers to particle systems
• Functions like AddSystem, RemoveSystem, Update ,Render can
to deal with the particle systems.
Particle Manager
Particle System
Particle
Particle
Particle System
Particle
Particle
13
Optimizing Particle systems:
• Minimize texture swapping : advantage to render particles with
similar texture in sequence
• Implementing Level of Detail : number of new particles must
vary based on existing particles
• Particle effect is far from the camera, occupy only a few pixels of
screen space - not necessary to introduce many particles.
• Efficient Memory Access: Tag dead particles as inactive and use
them once again for introducing new particles. Reduces
overhead due to creation, initialization and destruction
• Render particles in batch so that GPU is busy.Longer loads
make GPU idle
14
Optimizing Particle systems:
• Reduce Memory and Computation Requirements with Custom
Structures and Update Routines : code several different types of
particle classes for certain effects
• Store shared variables only once. Increases efficiency referencing one variable many times.
•
Fast Random Number Generation: avoid random numbers precomputing several effects and storing them and use the stored
effect.
• Drawback : more memory, no random effect
• Fast Dynamic Storage Structures: Vectors, lists and arrays.
Vectors are faster than Lists in terms of initialization speed and
access speed.
15
Environment and system interaction:
• Environment has external factors acting on particles
• Particles effect environment, vice versa
• Single global environment handles little interaction between
particle systems and environment
Global environment
Gravity
16
Environment and system interaction:
• For more interactions, subdivided into localized environments
Local Environment 1
Local Environment 2
Gravity
Gravity
Influence of different parameters in different environments
17
Environment and system interaction:
•Degree of control –small and more or few and large
•Rising Smoke –top of flame
•Lower part –Larger environments particle movement uniform
•Upper part –more environments to give a chaotic behavior
18
Environment and system interaction:
• Local environments borders can overlap
•
Drastic change in parameters
reflect on particle behavior
• Overlap- Parameters are averaged
• Computation cost
• Increase environments increases
rendering time
19
Questions …..
20
Download