✚ Game development

Particle systems: smoke, sparks and explosions in games

How a particle system works in video games: emitters, lifetime, curves over time, additive blending, performance and particles that serve gameplay.

Smoke, fire, sparks, dust kicked up by footsteps, raindrops, glowing trails: a large share of video game visual effects comes from a simple idea. Instead of animating an explosion by hand, you spawn dozens or hundreds of small independent elements, particles, each with elementary rules. The overall result looks organic and always slightly different.

What a particle is

A particle is a very lightweight object with few properties:

  • position and velocity;
  • remaining lifetime;
  • size, colour, opacity;
  • rotation and rotation speed;
  • possibly a texture or one frame of a small animation.

On each update the particle moves, ages and, when its lifetime runs out, is removed. It has no complex collisions and no intelligence: the richness of the effect comes from numbers and variation.

The emitter

Particles are created by an emitter, which defines how they are born. The main parameters:

Parameter Smoke example Explosion example
Mode Continuous, 20 per second Single burst of 80
Shape Point or small circle Sphere
Initial direction Upwards, narrow cone All directions
Initial speed Low, little variation High, wide variation
Lifetime 2-4 seconds 0.3-1 second
Gravity Slightly negative, rises Positive for debris

Almost every value is defined as a range, not a fixed number: speed between 50 and 120, lifetime between 0.5 and 0.9. It is this controlled randomness that avoids an artificial look.

Evolution over time

The secret of a good effect is how properties change over a particle's life. Instead of constant values, curves or gradients are used as a function of normalised age, from 0 at birth to 1 at death:

  • size: smoke grows as it rises; a spark shrinks;
  • colour: fire goes from yellow to red to dark grey;
  • opacity: a quick fade-in at the start and a fade-out at the end, so the particle does not pop in and out;
  • speed: drag that gradually reduces it makes movement more believable.
age = 1 - remaining_life / total_life
size = size_curve(age) * base_size
colour = colour_gradient(age)
velocity *= (1 - drag * dt)

Blending and draw order

How particles combine with the background completely changes their look:

  • normal alpha blending: suited to smoke, dust and debris, which cover what is behind them;
  • additive blending: colours add up, and overlapping areas become brighter. It is ideal for fire, sparks, energy beams and lasers, and has the advantage of not depending on draw order.

With alpha blending, by contrast, order matters: particles should be drawn from furthest to nearest. In 2D the problem is often negligible; in 3D, with many overlapping effects, it is one of the main difficulties.

Composite effects

A convincing effect rarely comes from a single emitter. A well-made explosion combines, for example:

  1. a very short, bright initial flash;
  2. an additive fireball that expands and cools in colour;
  3. debris flying off under gravity;
  4. smoke that lingers longer and rises slowly;
  5. an optional shockwave, a ring that expands rapidly.

Each layer has its own duration and behaviour, and together with a suitable sound and a slight screen shake they produce an impact far greater than the sum of the parts.

Performance

Particles are numerous by definition, so efficiency matters:

  • use a preallocated pool of particles instead of creating and destroying objects;
  • store properties in contiguous arrays for fast updates;
  • draw all of an emitter's particles in a single call, with one texture or an atlas;
  • set a maximum limit per emitter and globally;
  • suspend off-screen emitters;
  • for very large numbers, hand the simulation to the GPU, a capability the main engines provide.

Watch out for overdraw as well: many large, semi-transparent overlapping particles force the GPU to compute the same pixels several times. Often a few larger, well-drawn particles look better than many small ones.

Particles that serve the game

Effects are not just decoration: they communicate information. Dust on landing confirms contact with the ground, sparks show that a hit struck armour, a glow signals an item to pick up. Two recommendations:

  • effects must not obscure important elements such as enemy projectiles or the character;
  • provide an option to reduce flashes and particles, useful for people sensitive to intense visual stimuli and on less powerful hardware.

In short

  • A particle system spawns many simple elements with slightly random properties.
  • The emitter defines quantity, shape, direction, speed and lifetime.
  • Curves and gradients over time make size, colour and opacity believable.
  • Additive blending is ideal for fire and energy; alpha blending for smoke and dust.
  • Pools, limits and attention to overdraw keep performance good.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also