Skip to content

Postprocessing ​

The Postprocessing component owns the scene-wide effect chain (bloom, vignette, depth-of-field, tone mapping, SSAO, and more). Each effect has its own enabled flag plus per-effect parameters.

It is a singleton there is exactly one Postprocessing entity per scene, owned by the editor.

In the editor, you set these effects in the Post FX section of World Config. See World Config.

IMPORTANT

The render system only applies effects when the master toggle postEnabled is true. Enabling an individual effect alone has no visual impact unless the master toggle is also on.

Managed by: PostprocessingSyncSystem

Get the component from the world ​

Use world.getPostprocessingComponent(), a convenience method that handles the entity lookup for you:

ts
import { Behaviour } from "@relu-interactives/spatial-ecs";

export default class ReadPostprocessing extends Behaviour {
  init() {
    const post = this.world.getPostprocessingComponent();
    if (!post) return;

    console.log("post enabled?", post.values.postEnabled);
  }
}

post.values is the live state object, mutate fields on it directly. The PostprocessingSyncSystem reads it every frame and rebuilds the effect chain as effects are toggled.

Change values at runtime ​

Enable the master toggle and a few effects ​

ts
post.values.postEnabled = true;

post.values.bloom.enabled = true;
post.values.bloom.intensity = 1.5;
post.values.bloom.threshold = 0.25;
post.values.bloom.radius = 0.8;

post.values.vignette.enabled = true;
post.values.vignette.darkness = 1.4;

Toggle a single effect from a script ​

ts
function setBloom(post, on) {
  post.values.postEnabled = on || somethingElseEnabled(post);
  post.values.bloom.enabled = on;
}

Cinematic depth of field ​

ts
post.values.dof.enabled = true;
post.values.dof.focusDistance = 0.02; // distance from the camera (normalised)
post.values.dof.focalLength = 0.05;
post.values.dof.bokehScale = 4;

Color grading ​

ts
post.values.toneMapping.enabled = true;
post.values.toneMapping.exposure = 1.1;

post.values.hueSaturation.enabled = true;
post.values.hueSaturation.hue = 0.05;       // radians
post.values.hueSaturation.saturation = 0.2; // 0 = unchanged

Lens and retro effects ​

Since 0.5.4, chromatic aberration, pixelation, SMAA and tone mapping all render. Earlier versions accepted these fields and drew nothing.

ts
import { Behaviour } from "@relu-interactives/spatial-ecs";

export default class RetroLook extends Behaviour {
  init() {
    const post = this.world.getPostprocessingComponent();
    if (!post) return;

    post.values.postEnabled = true;

    // Red/blue fringing. The (x, y) offset sets direction and strength, in UV units.
    post.values.chromAberration.enabled = true;
    post.values.chromAberration.offsetX = 0.002;
    post.values.chromAberration.offsetY = 0.001;

    // Mosaic blocks, `granularity` CSS pixels wide.
    post.values.pixelation.enabled = true;
    post.values.pixelation.granularity = 4;

    // Edge antialiasing for the composed image.
    post.values.smaa.enabled = true;

    // ACES tone mapping at this exposure.
    post.values.toneMapping.enabled = true;
    post.values.toneMapping.exposure = 1.2;
  }
}
  • Chromatic aberration runs three's RGBShiftShader. The pass shifts red by the offset and blue by the opposite offset.
  • Pixelation samples the centre of each block. It pixelates everything earlier in the chain, bloom included.
  • SMAA runs three's SMAAPass right before the output pass. Turn it on when the canvas was created without antialias, or whenever the composer is active: render targets do not use the canvas's built-in MSAA.
  • Tone mapping has no pass of its own. It sets the renderer's tone mapping and exposure, which the final OutputPass applies. When the scene's Environment.values.lighting.toneMapping names an operator, that operator wins and this effect only sets the exposure. With no environment operator it uses ACES Filmic. The Environment page has the full table.

The composer applies effects in this order: scene → depth of field → bloom → vignette → hue/saturation → sepia → film noise → dot screen → SSAO → glitch → chromatic aberration → pixelation → SMAA → output (tone mapping and sRGB).

Support per renderer ​

The same component drives both renderers. On WebGL the chain is an EffectComposer; with WebGPURenderer and webgpuBackend it is a TSL RenderPipeline (WebGPU and TSL).

EffectWebGLWebGPU
Depth of field✅ BokehPass✅ DepthOfFieldNode (focusDistance / focalLength in world units)
Bloom✅ UnrealBloomPass✅ BloomNode
Vignette✅✅ same formula
Hue / saturation✅✅ hue() / saturation() with the same curves
Sepia✅✅
Film noise✅ FilmPass✅ FilmNode
Dot screen✅ DotScreenPass✅ DotScreenNode
SSAO✅ SSAOPass≈ GTAO (GTAONode); intensity is the occlusion exponent, normals come from depth
Chromatic aberration✅ RGBShiftShader✅ RGBShiftNode
Pixelation✅✅
SMAA✅ SMAAPass✅ SMAANode
Tone mapping✅✅
Glitch✅ GlitchPass❌ skipped, with one warning

On WebGPU, changing a parameter (bloom strength, vignette darkness, ...) updates the running chain in place. Switching an effect on or off rebuilds it. A WebGPURenderer without webgpuBackend renders with no post-processing at all.

Authorable values ​

Top-level master toggle:

PathTypeDefault
postEnabledbooleanfalse

Each effect lives under its own key with enabled plus parameters:

EffectPath prefixKey parameters
Depth of fielddoffocusDistance, focalLength, bokehScale
Bloombloomintensity, threshold, radius
Vignettevignetteoffset, darkness
Chromatic aberrationchromAberrationoffsetX, offsetY (UV units)
Film noisenoiseopacity
Pixelationpixelationgranularity (CSS pixels)
Tone mappingtoneMappingexposure (ACES unless the environment picks an operator)
Hue / saturationhueSaturationhue, saturation
Sepiasepiaintensity
SMAAsmaa(toggle only)
SSAOssaointensity, radius
Dot screendotScreenscale, angle, opacity
Glitchglitchdelay, duration, strength, mode, active

For the full type, including every legacy/optional parameter, see PostprocessingState.

API reference ​