skip to content

A smoky explosion of thousands of particles costs several milliseconds of GPU time when the camera is inside it and shows hard lines where puffs meet the ground; why, and how do you fix both?

level: seniorimportance: should knowfreq 45%

answer

  1. layers per pixel, not particle count
  2. close billboards fill the screen
  3. fewer pixels, then composite
  4. a flat quad cuts the ground
  5. fade against the scene's depth

basics

~20 s

Inside the cloud each billboard covers much of the screen, so every pixel blends dozens of layers: overdraw sets the cost. Render particles at reduced resolution, trim quads, fade near the camera. Soft particles fade alpha against scene depth, removing the hard lines.

solid answer

~50 s

The cost is **overdraw**: every layer covering a pixel runs the particle fragment program and a read-modify-write blend, and from inside the cloud each billboard fills much of the screen, so layers times screen area explodes while the particle count stays the same. The fixes: render particles into a half-resolution premultiplied target, a quarter of the pixels, and composite it with a depth-aware upsample; trim each quad to a polygon that hugs the sprite's visible alpha; fade and cull particles near the camera; use fewer, denser particles and emitter LOD. The hard lines come from a flat billboard crossing the ground under a binary depth test. **Soft particles** read the scene depth and scale alpha by `clamp((sceneDepth - particleDepth) / fadeDistance, 0, 1)` in linear view depth, so a puff fades out as it reaches the surface behind it.

go deeper

for a junior

Recall what overdraw is: the same pixel shaded and blended once for every transparent layer that covers it.

for a middle

Explain why cost tracks screen coverage times layers, and how soft particles fade alpha using the gap between particle depth and scene depth.

for a senior

Diagnose a fill-bound particle pass from an overdraw view, then pick the levers: near-camera fade, trimmed quads, a half-resolution pass with a depth-aware upsample.

for a principal

Set a per-effect overdraw budget artists can see and check, so heavy effects are caught when authored rather than when a camera first walks into them.

## Why the cloud gets expensive Each particle is a camera-facing quad, a **billboard**, drawn with blending. Every pixel it covers runs the particle fragment program and a **read-modify-write** blend into the colour target. What sets the cost is not how many particles exist but how many **layers** cover each pixel, summed over the screen: the **overdraw** of the transparent layers. From outside, a few hundred puffs each cover a few thousand pixels. From inside, the same puffs sit close to the camera and each can cover most of the screen. As this scenario's example: if 60 billboards each fill a 2560 x 1440 screen, the frame shades and blends 60 x 3,686,400, about 221 million fragments, with the same particle count that cost little a moment earlier. Particle count alone is a poor predictor; screen coverage is the real one. ## Confirming the cause - An **overdraw view**, a debug mode that counts layers per pixel, shows where the cost is; a hot core over the camera position is the classic picture. - Timing the particle pass on its own confirms that it is fill-bound: its cost tracks covered pixels and changes little when the particle count changes at constant coverage. Capture and timing tools themselves are a profiling subject. ## Cutting the cost - **Render at reduced resolution.** Drawing particles into a half-width, half-height target shades a quarter of the pixels, 921,600 instead of 3,686,400 at this resolution, before compositing over the full-resolution scene. - **Trim the quads.** Much of a smoke sprite's quad has zero alpha. Fitting each sprite with a tight polygon of four to eight vertices around its visible pixels skips fragments that contribute nothing, for a few extra vertices. - **Fade and cull near the camera.** Fading alpha to zero as a particle approaches the near plane, then culling it, removes the largest layers and the pop when they clip. - **Fewer, denser particles** and **emitter LOD**, so fewer, more opaque puffs carry the look, both at a distance and inside the effect. - **Cheaper shading**, such as lighting smoke per vertex or from a coarse lighting volume rather than per fragment. A half-resolution pass in practice: 1. Downsample the scene depth to half resolution with one consistent rule, the nearest or the farthest of each 2 x 2 block. 2. Render particles into a premultiplied half-resolution target cleared to `(0, 0, 0, 0)`, depth-testing against the downsampled depth. 3. Upsample and composite with `C = rgb + (1 - a) * Cscene`, picking for each full-resolution pixel the low-resolution sample whose depth best matches its own. 4. Where no sample matches, on silhouettes of geometry in front of the smoke, either accept a faint halo or re-render those edge pixels at full resolution. Premultiplied alpha is what makes step 3 a single composite: in that form many layers flatten into one. ## Hard lines and soft particles A billboard is a flat plane. Where it passes through the ground, the depth test is binary: fragments in front of the ground draw at full strength and those behind it are rejected, leaving a crisp line across a soft puff. **Soft particles** read the scene depth as a texture and fade alpha by the gap between the particle and the surface behind it: `fade = clamp((sceneDepth - particleDepth) / fadeDistance, 0, 1)` `alpha = alpha * fade` - Both depths must be **linear view distances**. A perspective depth buffer stores a non-linear value, so raw differences would mean centimetres near the camera and metres far away. Once both are linearised, the formula holds whichever depth direction the buffer uses. - The pass reads the opaque scene depth, so that depth must be readable as a texture while the particle pass still tests against it with depth writes off. - The cost is one depth read and a few instructions per fragment, small next to the overdraw itself. ## The levers side by side | Lever | Saves or fixes | Costs | |---|---|---| | Half-resolution pass | 75% of particle fragments | edge artefacts, an upsample pass | | Trimmed quads | fragments with zero alpha | a few vertices per particle | | Near-camera fade and cull | the largest layers | particles thin out up close | | Emitter LOD | particle count and layers | detail at a distance | | Soft particles | hard intersection lines | one depth read per fragment | The order to reach for them is usually measurement first, then the near-camera fade and trimmed quads, which are cheap, then the half-resolution pass, which buys the most but needs the upsample work.

  • What does a half-resolution particle pass break, and how is it repaired?
    Each low-resolution pixel covers four full-resolution ones, so where scene depth changes sharply, a tree trunk in front of smoke for instance, particles can bleed over the trunk or leave a gap. The composite repairs most of it by choosing, per full-resolution pixel, the low-resolution sample whose depth best matches, and the remaining edge pixels can be re-shaded at full resolution.
  • Why must soft particles compare linear depth rather than raw depth-buffer values?
    A perspective depth buffer stores a non-linear function of distance, so a fixed difference in raw values means centimetres near the camera and metres far away. Converting both depths to linear view distance makes the fade distance a world-space length, so a puff fades over the same distance wherever it is. The conversion uses the projection's near and far planes and works for either depth direction.

  • Particle cost is set by particle count, so halving the count halves the cost.
  • Additive particles are cheap to fill because they skip sorting.
  • Soft particles need each particle to write its own depth.
  • A half-resolution particle pass halves the fragment work.
  • Turning the depth test off for particles removes the hard intersection lines.