exposure.renderFeature
This package holds more than this page lists. See all of its files in its world.
README.md
exposure
The render feature behind AutoExposure and
@builtin::systems.exposure.exposure. Two compute passes run in the meter
stage, on the picture the temporal resolve reconstructed:
| local order | pass | output |
|---|---|---|
| 0 | exposure_meter | 32x32 grid of tile log-luminances, weighted by the metering mask |
| 2 | exposure_adapt | the live exposure, moved toward the scene's reading |
Metering
exposure_meter gives each tile a slice of the frame and averages the
log-luminance across it, sampling every fourth pixel in each axis — a tile
covers hundreds of pixels and the result is an average, so sampling all of them
buys precision the eye cannot see at sixteen times the cost.
Averaging happens in log space. The eye's response is logarithmic and so is the quantity being averaged, which is why a few very dark pixels do not drag the whole frame's exposure up the way a linear average would.
The metering mask weights that average. Full metering reads everything; centre-weighted tapers to a floor at the frame edge; spot reads only the middle.
Adaptation
exposure_adapt runs as a single invocation, so there is one writer to the
state buffer and no ordering to arrange between workgroups. It reduces the tile
grid, works out the exposure that would land the average on targetGrey, and
moves the live value toward it.
The approach is exponential in dt, so the rate is independent of frame rate.
Rising and falling use different speeds on purpose: the eye adjusts to
brightness far faster than it adjusts to darkness.
The live exposure lives in the exposure_state buffer, written by the GPU and
read back the next frame — that persistence across frames is the whole
mechanism behind an image that settles rather than snaps. The buffer starts
zeroed, and a zero in its "initialised" slot tells the first frame to settle on
its reading immediately instead of adapting up from an exposure the scene never
had.
exposure_state[0] is (currentEV, initialised, targetEV, compensation) and
exposure_state[1] is (settings generation, gain, adapting, 0): the gain is
exp2(currentEV + compensation), and adapting is 1 on the first frame, on
the first frame metered under new settings, and while the live stop is a
hundredth of a stop or more from a target it moves toward. exposure_adapt
also writes the live and target stops to its single-texel output.
Reaching the picture
The chain's display pass follows the gain as __display__'s exposure
property (postprocess.setPropertySource on exposure_state word 5, settling
on word 6) — the one place in the frame a stop turns into a change on screen.
The renderer reads those words back once for each frame it draws, and goes on
drawing frames while adapting reads 1, so a renderer that draws only for its
consumers settles the exposure too. Until the first frame is metered the state
holds the exposure that stood, which the display keeps.
Parameters arrive through the exposure_params buffer, packed by
@builtin::systems.exposure.exposure when the settings change; the step the
adaptation advances by is the wall-clock seconds since the previous drawn
frame, @frame.clock's [2].x. The passes stand from frame to frame, so the
feature's render runs only on a settings change.