---
id: "deferred-shading"
title: "Deferred shading (G-buffer)"
aliases: [deferred rendering, G-buffer rendering]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot]
year_introduced: 1988
inputs: [mesh, material-params]
outputs: [gbuffer, radiance]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Saito & Takahashi, 1990"
url: "https://texelatlas.vercel.app/t/deferred-shading/"
sources_verified_at: "2026-11-29"
---
# Deferred shading (G-buffer) (Saito & Takahashi, 1990)

> Rasterize geometry once into several screen-sized attribute targets, then run lighting as a separate screen-space pass so shading cost scales with pixels and lights, not with overdraw.

## Reach for it when

- many dynamic lights make forward rendering too slow
- pixel shader cost explodes with overdraw and lights
- need normals and depth for screen-space effects for free
- thousands of small point lights in a scene
- lighting cost should scale with pixels not geometry

## How it works

Pass one renders every opaque mesh into a set of render targets, the G-buffer, storing per-pixel what lighting later needs: depth, a packed normal, albedo, roughness, metalness, sometimes emissive and a material id. No lighting is evaluated here, so overdraw only costs attribute writes.

Pass two reads those targets and evaluates lighting per pixel. Each light is drawn as a proxy (full-screen quad, sphere, cone) or batched by tiles, and its contribution is accumulated additively into an HDR target, with position reconstructed from depth. Because each visible pixel is shaded once per light, hundreds of small lights become affordable.

Transparent surfaces, which have no single attribute set per pixel, are handled in a separate forward pass afterwards.

## When to use it

Choose it when a scene has many dynamic lights and mostly opaque surfaces, and you want screen-space effects (SSAO, SSR, decals) that need normals and depth anyway. Prefer [Clustered forward shading](https://texelatlas.vercel.app/t/clustered-forward-shading.md) when you need MSAA, many transparents, or tight bandwidth on mobile. Prefer [Tiled deferred shading](https://texelatlas.vercel.app/t/tiled-deferred-shading.md) as the scaling step once the light count makes per-light proxies expensive. Prefer [Visibility buffer rendering](https://texelatlas.vercel.app/t/visibility-buffer.md) when G-buffer bandwidth or material-count fragmentation is the bottleneck.

## Cost

medium — Dominated by G-buffer bandwidth (4-6 targets at full resolution) rather than ALU; qualitative, no source-specific numbers.
Measured GPU Weight: 66.6× baseline (extreme) — 2.1913 ms median / 2.284 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 61.6× baseline (extreme) — 0.9795 ms median (2.24× faster on L4).
Ampere A100 scaling: 42× baseline (heavy) — 1.2096 ms median (1.81× faster on A100).

## Failure modes

- Hardware MSAA is awkward: multisampled G-buffers multiply bandwidth, so engines fall back to post-process AA and get shimmering sub-pixel edges
- Transparency, hair and foliage with alpha need a second forward path with different lighting, so the two look slightly different
- Packing normals and material data into few channels causes banding in smooth gradients and limits material variety (one BRDF per pass)
- Bandwidth blows up on tile-based mobile GPUs unless the G-buffer stays in on-chip memory
- Light proxy overdraw becomes the new bottleneck with large overlapping lights

## Engine support

- blender: builtin — `EEVEE Next default opaque lighting runs through DeferredPipeline with multi-layer G-buffer closures` (evidence: https://github.com/blender/blender/blob/main/source/blender/draw/engines/eevee/eevee_pipeline.cc, checked 2026-12-01)
- unity: builtin — `HDRP Asset > Lit Shader Mode = Deferred (or Both); URP Renderer > Rendering Path = Deferred` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.render-pipelines.high-definition/Documentation~/Forward-And-Deferred-Rendering.md, checked 2026-12-01)
- unreal: builtin — `Default renderer is deferred; optional Forward Shading Renderer in Project Settings > Rendering` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/forward-shading-renderer-in-unreal-engine, checked 2026-12-01)
- webgpu: builtin — `GPURenderPassDescriptor.colorAttachments (up to maxColorAttachments=8 MRT targets in one pass)` (evidence: https://www.w3.org/TR/webgpu/, checked 2026-12-01) — Hardware MRT G-buffer output is native; lighting pass is authored in WGSL.

## Dataflow

- Inputs: mesh, material-params
- Outputs: gbuffer, radiance
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot

## Presets

### Deferred shading — G-buffer (albedo, normals, depth) split vs multi-light pass (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_LIGHT_COUNT": 12,
  "P_LIGHT_RADIUS": 1.4,
  "P_SPECULAR": 0.8,
  "P_GBUF_SPLIT": 0.44
}
```

```glsl
const float P_LIGHT_COUNT = 12.0; // P Point Lights [2.0, 16.0, 1.0]
const float P_LIGHT_RADIUS = 1.4; // P Light Radius [0.4, 2.8, 0.05]
const float P_SPECULAR = 0.8; // P Specular Gain [0.0, 2.0, 0.05]
const float P_GBUF_SPLIT = 0.44; // P G-Buffer Split [0.0, 1.0, 0.02]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

float sdTorus(vec3 p, vec2 t) {
  vec2 q = vec2(length(p.xz) - t.x, p.y);
  return length(q) - t.y;
}

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Returns vec2(distance, materialId)
vec2 mapScene(vec3 p) {
  vec2 res = vec2(p.y + 0.85, 1.0); // Floor

  // Central sculpted torus
  vec3 q = p - vec3(0.0, 0.05, 0.0);
  q.xy = rot2(iTime * 0.35) * q.xy;
  q.yz = rot2(0.55) * q.yz;
  float dT = sdTorus(q, vec2(0.68, 0.24));
  if (dT < res.x) res = vec2(dT, 2.0);

  // Orbiting chrome spheres
  for (int i = 0; i < 4; i++) {
    float a = float(i) * 1.5708 + iTime * 0.4;
    vec3 sp = vec3(cos(a) * 1.45, -0.45 + 0.18 * sin(iTime * 1.2 + float(i)), sin(a) * 1.45);
    float dS = length(p - sp) - 0.32;
    if (dS < res.x) res = vec2(dS, 3.0);
  }

  // Architectural rear pillars
  vec3 rp = p - vec3(0.0, 0.0, -2.2);
  rp.x = mod(rp.x + 1.2, 2.4) - 1.2;
  float dP = sdBox(rp, vec3(0.28, 2.0, 0.28)) - 0.04;
  if (dP < res.x) res = vec2(dP, 4.0);

  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.002, 0.0);
  return normalize(vec3(
    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
  ));
}

vec3 hsv2rgb(float h, float s, float v) {
  vec3 p = abs(fract(vec3(h) + vec3(0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0);
  return v * mix(vec3(1.0), clamp(p - 1.0, 0.0, 1.0), s);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  vec2 screenUV = fragCoord / iResolution.xy;

  vec3 ro = vec3(0.0, 0.85, 3.6);
  vec3 ta = vec3(0.0, -0.1, 0.0);
  vec3 ww = normalize(ta - ro);
  vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
  vec3 vv = cross(uu, ww);
  vec3 rd = normalize(uv.x * uu + uv.y * vv + 1.45 * ww);

  // Geometry pass: populate G-buffer (albedo, world normal, linear depth, roughness)
  float t = 0.0;
  float matId = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    vec2 h = mapScene(ro + rd * t);
    if (h.x < 0.002) { matId = h.y; hit = true; break; }
    t += h.x;
    if (t > 16.0) break;
  }

  vec3 gAlbedo = vec3(0.03, 0.04, 0.06);
  vec3 gNormal = vec3(0.0, 0.0, 1.0);
  float gRough = 0.5;
  float gDepth = clamp(t / 12.0, 0.0, 1.0);
  vec3 lit = vec3(0.02, 0.025, 0.04);

  if (hit) {
    vec3 p = ro + rd * t;
    gNormal = calcNormal(p);
    if (matId < 1.5) {
      vec2 chk = floor(p.xz * 1.4);
      float m = mod(chk.x + chk.y, 2.0);
      gAlbedo = mix(vec3(0.18, 0.19, 0.22), vec3(0.46, 0.48, 0.52), m);
      gRough = mix(0.28, 0.52, m);
    } else if (matId < 2.5) {
      gAlbedo = vec3(0.84, 0.78, 0.72);
      gRough = 0.22;
    } else if (matId < 3.5) {
      gAlbedo = vec3(0.75, 0.82, 0.88);
      gRough = 0.14;
    } else {
      gAlbedo = vec3(0.48, 0.50, 0.56);
      gRough = 0.58;
    }

    // Lighting pass: accumulate N deferred point lights solely from G-buffer attributes
    lit = gAlbedo * vec3(0.06, 0.07, 0.11);
    int nLights = int(clamp(P_LIGHT_COUNT, 1.0, 16.0));
    float lRad = max(P_LIGHT_RADIUS, 0.25);
    float specGain = max(P_SPECULAR, 0.0);
    vec3 v = -rd;

    for (int i = 0; i < 16; i++) {
      if (i >= nLights) break;
      float fi = float(i);
      float ang = fi * 0.3927 * 1.6 + iTime * (0.45 + 0.05 * mod(fi, 3.0));
      float rOrbit = 0.85 + 0.95 * sin(fi * 1.9 + iTime * 0.3);
      vec3 lPos = vec3(cos(ang) * rOrbit, -0.35 + 0.75 * abs(sin(fi * 1.3 + iTime * 0.7)), sin(ang) * rOrbit);
      vec3 lCol = hsv2rgb(fract(fi * 0.13 + 0.05), 0.82, 1.0);

      vec3 toL = lPos - p;
      float dist = length(toL) + 1e-4;
      vec3 l = toL / dist;
      float att = pow(clamp(1.0 - dist / (lRad * 2.2), 0.0, 1.0), 2.0) / (0.18 + dist * dist);

      float ndl = max(dot(gNormal, l), 0.0);
      vec3 h = normalize(l + v);
      float shininess = mix(96.0, 10.0, gRough);
      float spec = pow(max(dot(gNormal, h), 0.0), shininess) * specGain;
      lit += lCol * att * (gAlbedo * ndl * 1.5 + vec3(spec) * 1.2);
    }
  }

  // Visualize light volumes as subtle glowing sprites in the deferred composite
  int nLightsVis = int(clamp(P_LIGHT_COUNT, 1.0, 16.0));
  for (int i = 0; i < 16; i++) {
    if (i >= nLightsVis) break;
    float fi = float(i);
    float ang = fi * 0.3927 * 1.6 + iTime * (0.45 + 0.05 * mod(fi, 3.0));
    float rOrbit = 0.85 + 0.95 * sin(fi * 1.9 + iTime * 0.3);
    vec3 lPos = vec3(cos(ang) * rOrbit, -0.35 + 0.75 * abs(sin(fi * 1.3 + iTime * 0.7)), sin(ang) * rOrbit);
    vec3 toL = lPos - ro;
    float proj = dot(toL, rd);
    if (proj > 0.0 && (!hit || proj < t)) {
      float perp = length(toL - rd * proj);
      vec3 lCol = hsv2rgb(fract(fi * 0.13 + 0.05), 0.78, 1.0);
      lit += lCol * exp(-perp * 26.0) * 1.1;
    }
  }

  // Split G-buffer diagnostic panel on the left: top = World Normals, middle = Albedo, bottom = Depth
  float splitX = clamp(P_GBUF_SPLIT, 0.0, 1.0);
  vec3 col = aces(lit);
  if (screenUV.x < splitX) {
    if (screenUV.y > 0.666) {
      col = hit ? (gNormal * 0.5 + 0.5) : vec3(0.08, 0.09, 0.14);
    } else if (screenUV.y > 0.333) {
      col = hit ? gAlbedo : vec3(0.06, 0.07, 0.09);
    } else {
      float dVis = hit ? pow(1.0 - gDepth, 1.8) : 0.0;
      col = vec3(dVis * 0.9, dVis * 0.95, dVis);
    }
    // Thin horizontal dividers between G-buffer rows
    if (abs(screenUV.y - 0.666) < 0.004 || abs(screenUV.y - 0.333) < 0.004) col = vec3(0.95);
  }
  if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) col = vec3(0.98, 0.86, 0.45);

  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Lineage

- extended by [Tiled deferred shading](https://texelatlas.vercel.app/t/tiled-deferred-shading.md)
- extended by [Visibility buffer rendering](https://texelatlas.vercel.app/t/visibility-buffer.md)

## Combines with

- [Tiled deferred shading](https://texelatlas.vercel.app/t/tiled-deferred-shading.md): Deferred's G-buffer is exactly what the tile light-culling pass reads depth from before accumulating lights.
- [Screen-Space Ambient Occlusion](https://texelatlas.vercel.app/t/ssao.md): The depth and normal targets written by the geometry pass feed screen-space AO with no extra rendering.

## Sources

1. [primary] Takafumi Saito, Tokiichiro Takahashi (1990) Comprehensible rendering of 3-D shapes. Proceedings of the 17th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/97879.97901 (verified via crossref on 2026-11-29)
2. [primary] Michael Deering, Stephanie Winner, Bic Schediwy, Chris Duffy, Neil Hunt (1988) The triangle processor and normal vector shader. Proceedings of the 15th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/54852.378468 (verified via crossref on 2026-11-29)
3. [talk] Shawn Hargreaves, Mark Harris Deferred Shading (GDC 2004). GDC 2004. https://www.nvidia.com/en-us/page-not-found (verified via http on 2026-11-29)

## Cite this entry

Texel. "Deferred shading (G-buffer)." https://texelatlas.vercel.app/t/deferred-shading/ (accessed 2026-12-01).
