Why does deferred shading handle transparent surfaces and MSAA poorly, and how does a deferred renderer still draw glass and anti-aliased edges?
answer
- one surface per pixel
- a pass after opaque lighting
- samples multiply every target
- averaged attributes light wrongly
- find the edges, shade them per sample
basics
~20 sA 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.
solid answer
~50 sDeferred lighting reads one set of attributes per pixel: the nearest opaque surface. Glass needs two lit surfaces at that pixel, itself and what lies behind it, blended together, and the G-buffer has nowhere to put the second. So deferred renderers light opaques first, then draw transparent surfaces in a forward pass, depth-tested against the opaque depth and blended over the lit result, using the same lighting functions and light lists so glass and walls match. MSAA breaks a different assumption: the G-buffer must keep every sample, multiplying its memory and bandwidth by the sample count, and it cannot be resolved before lighting, because an averaged normal or depth belongs to no real surface. Renderers detect edge pixels and light those per sample and the rest per pixel, or skip MSAA for post-process or temporal anti-aliasing.
go deeper
Recall that a G-buffer keeps one surface per pixel, so deferred frames draw glass in a separate forward pass after the opaque lighting.
Explain why resolving a multisampled G-buffer before lighting is wrong, and how edge pixels are found and lit per sample while the rest are lit once.
Weigh the memory of a multisampled G-buffer against post or temporal anti-aliasing, and keep the forward transparent pass's lighting and light lists identical to the deferred path.
Decide early whether the project needs hardware MSAA, for thin geometry or head-mounted displays, because that requirement pushes the shading architecture toward forward.
## The one-surface assumption A deferred renderer's lighting pass reads one set of surface attributes per pixel from the **G-buffer**: the nearest opaque surface that won the depth test. Two common needs break that assumption: - **Transparency** needs more than one surface per pixel. - **Multisample anti-aliasing (MSAA)** needs more than one sample per pixel. Picture a night-market stall: a glass display case lit by strings of small lights, with thin awning cables against a bright sign behind them. ## Transparency: a forward pass in a deferred frame A glass pane in front of the stall needs two lit surfaces at the same pixel, the glass and what lies behind it, and then a blend of the two. The G-buffer has room for one. Writing the glass into it erases the surface behind; leaving it out leaves the glass unlit. So deferred renderers draw transparent surfaces in a separate stage: 1. The geometry pass writes the opaque G-buffer. 2. The lighting pass lights the opaque surfaces into the lit HDR target. 3. A **forward pass** draws transparent meshes on top, depth-tested against the opaque depth buffer with depth writes off. Each fragment computes its own lighting and blends over the lit result. How the transparent layers are ordered and blended is a subject of its own. 4. Post-processing runs on the combined image. Two consequences matter: - **Two lighting paths must match.** The forward pass needs the same BRDF, light types, shadows and probes as the deferred pass, or glass and walls under the same lantern look lit differently. Teams share the lighting functions between both paths. - **Light lists must cover the glass.** If lighting uses per-tile light lists culled against each tile's opaque depth range, a lantern hanging between the glass and the stall can be culled away, because it never reaches the opaque pixels. The transparent pass needs lists whose depth range starts at the near plane, or clustered lists that do not depend on opaque depth. ## MSAA: why sample storage multiplies With MSAA the rasteriser tests coverage at several sample positions per pixel. In forward rendering the fragment program normally runs once per pixel per triangle and its result is copied to the covered samples; at the end a **resolve** averages each pixel's samples. In a deferred renderer the G-buffer itself must keep every sample, because at an edge the samples belong to different surfaces: - A 20-byte-per-pixel G-buffer at 2560x1440 is 3,686,400 x 20 bytes, about 74 MB. With 4x MSAA it is about 295 MB, and every pass that touches it moves four times the data. - You cannot resolve the G-buffer before lighting. Lighting is not linear in its inputs: an averaged normal or depth at the edge between a cable and the bright sign describes a surface that is in neither, and lighting it produces halos along the very edges MSAA should clean up. Light the samples first, then resolve the lit colour. ## Lighting per sample only where needed Shading every sample of every pixel would multiply lighting cost by the sample count. Most pixels lie inside one surface, so all their samples hold the same attributes. Renderers classify: 1. Detect **edge pixels** whose samples differ, by comparing sample depths and normals or by checking coverage, and mark them in a stencil mask or a per-tile list. 2. Light non-edge pixels once, from one sample. 3. Light edge pixels once per sample, then average the lit samples. Edge pixels are usually a small fraction of the screen, but dense cables, foliage and fences can raise it sharply, and keeping per-sample work efficient on the GPU takes care. | Approach | Memory | Edge cost | Result | |---|---|---|---| | Multisampled G-buffer with edge classification | G-buffer times sample count | per-sample lighting on edge pixels | geometric anti-aliasing | | No MSAA, post-process or temporal anti-aliasing | single-sample G-buffer | one screen-space pass | depends on the filter; thin features may shimmer | | Forward or clustered forward with MSAA | multisampled colour and depth only | shaded once per pixel per triangle | native MSAA | Many deferred renderers therefore skip MSAA and rely on post-process or temporal anti-aliasing instead. ## How forward-style designs differ Forward shading with per-tile or per-cluster light lists avoids both problems in this form. MSAA works as the hardware intends, because only colour and depth are multisampled, and transparent meshes are just more forward draws that read the same clustered light lists. That is one reason projects that need hardware MSAA, such as those with much thin geometry or targeting head-mounted displays, often prefer a forward architecture.
- Why can't a deferred renderer resolve its multisampled G-buffer to one sample per pixel before lighting?Resolving averages attributes, and lighting is not linear in them. At the edge between a thin cable and a bright sign, the averaged normal and depth describe a surface that exists in neither, and the reconstructed position floats between them. Lighting that produces halos along exactly the edges MSAA was meant to fix. Light each sample first, then resolve the lit colours.
- In a tiled deferred frame, why might a glass pane miss a light hanging between it and the opaque wall behind it?Per-tile light lists are usually culled against the depth range of the opaque pixels in the tile. A lantern between the glass and the wall may not reach that range, so it is culled even though it lights the glass. Clustered lists, or a second per-tile list whose range starts at the near plane, give the transparent pass the lights it needs.
- A G-buffer can store a glass pane and the wall behind it at the same pixel.
- Deferred renderers cannot draw transparent surfaces at all.
- You can resolve a multisampled G-buffer before lighting without visible errors.
- MSAA on a G-buffer costs no more memory than MSAA on one colour target.
- Lighting every sample of every pixel is the only correct way to combine MSAA with deferred.