skip to content

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%

answer

  1. where lighting happens relative to the draw
  2. per-object light assignment
  3. hidden fragments lit anyway
  4. light footprint on screen
  5. bandwidth is the price

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.

solid answer

~40 s

In classic forward shading, lighting happens inside the draw. The CPU picks the lights that touch each object's bounds and either loops over them in one shader or redraws the object once per light with additive blending. Cost scales with objects times lights: a street-floor mesh under two hundred lanterns evaluates all two hundred for every fragment, even where three are in range, and fragments later hidden by overdraw were lit for nothing. Deferred shading splits the work. A geometry pass writes each visible pixel's attributes once; a lighting pass then shades each light over its screen footprint, so cost scales with the pixels each light covers, independent of object count and overdraw. The price is G-buffer memory and bandwidth, a fixed material menu, and awkward transparency and MSAA.

go deeper

for a junior

Recall that forward shading lights surfaces during the draw while deferred shading lights them afterwards from stored surface attributes.

for a middle

Explain both cost models, fragments times lights per object versus pixels times lights per pixel, and show where overdraw is paid in each.

for a senior

Name what deferred trades for its scaling, bandwidth, a fixed material menu, transparency and MSAA, and explain when forward with per-region light lists wins.

for a principal

Treat forward versus deferred as one input to the project's shading-architecture choice, weighed against target hardware, material variety and anti-aliasing policy.

## Classic forward shading: lighting inside the draw In **forward shading**, each mesh's fragment program computes the final lit colour while the mesh is being drawn. The renderer has to tell each draw which lights affect it, and there are two classic ways: - **Single pass with a light list.** The CPU picks the lights whose ranges touch the object's bounding volume and passes them as constant data; the fragment program loops over them. Different light counts or types are often compiled as separate shader variants, and a cap of a few lights per object bounds the loop. - **Multi-pass additive.** The object is drawn once per light, each pass blending its light's contribution on top of the previous ones. The geometry is transformed and rasterised again for every light. ## Where forward's cost comes from Picture a night market: a long street under a couple of hundred small string lights and lanterns, with stalls, awnings and crowds. - **Objects times lights.** Light assignment is per object, so an object costs roughly its shaded fragments times the lights assigned to it. A street-floor mesh that spans the whole market is touched by every light, so every one of its fragments evaluates all two hundred, even where only three are in range. Multi-pass forward is worse still: two hundred extra draws of that mesh. - **Overdraw.** Lighting runs for every fragment that is shaded, including ones later covered by something nearer. Without a depth pre-pass, a pixel shaded three times is lit three times. - **Caps and popping.** Capping lights per object bounds the worst case but drops lights, and as the camera or object moves the chosen set changes, so lights blink on and off across large meshes. - **Variants.** Compiling per light count and type multiplies the number of shader variants. ## Deferred shading: separate visibility from lighting **Deferred shading** splits the frame in two: 1. A **geometry pass** draws each opaque mesh once and writes surface attributes (depth, base colour, normal, roughness and so on) into the G-buffer. No lighting runs here. 2. A **lighting pass** applies each light only to the pixels it can reach. Classic deferred draws a proxy shape per light, such as a sphere for a point light, a cone for a spot light or a screen-space rectangle around either, and for each covered pixel reads the attributes, evaluates the light and adds the result into a lit target. Lighting cost is now roughly **the sum, over all lights, of the pixels each light covers**: screen pixels times the average number of lights per pixel. It no longer depends on how many objects there are or how the scene was split into meshes, and hidden fragments never pay for lighting because visibility was resolved first. ## Side by side | | Classic forward | Classic deferred | |---|---|---| | Lighting cost scales with | fragments shaded times lights per object | pixels covered, summed over lights | | Overdraw | lit again for each layer | only attribute writes repeat | | Light assignment | per object, often capped | per light, by screen footprint | | Memory per pixel | lit colour and depth | G-buffer of attributes plus a lit target | | Materials | any shader per material | must fit the shared G-buffer channels | | Transparency and MSAA | native | need extra work | ## What deferred gives up Deferred's scaling is not free: - **Bandwidth.** Every G-buffer byte is written and read for every pixel. Classic per-light deferred also re-reads the G-buffer and read-modify-writes the lit target for every light covering a pixel, so twenty overlapping lanterns mean twenty reads of the same attributes. - **A material menu.** All materials share one layout and one lighting pass, so unusual shading models need IDs, spare channels and branches. - **Transparency and MSAA.** The G-buffer keeps one surface per pixel, and keeping several samples per pixel multiplies its size. ## Where the field went next The modern answer for both families is a **per-region light list**: divide the screen into tiles, or the view volume into clusters, find which lights touch each region, and have each pixel loop only over its region's list. - Forward shading with such lists, often called Forward+ or clustered forward, keeps forward's strengths without per-object light assignment. - Deferred shading with such lists, tiled or clustered deferred, reads the G-buffer once per pixel instead of once per light. So "many lights" no longer settles forward versus deferred on its own. It is one input among bandwidth, material variety, transparency and anti-aliasing, and the per-region light list is a separate decision from how surfaces are stored.

  • Classic deferred draws a volume per light and blends into a lit target; what does that cost when many lights overlap?
    Each light's volume re-reads the G-buffer for every pixel it covers and read-modify-writes the lit target, so a pixel under twenty overlapping lanterns reads the same attributes twenty times. Bandwidth grows with overlap, which is why tiled and clustered deferred read the G-buffer once per pixel and loop over a short per-region light list instead.
  • Why do forward renderers often cap lights per object, and what does the cap look like on screen?
    Without per-pixel light lists, the shader loops over the lights assigned to the whole object, so a cap bounds the worst case and the number of variants per light count. Lights past the cap are dropped or folded into an approximation, and as the object or camera moves the chosen set changes, so lights visibly pop on and off large meshes.
  • Does deferred shading remove the cost of overdraw entirely?
    No. Overdraw still costs vertex work, fragment work for the attribute writes and G-buffer bandwidth for every fragment that passes the depth test when it is drawn. Deferred only stops lighting from being evaluated for surfaces that end up hidden. A depth pre-pass or rough front-to-back ordering reduces the remaining waste.

  • Deferred shading makes lighting free no matter how many lights touch a pixel.
  • Forward shading cannot light an object with more than one light.
  • Deferred lighting cost grows with the number of objects times lights.
  • Deferred shading uses less memory per pixel than forward shading.
  • Overdraw costs nothing at all in a deferred renderer.