Deferred shading

Also known as: deferred rendering

On this page 7

Deferred shading is a real-time rendering technique that splits drawing into two passes: a geometry pass that writes surface attributes of every visible pixel into a set of screen-sized textures called the G-buffer, and a lighting pass that reads those textures and computes illumination afterward. In Real-time 3D, it is also known as deferred rendering, and it became a standard approach in game engines because it decouples lighting cost from scene complexity.

The central idea is simple: shade only what the camera actually sees. Instead of evaluating every light for every fragment that might later be hidden, the renderer first resolves visibility with the Z-buffer and then spends lighting work once per visible pixel. This makes scenes with hundreds of dynamic lights practical, at the price of higher memory bandwidth and some restrictions on materials.

How deferred shading splits the frame

Deferred shading works by separating visibility from lighting. During the geometry pass, the vertex shader transforms meshes as usual, but the fragment shader does not calculate light. It writes material and surface data into multiple render targets at once, a capability that modern GPU pipelines support through MRT output.

During the lighting pass, the renderer draws screen-aligned shapes for each light: a full-screen quad for directional lights, and light volumes such as spheres or cones for point and spot lights. For every covered pixel, the lighting shader samples the G-buffer, reconstructs the world position from depth, and adds that light’s contribution to an accumulation buffer. A final composition pass then applies post-processing and tone mapping.

The following table lists a typical G-buffer layout. Exact formats differ between engines, and many renderers pack several attributes into one texture to save bandwidth.

Render targetStored dataCommon format
Depth bufferScene depth for position reconstructionD24S8 or D32F
Albedo targetBase color and ambient occlusionRGBA8
Normal targetEncoded surface normalRGB10A2 or RG16F
Material targetRoughness, metalness, specularRGBA8
Emissive or velocity targetSelf-illumination or motion vectorsRGBA16F or RG16F
Typical G-buffer contents and formats

Deferred shading compared with forward rendering

The main alternative is forward rendering, which computes lighting directly in the fragment shader while each object is drawn. In classic forward rendering, cost grows roughly with objects multiplied by lights, and overdraw wastes lighting work on fragments that are later hidden. Deferred shading changes this to cost that grows with visible pixels multiplied by lights affecting them.

Neither approach is universally better. The table summarizes the main engineering trade-offs that guide the choice.

CriterionForward renderingDeferred shading
Many dynamic lightsExpensive without clusteringEfficient by design
Memory bandwidthLowHigh, several full-screen targets
TransparencyHandled nativelyRequires a separate forward pass
Hardware MSAAStraightforwardCostly or impractical
Material varietyAny shading model per objectLimited by G-buffer layout
Screen-space effectsNeed an extra depth or normal prepassG-buffer data available for free
Forward rendering and deferred shading side by side

A useful side effect is that the G-buffer already contains depth and normals, so techniques such as screen space ambient occlusion and screen space reflections can reuse it without extra geometry passes.

Variants and modern refinements

Several variants address the bandwidth and material limits of the classic method. Engine developers usually pick a variant according to target hardware, light count and the importance of transparent or complex materials.

VariantCore ideaTypical use
Classic deferred shadingFat G-buffer, light volumesDesktop and console games
Deferred lighting (light prepass)Thin G-buffer, geometry drawn twiceOlder consoles with small memory
Tiled deferredLights culled per screen tile in a compute shaderScenes with hundreds of lights
Clustered deferredLights culled in 3D view-space clustersLarge depth ranges, open worlds
Visibility bufferStores triangle and instance IDs onlyDense geometry, high resolutions
Common variants of deferred techniques

Tiled and clustered approaches read the G-buffer once per pixel and loop over a short list of relevant lights, which greatly reduces repeated texture reads. On mobile GPUs with tile-based architectures, keeping the G-buffer in on-chip tile memory through subpasses avoids writing it to main memory at all, which makes deferred rendering viable on phones.

When to choose deferred shading

Deferred shading fits best when a scene has many local dynamic lights and mostly opaque surfaces. It is less attractive when bandwidth is scarce, when transparency dominates, or when the project depends on hardware antialiasing. The decision table below reflects common practice.

SituationRecommended pathReason
Night city with hundreds of lightsClustered or tiled deferredLighting cost scales with pixels
VR title needing sharp edgesForward or clustered forwardMSAA works without G-buffer cost
Mobile game with few lightsForward renderingSaves memory bandwidth and power
Browser scene in WebGLUsually forwardLimited render-target support and bandwidth
Mixed opaque and glass sceneHybrid deferred plus forwardTransparent objects drawn afterward
Choosing a rendering path

Most production engines are hybrid renderers: opaque geometry goes through a deferred path, while particles, glass, hair and other translucent elements are drawn in a forward pass on top of the lit result.

Limitations and common mistakes

The technique has well-known weaknesses that experienced graphics programmers plan around from the start. Ignoring them typically produces blurry edges, banding or poor performance on weaker hardware.

  • Transparency cannot be stored in a single-layer G-buffer, so translucent objects need a separate forward pass.
  • Antialiasing is usually handled with post-process methods such as FXAA or temporal antialiasing (TAA) rather than MSAA.
  • Low-precision normals cause visible banding in specular highlights; octahedral encoding in 16-bit channels reduces it.
  • Oversized light volumes waste fill rate; stencil or depth-bounds tests restrict lighting to pixels the light can reach.
  • Too many material models bloat the G-buffer; engines usually store a small material ID and branch in the lighting shader.

In everyday language

Imagine painting a room full of furniture. One way is to light each piece as you place it. You might then hide it behind a sofa and waste the effort. Deferred shading works differently. It first notes what is visible. It records the color, angle and material of every visible spot. Only then does it add the light.

This saves work when there are many lamps. Each lamp only touches the spots it can reach. The cost is extra memory. Glass and smoke are also harder to handle. The key takeaway is simple: decide what is seen first, then light it.

Seen in the real world

A small studio builds a rainy night street for a third-person action game on current consoles. The scene has neon signs, car headlights, shop windows and streetlamps, adding up to about 300 dynamic point and spot lights. A plain forward renderer would evaluate many of these lights for every mesh and drop well below the 60 frames per second target.

The team uses clustered deferred shading. The geometry pass fills a G-buffer at 1440p, a compute shader assigns lights to view-space clusters, and each pixel processes only the eight to twelve lights that actually reach it. Wet asphalt reuses the G-buffer for screen space reflections, while rain particles and glass are drawn in a forward pass afterward. The frame stays within its 16.6 ms budget, and artists can add lights freely without rebaking anything.