---
id: "clustered-forward-shading"
title: "Clustered forward shading"
aliases: [clustered shading, clustered forward]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity]
year_introduced: 2012
inputs: [depth, mesh]
outputs: [radiance]
style: "both"
dynamic: "both"
cost: "medium"
authority: "Olsson et al., 2012"
url: "https://texelatlas.vercel.app/t/clustered-forward-shading/"
sources_verified_at: "2026-11-29"
---
# Clustered forward shading (Olsson et al., 2012)

> Divide the view frustum into a 3D grid of clusters, assign each light to the clusters it overlaps, and let each shaded fragment loop only over its cluster's lights.

## Reach for it when

- too many dynamic lights tank the frame rate
- forward renderer needs hundreds of point lights
- need transparent objects lit by many lights
- deferred g-buffer is too heavy for msaa or vr

## How it works

The frustum is sliced into screen tiles and depth slices, usually exponential in depth. A compute pass tests each light's bounding volume against cluster bounds and writes light indices into per-cluster lists, optionally restricted to clusters containing visible geometry.

In the fragment shader, the pixel's position and depth give its cluster id; the shader reads that list and accumulates lighting. Unlike 2D tiling, depth splits mean far-apart surfaces at the same pixel do not share a long list, which handles depth discontinuities and transparent objects.

## When to use it

Choose it for many dynamic lights with forward rendering, MSAA or transparencies. Prefer [Tiled deferred shading](https://texelatlas.vercel.app/t/tiled-deferred-shading.md) when deferred is already in place and depth ranges per tile are tight. Prefer a handful of per-object lights when light count stays small.

## Cost

medium — Cost depends on lights per cluster and cluster count; the build pass is cheap relative to shading.
Measured GPU Weight: 9.75× baseline (moderate) — 0.3208 ms median / 0.3384 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 9.94× baseline (moderate) — 0.1581 ms median (2.03× faster on L4).
Ampere A100 scaling: 6.44× baseline (moderate) — 0.1855 ms median (1.73× faster on A100).

## Failure modes

- Large lights fall in many clusters, bloating lists and overflowing fixed list capacity
- Lights near cluster boundaries cause popping if bounds are too tight
- Slice distribution mismatched to scene depth leaves clusters under- or over-populated
- Per-fragment light loops diverge across a wavefront

## Engine support

- babylonjs: builtin — `new BABYLON.ClusteredLightContainer('c', lights, scene)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Lights/Clustered/clusteredLightContainer.ts, checked 2026-12-01)
- godot: builtin — `Project Settings > Rendering > Renderer > Rendering Method = forward_plus` (evidence: https://github.com/godotengine/godot-docs/blob/master/tutorials/rendering/renderers.rst, checked 2026-12-01)
- threejs: official — `import { ClusteredLighting } from 'three/addons/lighting/ClusteredLighting.js'` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/lighting/ClusteredLighting.js, checked 2026-12-01) — WebGPURenderer.
- unity: builtin — `URP Renderer > Rendering Path = Forward+` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs, checked 2026-12-01) — URP Forward+; HDRP uses its own tiled/cluster light list.
- unreal: builtin — `Project Settings > Rendering > Forward Renderer > Forward Shading (with MSAA support)` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/forward-shading-renderer-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: depth, mesh
- Outputs: radiance
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity

## Presets

### Toy top-down frustum clusters with per-cluster light counts (glsl-fragment; rendered 2026-11-29)

```json
{
  "LIGHTS": 14,
  "SLICES": 8,
  "BINS": 8,
  "HALF_FOV_TAN": 0.8
}
```

```glsl
// Toy top-down view of a frustum cut into clusters (angular bins x exponential depth slices); colour = lights overlapping each cluster.
const int LIGHTS = 14;
const int SLICES = 8;
const int BINS = 8;
const float NEAR = 0.1, FAR = 10.0;
const float HALF_FOV_TAN = 0.8;
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    vec2 v = vec2((uv.x - 0.5) * 2.0 * 3.2, 0.0);       // view-space x
    float z = 0.02 + uv.y * 0.0;                          // placeholder, set below
    // map screen y to depth with exponential spacing so slice cells look equal height
    float sl = uv.y * float(SLICES);
    z = NEAR * pow(FAR / NEAR, sl / float(SLICES));
    v.x = (uv.x - 0.5) * 2.0 * z * HALF_FOV_TAN;
    float bin = floor(uv.x * float(BINS));
    float s = floor(sl);
    float z0 = NEAR * pow(FAR / NEAR, s / float(SLICES)), z1 = NEAR * pow(FAR / NEAR, (s + 1.0) / float(SLICES));
    float t0 = (bin / float(BINS) - 0.5) * 2.0 * HALF_FOV_TAN, t1 = ((bin + 1.0) / float(BINS) - 0.5) * 2.0 * HALF_FOV_TAN;
    vec2 lo = vec2(min(min(t0 * z0, t0 * z1), min(t1 * z0, t1 * z1)), z0);
    vec2 hi = vec2(max(max(t0 * z0, t0 * z1), max(t1 * z0, t1 * z1)), z1);
    int cnt = 0; float lit = 0.0; float dm = 1e9;
    for (int i = 0; i < LIGHTS; i++) {
        float f = float(i);
        float lz = NEAR * pow(FAR / NEAR, fract(f * 0.381 + 0.1 * sin(iTime * 0.5 + f)) * 0.95 + 0.03);
        float lx = lz * HALF_FOV_TAN * (2.0 * fract(f * 0.618 + 0.2) - 1.0) * 0.9;
        float r = 0.35 * lz + 0.1;
        vec2 c = vec2(lx, lz);
        if (distance(clamp(c, lo, hi), c) < r) cnt++;
        lit += smoothstep(r, 0.0, distance(vec2(v.x, z), c));
        dm = min(dm, abs(distance(vec2(v.x, z), c) - r) / z);
    }
    float x = float(cnt) / 5.0;
    vec3 heat = clamp(vec3(1.5 * x, 1.5 - abs(3.0 * x - 1.5), 1.5 - 1.5 * x), 0.0, 1.0);
    vec3 col = mix(vec3(0.04, 0.05, 0.08), heat * 0.6, cnt > 0 ? 1.0 : 0.0);
    col += vec3(1.0, 0.9, 0.7) * lit * 0.15;
    vec2 g = fract(vec2(uv.x * float(BINS), sl));
    col = mix(col, vec3(0.0), (g.x < 0.03 || g.y < 0.03) ? 0.6 : 0.0);
    col = mix(col, vec3(1.0), smoothstep(0.012, 0.004, dm) * 0.8);
    fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}

```

Attribution: written for this index

## Lineage

- extends [Tiled deferred shading](https://texelatlas.vercel.app/t/tiled-deferred-shading.md)

## Combines with

- [Hierarchical-Z occlusion culling](https://texelatlas.vercel.app/t/hierarchical-z-occlusion-culling.md): A depth pre-pass used for cluster culling also feeds the pyramid used for object culling.

## Sources

1. [primary] Ola Olsson, Markus Billeter, Ulf Assarsson (2012) Tiled and clustered forward shading. ACM SIGGRAPH 2012 Posters on - SIGGRAPH '12. https://doi.org/10.1145/2343045.2343095 (verified via crossref on 2026-11-29)
2. [implementation] pezcode (2019) pezcode/Cluster. https://github.com/pezcode/Cluster License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Clustered forward shading." https://texelatlas.vercel.app/t/clustered-forward-shading/ (accessed 2026-12-01).
