Introduction to Particle Systems
What is a particle system?
Particle systems are a graphical technique that simulates complex physically-based effects. Particle systems are collections of small images that when viewed together form a more complex “fuzzy” object, such as fire, smoke, weather, or fireworks. These complex effects are controlled by specifying the behavior of individual particles using properties such as initial position, velocity, and lifespan.
Particle system effects are common in movies and video games. For example, to represent damage to a plane, a technical artist could use a particle system to represent an explosion on the plane’s engine and then render a different particle system representing a smoke trail from the plane as it crashes.
Particle system basics
Take a look at the code for a basic particle system:
The above code creates a
ParticleSystem, an object parameterized to control the appearance and
behavior of individual
Particle objects over time. Particles, which are born from a
ParticleEmitter, have a position and type, live for a set amount of time, and then die.
Some of these properties are dynamic. Notice that instead of using the available single color property
scale, there is a
endScale. These allow you to specify that the particle size transitions between the start and end scale over the course of the particle’s life.
endColor work similarly.
Other ways of affecting the visual output include maximum and minimum attributes. For every variable with a maximum and minimum input, the actual value for that variable on the particle will be randomly assigned to be between the maximum and minimum input and stay statically at that value for the entire life of the particle. For example, use
maximumSpeed as bounds for the randomly chosen speed of each particle. Attributes that allow for changes like this include
When a particle is born, its initial position and velocity vector are controlled by the
The emitter will spawn some number of particles per second, specified by the
emissionRate parameter, initialized with a random velocity dependent on the emitter type.
Cesium has various ParticleEmitter’s that you can use out of the box.
BoxEmitter initializes particles at randomly-sampled positions within a box and directs them out of one of the six box faces.
It accepts a
Cartesian3 parameter specifying the width, height, and depth dimensions of the box.
CircleEmitter initializes particles at randomly-sampled positions within a circle in the direction of the emitter’s up axis.
It accepts a single float parameter specifying the radius of the circle.
If no emitter is specified, a
CircleEmitter is created by default.
ConeEmitter initializes particles at the tip of a cone and directs them at random angles out of the cone.
It takes a single float parameter specifying the angle of the cone. The cone is oriented along the up axis of the emitter.
SphereEmitter initializes particles at randomly-sampled positions within a sphere and directs them outwards from the center of the sphere.
It takes a single float parameter specifying the radius of the sphere.
Configuring particle systems
Particle emission rate
emissionRate controls how many particles are emitted per second, which changes the density of particles in the system.
Specify an array of
burst objects to emit bursts of particles at specified times (as demonstrated in the animations above). This adds variety or explosions to your particle system.
Add this property to your
These bursts will emit between min and max particles at the given times.
Life of the particle and life of the system
By default, particle systems will run forever. To make a particle system run for a set duration, use
lifetime to specify the duration in seconds and set
loop to false.
particleLife to 5.0 will set every particle in the system to have that value for
particleLife. To randomize the output for each particle, use the variables
Particles are styled using a texture specified with
image and a
color, which can change over the particle’s lifetime to create dynamic effects.
The following code makes the smoke particles transition from green and fade out to white.
The size of a particle is controlled with the
imageSize. To randomize sizes, control the width in pixels with
maximumImageSize.x and the height in pixels between
This creates square particles between 30 and 60 pixels:
The size of a particle can be modulated over its lifetime with the
endScale properties to make particles grow or shrink over time.
Speed is controlled by either the
speed or by both the
Particle systems can be further customized by applying an update function. This acts as a manual updater for each particle for effects such as gravity, wind, or color changes.
Particle systems have an
updateCallback that modifies properties of the particle during the simulation. This function takes a particle and a simulation time step. Most physically-based effects will modify the velocity vector to change direction or speed. Here’s an example that will make particles react to gravity:
This function computes a gravity vector and uses the acceleration of gravity to alter the velocity of the particle.
Set the force as the particle system’s
Particle systems are positioned using two
Matrix4 transformation matrices:
modelMatrix: transforms the particle system from model to world coordinates.
emitterModelMatrix: transforms the particle system emitter within the particle system’s local coordinate system.
You can use just one of these transformation matrices and leave the other as an identity matrix, but we provide both for convenience. To practice creating the matrices, let’s position our particle emitter relative to another entity.
Create an entity for our particle system to accent. Open the Hello World Sandcastle example and add the following code to add a milk truck model to the viewer:
We want to add a smoke effect coming from the rear of the truck. Create a model matrix that will position and orient the particle system the same as the milk truck entity.
This places the particle system at the center of the truck. To position it at the back of the truck, we can create a matrix with a translation.
Now add the particle system.
Also note that we can update the model or emitter matrices over time. For instance, if we wanted to animate the emitter position on the truck,
we can modify the
emitterModelMatrix while leaving the
See the complete code example here: Particle System demo.
For more cool effects with Particle Systems using more advanced techniques, see the Particle System More Effects Tutorial
For more example code see: