Skip to main content

HDR Auto Exposure

Continuously meter scene luminance and adapt camera exposure entirely on the GPU. createHDRAutoExposureShaderPassPipeline uses a center-weighted logarithmic luminance pyramid, persistent exposure history, and independent brightening and darkening response speeds.

GitHub

At a Glance

PropertyValue
ExportcreateHDRAutoExposureShaderPassPipeline
BackendWebGPU
Render passesSeven: extraction, four reductions, adaptation, and application
Persistent stateOne GPU-owned exposure-history texture
Recommended inputLinear rgba16float scene color

Usage

import {ShaderPassRenderer} from '@luma.gl/engine';
import {
createBloomShaderPassPipeline,
createHDRAutoExposureShaderPassPipeline,
toneMapping
} from '@luma.gl/effects';

const renderer = new ShaderPassRenderer(device, {
colorFormat: 'rgba16float',
shaderPasses: [
createHDRAutoExposureShaderPassPipeline({meteringScale: 0.25, initialExposure: 1}),
createBloomShaderPassPipeline({quality: 'high'}),
toneMapping
]
});

renderer.renderToScreen({
sourceTexture: hdrSceneTexture,
uniforms: {
hdrAutoExposureAdapt: {
keyValue: 0.48,
minimumExposure: 0.45,
maximumExposure: 2.4,
brightenSpeed: 1.6,
darkenSpeed: 2.8,
deltaTime: frameDeltaSeconds,
enabled: 1
}
}
});

Parameters

ParameterDefaultDescription
meteringScale0.25Initial luminance-target scale; smaller values are clamped to 0.25.
initialExposure1Value used to initialize or recreate persistent exposure history.
keyValue0.48Target middle-gray response used to derive scene exposure.
minimumExposure0.45Lower bound on the adapted exposure multiplier.
maximumExposure2.4Upper bound on the adapted exposure multiplier.
brightenSpeed1.6Adaptation rate when the image needs to become brighter.
darkenSpeed2.8Adaptation rate when the image needs to become darker.
deltaTime0.016Current frame duration in seconds; update this application-owned uniform every frame.

How It Works

  1. Sample a 4-by-4 footprint and accumulate center-weighted logarithmic luminance.
  2. Reduce four successively smaller floating-point pyramid levels.
  3. Derive geometric-mean scene brightness without copying results back to the CPU.
  4. Adapt and clamp the persistent exposure target with direction-specific response speeds.
  5. Multiply the original HDR scene color by the current adapted exposure.

The pipeline can also expose a false-color luminance visualization through the application-stage debug uniform. Reset renderer history when a resize, camera cut, or scene replacement should discard the previous adaptation state.

  • Bloom supports exposure-aware highlight thresholds and exposure-corrected temporal history.
  • Tone Mapping converts the adapted HDR image into display-ready color.
  • Temporal Antialiasing normally precedes exposure and bloom in the render stack.