skip to content

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%

answer

  1. assign lights per screen region
  2. depth pre-pass gives bounds
  3. tile frustum versus light sphere
  4. silhouettes stretch the depth range
  5. exponential slices in view depth

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.

solid answer

~50 s

Forward+ runs a depth pre-pass, then a compute pass over screen tiles of, say, 16x16 pixels. Each tile reduces its depths to a minimum and maximum view distance, builds a small frustum from the tile's four side planes and that range, and tests every light's bounding sphere against it, writing survivors' indices into a per-tile list. The forward pass then loops only over its tile's list. The weakness is depth discontinuity: a tile holding a near lantern post and the far end of the street spans almost the whole depth range, so it keeps lights that touch none of its pixels. Clustered shading divides the view frustum into tiles times depth slices, usually spaced exponentially, assigns lights per cluster, and each fragment finds its cluster from screen position and view depth. Cluster bounds need no depth buffer, so transparent surfaces can use them too.

code

pseudocode · 19 lines
pseudocode
// Forward+ light culling for one 16x16 tile, written serially for clarity
// depth is view-space distance: larger means farther from the camera
function cullTile(tile):
    zMin = +infinity
    zMax = 0
    for each pixel p in tile:
        z = viewDepth(depthBuffer[p])
        if z < zFar:                        // skip sky pixels
            zMin = min(zMin, z)
            zMax = max(zMax, z)
    if zMin > zMax:                         // the tile sees only sky
        tileLights[tile] = empty
        return
    planes = sidePlanes(tile) + [planeAtDepth(zMin), planeAtDepth(zMax)]
    list = empty
    for each light L in visibleLights:
        if sphereNotOutsideAnyPlane(planes, L.center, L.radius):
            append L.index to list
    tileLights[tile] = list

go deeper

for a junior

Recall that Forward+ gives each screen tile a short list of the lights that can reach it, and the shading pass loops only over that list.

for a middle

Walk through the depth pre-pass, the per-tile depth reduction, the sphere-against-tile-frustum test and the offset-and-count layout of the shared index list.

for a senior

Diagnose silhouette tiles with a lights-per-tile heat map, and justify depth bins or clusters, tile size and list capacity from the scene's worst view.

for a principal

Treat the light-list method as separate from the shading architecture; one clustered list can feed forward, deferred and transparent passes across platforms.

## The problem: hundreds of small lights A night market under a few hundred small lights is the worst case for per-object light assignment: big meshes overlap many lights, yet each pixel is reached by only a handful. The fix is to assign lights per **screen region** rather than per object, and have each pixel loop over its region's short list. ## Forward+ step by step **Forward+**, or tiled forward shading, builds those lists every frame on the GPU. Depth below means view-space distance, growing away from the camera. 1. **Depth pre-pass.** Draw opaque geometry writing only depth. This gives the culling pass the visible depth of every pixel, and lets the later shading pass test depth for equality so hidden fragments are not shaded. 2. **Per-tile depth bounds.** Split the screen into tiles, for example 16x16 pixels; at 2560x1440 that is 160 x 90 = 14,400 tiles. One compute workgroup per tile reduces its pixels' depths to a minimum and maximum, skipping sky pixels. 3. **Tile frustum.** The tile's four edges give four side planes through the camera, and the depth bounds give a near and a far plane. Together they enclose the space where this tile's visible surfaces lie. 4. **Cull lights.** Test each light's bounding sphere, or a cone for a spot light, against the six planes. The intersection test itself is ordinary geometry. 5. **Write the lists.** Surviving light indices go into one shared index buffer, and each tile records an offset and a count into it. 6. **Shade.** The forward pass draws the scene; each fragment finds its tile from its pixel position and loops only over that tile's lights. ## The depth discontinuity problem A tile that sees one surface has tight bounds and a short list. A tile that straddles a silhouette does not: one covering the edge of a near lantern post and the far end of the street has a depth range from a few metres to hundreds of metres, so its frustum is long and keeps lights all along the street, though its pixels are near few of them. A heat map of lights per tile lights up along silhouettes. Mitigations: - **Depth bins inside the tile.** Divide each tile's depth range into, say, 32 bins, record which bins hold pixels in a bitmask, and keep a light only if it overlaps an occupied bin. - **Smaller tiles**, at the cost of more culling work and more list memory. - **Clustering**, described next. ## Clustered shading **Clustered shading** divides the view frustum in three dimensions: screen tiles times **depth slices**. Each cluster is a small segment of the frustum, and each light is assigned to the clusters its bounds overlap. - Slices are usually spaced **exponentially** in view depth, so clusters keep roughly the same proportions near and far: `slice = floor(log(z / zNear) / log(zFar / zNear) * numSlices)`. - Cluster bounds come from the grid alone, not from the depth buffer, so lists can be built without a depth pre-pass, even on the CPU, and they serve **transparent** surfaces, which are absent from the opaque depth buffer. - An optional step marks only the clusters that contain visible pixels, so culling can skip empty ones. - Each fragment computes its cluster from its pixel position and view depth and loops over that cluster's list. | | Forward+ tiles | Clustered | |---|---|---| | Region | 2D screen tile, depth bounds from the depth buffer | 3D cell: screen tile times depth slice | | Needs a depth pre-pass | yes, for the bounds | no; optional, to skip empty clusters | | Depth discontinuities | inflate lists along silhouettes | limited to one slice's depth range | | Transparent surfaces | need a separate list or range | use the same lists | | Memory | one list per tile | one list per cluster, many more cells | ## Where each fits Both methods build light lists; neither decides how surfaces are stored. The same per-tile culling drives **tiled deferred** shading, where one compute pass reads each pixel's G-buffer once and loops over its tile's lights, and the same clustered lists can feed a deferred opaque pass, a forward transparent pass and volumetric effects alike. In production, size list capacity for the worst view rather than the average, and keep a debug view of lights per tile or cluster: silhouettes, overflow and oversized light ranges show up immediately, and shortening light ranges is often the cheapest fix of all.

  • Why are cluster depth slices usually spaced exponentially rather than evenly?
    Under perspective a cluster's width grows with distance. With even slices, near clusters are long and narrow and far clusters are wide, flat slabs, so light counts per cluster vary wildly. Exponential spacing keeps each slice's depth proportional to its distance, so clusters stay similarly shaped. Because exponential slices near the camera become very thin, many renderers make the first slice deep and start the exponential spacing beyond it.
  • What should a Forward+ renderer do about a tile whose light list exceeds its capacity?
    With a fixed per-tile array, lights past the cap are silently dropped and pop as the camera moves. Safer layouts write variable-length lists into one shared index buffer with a per-tile offset and count, sized for a measured worst case, and report or visualise overflow in development builds. Tighter light ranges, smaller tiles or depth bins reduce the counts that overflow in the first place.
  • Can tiled light culling be used with deferred shading too?
    Yes. Tiled deferred runs the same per-tile culling in a compute pass, then in that same pass reads each pixel's G-buffer once and loops over the tile's lights, writing the lit colour once. That removes classic deferred's per-light re-reads of the G-buffer, which shows that the light-list method and the shading architecture are separate decisions.

Tile light lists work like a notice board on each block of a city that lists only the street lamps whose light reaches that block, so a resident reads one short board instead of the city's whole lamp register. Clustered shading cuts each block into near, middle and far stretches with their own boards, so a lamp at the far end is not listed for someone standing at the near end.

  • Forward+ tests every light against every pixel during the shading pass.
  • Tile depth bounds come from the transparent surfaces in the tile.
  • Smaller tiles always make the whole frame faster.
  • Clustered shading cannot work without a depth pre-pass.
  • Even depth slices give every cluster the same shape and volume.