Shaders From Zero · Episode 16

Post-Processing Suite

Post-Processing Suite is Episode 16 of Shaders From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.

Part of the MasterAllArts Creative 3D Roadmap .

Episode 16 · Shaders From Zero · Season 2 Finale

Post-processing is shaders applied to the entire frame, after the scene is rendered. Your scene is rendered into a texture, then that texture is passed through a chain of full-screen quad shaders — bloom, color grading, distortion, anti-aliasing. This episode builds a four-pass pipeline by hand: bloom, chromatic aberration, vignette, pixelation. Each one is ten lines of GLSL.

This is the last episode of Season 2 and of the canonical curriculum. By the end you have a shader pipeline you'd ship in any cinematic 3D project.

0 fps
EffectComposer · 5 passes
Layer 1: raw scene, no post-processing. Baseline.

The architecture

EffectComposer is Three.js's chain abstraction. You add passes; it manages the render targets between them. Each pass takes the previous pass's output as a texture input and writes its output to a new texture (or to the screen, if it's the last one).

import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass }    from 'three/addons/postprocessing/RenderPass.js';
import { ShaderPass }    from 'three/addons/postprocessing/ShaderPass.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';

const composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
composer.addPass(new UnrealBloomPass(new THREE.Vector2(w, h), strength, radius, threshold));
composer.addPass(new ShaderPass(MyCustomShader));

// In the loop:
composer.render();   // not renderer.render() anymore

Three new concepts:

  • RenderPass(scene, camera) — must be first. Renders your scene into a texture.
  • UnrealBloomPass — Three.js built-in. We use it as-is.
  • ShaderPass(shaderObject) — lets you author your own. The shader object has the same shape as a ShaderMaterial (uniforms + vertex + fragment), with one twist: it MUST have a uniform named tDiffuse — that's the input texture from the previous pass, which Three.js auto-injects.

Authoring a custom ShaderPass

const ChromaticAberrationShader = {
  uniforms: {
    tDiffuse: { value: null },        // auto-injected by Three.js
    uOffset:  { value: 0.005 },
  },
  vertexShader: /*glsl*/`
    varying vec2 vUv;
    void main() {
      vUv = uv;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
    }
  `,
  fragmentShader: /*glsl*/`
    uniform sampler2D tDiffuse;
    uniform float uOffset;
    varying vec2 vUv;
    void main() {
      float r = texture2D(tDiffuse, vUv + vec2(uOffset, 0.0)).r;
      float g = texture2D(tDiffuse, vUv).g;
      float b = texture2D(tDiffuse, vUv - vec2(uOffset, 0.0)).b;
      gl_FragColor = vec4(r, g, b, 1.0);
    }
  `,
};

The pattern is identical to a normal ShaderMaterial — same uniform declarations, same vertex/fragment GLSL. The only fixed convention is the tDiffuse uniform name.

Pass 1 — Raw scene

Just RenderPass(scene, camera). The base — your scene as it would look without any post.

For the demo we build a small scene: a rotating torus knot, a glowing sphere, a cube. The sphere is given a bright emissive color so bloom has something obvious to grab onto.

Pass 2 — Bloom

Bloom takes bright pixels and bleeds them outward. Every Apple Store ad. Every game with magic. Every neon sign.

new UnrealBloomPass(
  new THREE.Vector2(w, h),    // resolution
  0.8,                         // strength: how much bloom to add back
  0.4,                         // radius: how far it spreads
  0.85                         // threshold: only pixels brighter than this contribute
);

Three.js ships this. We use it as-is. The threshold is the most important parameter — too low and EVERYTHING blooms (washes out the image); too high and nothing does.

Building your own bloom from scratch: render the scene → extract bright pixels (threshold) → downsample several times → Gaussian blur each downsampled level → upsample and accumulate → add to the original. Six passes for one effect. The built-in UnrealBloomPass does this internally and is ~300 lines of Three.js source code. Worth reading once.

Pass 3 — Chromatic aberration

Real camera lenses don't focus all wavelengths to the same point. Result: color fringing at the edges of high-contrast regions. We fake it by sampling the input texture with slightly offset coordinates per channel.

// FRAGMENT
uniform sampler2D tDiffuse;
uniform float uOffset;
varying vec2 vUv;

void main() {
  float r = texture2D(tDiffuse, vUv + vec2(uOffset, 0.0)).r;
  float g = texture2D(tDiffuse, vUv).g;
  float b = texture2D(tDiffuse, vUv - vec2(uOffset, 0.0)).b;
  gl_FragColor = vec4(r, g, b, 1.0);
}

Tune uOffset in the range 0.003 to 0.01. Higher than that and the image looks like a glitch.

For radial aberration (more at edges, none at center), scale the offset by distance from center:

vec2 c = vUv - 0.5;
vec2 offset = c * length(c) * uOffset * 4.0;
float r = texture2D(tDiffuse, vUv + offset).r;
// ...

Pass 4 — Vignette

Darkens the corners. Sells "cinematic." Every movie ever.

// FRAGMENT
uniform sampler2D tDiffuse;
uniform float uInner;     // e.g., 0.3
uniform float uOuter;     // e.g., 1.0
varying vec2 vUv;

void main() {
  vec3 col = texture2D(tDiffuse, vUv).rgb;
  float d = length(vUv - 0.5);
  float vig = smoothstep(uOuter, uInner, d);
  col *= vig;
  gl_FragColor = vec4(col, 1.0);
}

The smoothstep(uOuter, uInner, d) with uInner < uOuter is REVERSED — it returns 1.0 at small d (center, full brightness) and 0.0 at large d (corners, full darkness). Multiply the input color by that mask.

Pass 5 — Pixelation

Snap UVs to a coarse grid, sample the texture at the snapped position.

// FRAGMENT
uniform sampler2D tDiffuse;
uniform vec2 uResolution;
uniform float uPixelSize;     // in pixels, e.g., 6.0
varying vec2 vUv;

void main() {
  vec2 d = uPixelSize / uResolution;
  vec2 uv = floor(vUv / d) * d + d * 0.5;
  gl_FragColor = texture2D(tDiffuse, uv);
}

uPixelSize = 4.0 looks like console-era 480p upscaled. uPixelSize = 16.0 looks like an Atari. Tune to taste.

Pass order matters

The chain we use:

RenderPass
  → UnrealBloomPass
  → ChromaticAberrationPass
  → VignettePass
  → PixelationPass

If you reorder, the look changes:

  • Pixelation BEFORE bloom → pixelated source, then bloom blurs the pixels. Looks like a CRT.
  • Pixelation AFTER bloom → bloom first, then pixelated. Looks like a low-res screenshot of a bloomed image. Lower fidelity.
  • Vignette before bloom → the dark corners don't bloom (they're dark, no bright pixels). Vignette after bloom → the bloom that spills into the corners gets darkened too. Subtle, but visible.

Common pitfalls

  • Used renderer.render() in the loop instead of composer.render(). The post-processing chain never runs. The scene renders direct to screen, bypassing all passes.
  • Wrong tDiffuse name. The convention is rigid. Three.js's ShaderPass looks for a uniform named exactly tDiffuse.
  • Resize handler doesn't call composer.setSize(). Window resize → distorted output.
  • Pixel ratio not set. Add composer.setPixelRatio(dpr) alongside the renderer's.
  • Bloom threshold too low. The whole image blooms; everything washes out. Push to 0.85 or higher for stylized cinematic; drop to 0.5 for game look.

Exercises

  1. Add a color grading pass (LUT or a simple col = pow(col, vec3(1.2)) contrast bump).
  2. Build a "threshold glow" as a cheaper bloom alternative — just brighten pixels above a threshold, blur cheaply, add back. Compare cost vs UnrealBloomPass.
  3. Add film grain via the Episode 05 hash function: col += (hash(vUv + uTime) - 0.5) * 0.05;.

What's next — the end of the canonical series

That's Season 1 (Eps 01-08) and Season 2 (Eps 09-16) — a 16-episode literacy track from "what is a shader" to "build a chromatic-aberration post pass."

What lives beyond:

  • Raymarching — full SDF scenes rendered by stepping rays through a distance field. Shadertoy's true native language.
  • Compute & WebGPU / TSL — GPU-side simulation, GPGPU particle systems, the new declarative shader graph.
  • Production shaders — onBeforeCompile patches into Three.js's PBR materials, custom lighting models that integrate cleanly with the renderer's standard pipeline.

If you've made it here, you have the toolkit. Go make something.