skip to content

Shading Architectures

Forward, deferred, tiled and clustered shading compared: what a G-buffer stores, why deferred struggles with transparency and MSAA, how Forward+ culls lights per tile. A staple design question.

on this pageshow

explore

questions

6

In deferred shading, what is a G-buffer, what does it typically store per pixel, and why is it filled before any lighting runs?

level: juniorimportance: must knowfreq 55%

answer

  1. several render targets, one pass
  2. surface inputs, not lit colour
  3. colour, normal, roughness, depth
  4. position comes back from depth
  5. only the visible surface gets lit

basics

~20 s

A G-buffer is a set of screen-sized render targets that a deferred renderer's geometry pass fills with each visible pixel's surface attributes: depth, base colour, normal and material parameters. Lighting then reads them, so lights touch only visible surfaces.

solid answer

~40 s

The *G-buffer* (geometry buffer) is the output of deferred shading's first pass. Every opaque mesh is drawn once into several render targets at the same time, writing surface attributes rather than lit colour: base colour, a world- or view-space normal, material parameters such as roughness and metalness, often ambient occlusion and motion vectors, plus the depth buffer. Position is usually not stored; it is rebuilt from depth and the pixel's screen coordinates. Because the depth test has already kept only the nearest opaque surface per pixel when lighting starts, the lighting passes evaluate each light against one surface per pixel, and fragments hidden by overdraw never pay for lighting. Many layouts pack this into three to five 32-bit targets plus depth.

go deeper

for a junior

Name the attributes a G-buffer holds, say they are written in one geometry pass into several render targets, and explain that lighting reads them afterwards.

for a middle

Explain why position is rebuilt from depth, how a normal fits into two channels, and why overdraw now costs attribute writes but not lighting.

for a senior

Reason in bytes per pixel: every channel you add is written and read for every pixel at full resolution, so justify each one by the effects that need it.

for a principal

Treat the layout as a contract between materials, lighting and screen-space effects; changing it later touches every shader, so settle the material menu early.

## What a G-buffer is **Deferred shading** splits a frame into two stages. First a **geometry pass** draws every opaque mesh once and, instead of computing lit colour, writes the surface's properties into several screen-sized render targets at the same time (multiple render targets). Together those targets are the **G-buffer**, short for geometry buffer. Then one or more **lighting passes** read the G-buffer and compute how each light affects each pixel, writing the result into a separate lit colour target, usually a high-dynamic-range one. The word *deferred* means exactly this: lighting is postponed until the frame knows which surface is visible at every pixel. ## What it typically stores There is no standard layout. Each renderer packs what its materials and screen-space effects need into as few bytes as it can. A representative layout: | Target | Example format | Contents | |---|---|---| | Depth | 32-bit depth | distance used by the depth test, later used to rebuild position | | Target 0 | `RGBA8` | base colour (albedo) in RGB, ambient occlusion in A | | Target 1 | `RGB10A2` or `RG16` | surface normal, often packed into two channels | | Target 2 | `RGBA8` | roughness, metalness, a material or shading-model ID, a spare channel | | Target 3 | `RG16F` | screen-space motion vector for temporal effects | That is 4 + 4 + 4 + 4 + 4 = **20 bytes per pixel**. Common variations: - **Emissive** colour is either stored in its own target or written straight into the lit target during the geometry pass. - **Specular colour or reflectance** replaces metalness in renderers that use a specular workflow. - **Normals** are stored in world space or view space; packing them into two channels (for example with an octahedral mapping) saves a channel without losing much precision. - **Position is rarely stored.** It is rebuilt per pixel from the depth value, the pixel's screen coordinates and the inverse of the camera's projection, which costs a few instructions instead of 12 or more bytes of memory traffic per pixel. ## Why it is filled before any lighting The order is the whole point. A deferred frame runs: 1. **Geometry pass.** Draw opaque meshes with depth testing. Nearer surfaces overwrite farther ones, so when the pass ends each pixel holds exactly one surface: the visible one. 2. **Lighting pass or passes.** For each light, or for each pixel with a list of nearby lights, read the stored attributes, evaluate the material's lighting model and add the result to the lit target. 3. **Later passes.** Transparent surfaces, post-processing and other screen-space effects run on top. Because visibility is resolved first, lighting is evaluated only for surfaces that are actually seen. Where several meshes overlap a pixel, the hidden fragments still pay to write their attributes, but they never pay for lights. And because lighting reads a screen-space image rather than drawing meshes, its cost depends on how many pixels each light covers rather than on how many objects are in the scene. The same attributes feed other screen-space work too: ambient occlusion and reflections read depth and normals, and decals can modify the stored base colour or normal before lighting runs, so the decal is lit exactly like the surface under it. ## What it cannot hold The G-buffer keeps **one surface per pixel**, and that is its main limitation: - A glass pane and the wall behind it cannot both be stored, so transparent surfaces are drawn later in a separate forward pass. - Every material must express itself through the same few channels. A material that needs extra parameters, such as skin, hair or cloth, needs a shading-model ID and spare channels, and the lighting pass branches on that ID. - Each channel costs bandwidth at full resolution: every byte is written once and read at least once for every pixel on screen, every frame. ## Common mistakes - Describing the G-buffer as storing lit colour. It stores the inputs to lighting; the lit result goes to a different target. - Assuming one G-buffer layer per light. There is one set of targets for the frame, and every light reads it. - Storing world position as three floats out of habit, which spends bandwidth on data the depth buffer already implies. - Claiming deferred shading removes the cost of overdraw. It removes lighting from hidden fragments, not their vertex work or their attribute writes.

  • Why do most deferred renderers not store world position in the G-buffer?
    Position can be rebuilt per pixel from the depth value, the pixel's screen coordinates and the inverse of the camera's projection, so storing it spends 12 or more bytes per pixel on data the depth buffer already implies. Lighting passes are usually limited by memory bandwidth rather than arithmetic, so a few instructions to reconstruct position cost less than reading a three-float target for every pixel.
  • What happens when a material needs a parameter the G-buffer has no room for, such as subsurface scattering for skin?
    It needs a shading-model ID plus somewhere for its extra data, often by reinterpreting spare channels for that model only. The lighting pass then branches on the ID. Every new shading model either competes for the same few bytes or widens the G-buffer for every pixel on screen, which is why deferred renderers offer a short, fixed menu of material models.

  • The G-buffer stores the final lit colour of each pixel.
  • Each light writes its own separate G-buffer layer.
  • A G-buffer must store world position as three floats per pixel.
  • The G-buffer holds every surface along the view ray, transparent ones included.
  • Deferring lighting also removes the cost of overdraw from the geometry pass.
open as a page

Why does classic forward shading's cost grow with lights times objects, and how does deferred shading change that cost for scenes with many dynamic lights?

level: middleimportance: must knowfreq 58%

basics

~20 s

Classic forward shading lights each object while drawing it, so every fragment evaluates every light assigned to its object, hidden fragments included. Deferred shading writes surface attributes once, then applies each light only to the screen pixels it covers.

open as a page

Why does deferred shading handle transparent surfaces and MSAA poorly, and how does a deferred renderer still draw glass and anti-aliased edges?

level: middleimportance: should knowfreq 50%

basics

~20 s

A G-buffer stores one surface per pixel, so glass and the surface behind it cannot both be lit from it; deferred frames add a forward pass for transparents. MSAA multiplies G-buffer memory by the sample count and needs per-sample lighting at edges.

open as a page

On bandwidth-limited hardware, how do you estimate a deferred renderer's G-buffer memory traffic per frame at a given resolution, and how do you cut it?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Multiply bytes per pixel by pixel count, then count each write and read: geometry-pass writes, lighting reads, lit-target writes and per-light re-reads in classic deferred. Cut it with packed channels, position from depth, tiled lighting and on-chip G-buffers on tile-based GPUs.

open as a page

How does Forward+ build per-tile light lists for a night market lit by hundreds of small lights, and why does clustered shading also slice in depth?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Forward+ splits the screen into tiles, takes each tile's depth range from a depth pre-pass, and keeps only lights whose bounds meet that tile's frustum. Clustered shading also slices depth, so one foreground edge cannot pull in every light behind it.

open as a page

As rendering lead, how do you choose a project's shading architecture: deferred, Forward+ or clustered forward, or a visibility buffer?

level: principalimportance: should knowfreq 25%

basics

~20 s

No architecture wins everywhere, so choose from measured constraints. Deferred suits many lights, uniform materials and screen-space effects; clustered forward suits MSAA, varied materials and transparency; a visibility buffer suits very dense geometry. Prototype the worst scene on the weakest target.

open as a page