Auto exposure from luminance histogram
Builds a luminance histogram of the HDR frame in a compute pass, discards outliers, averages the rest in log space, and smoothly adapts exposure over time, giving a stable eye-adaptation response.
Also known as eye adaptation
In the family Post-processing, color & imaging, exposure
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | ImageProcessingConfiguration exposes manual exposure; automatic luminance-histogram exposure adaptation is not built in. |
| Godot 4.7 | Built in | CameraAttributes.auto_exposure_enabled (exposure adaptation from scene luminance) docs |
| Unity | Built in | Volume > Add Override > Exposure > Mode = Automatic Histogram docs HDRP only. URP has no automatic exposure in Unity 6.3. |
| Unreal 5.7 | Built in | Post Process Volume > Exposure > Metering Mode = Auto Exposure Histogram docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A compute shader bins every pixel's log2 luminance into a histogram of around 256 buckets, with a small weight toward the screen centre if desired. A second dispatch walks the histogram, trims the darkest and brightest percentiles so tiny lights and black borders do not skew the result, and computes the weighted mean log luminance. That mean maps to a target exposure through an exposure compensation and key value, for example mapping the mean to mid grey. The scene exposure is blended toward the target with an exponential filter, using different rates for brightening and darkening, which mimics pupil adaptation. The exposure is then applied before the tonemapper.
When to choose it
Reach for it when
- scene is too dark then blown out when moving between rooms
- need eye adaptation that ignores tiny bright lights
- exposure pumps and flickers when a bright pixel enters view
- want smooth automatic brightness adjustment over time
- average luminance gets skewed by outliers
Choose it when scene brightness varies a lot and you want eye-adaptation with outlier rejection.
Prefer a simple log-average mip chain when compute is unavailable, as in WebGL2. Choose fixed exposure for photographic or art-directed shots. Feed the result into the tonemappers, for example AgX.
Field marks
- Pumping or oscillation if the adaptation rate is too fast or the metering follows moving lights
- Wrong exposure when the frame contains huge bright skies or pure black letterboxing without percentile trimming
- Temporal lag causes overexposed frames on cuts unless exposure is reset
- Needs compute shaders, so WebGL2 requires a fallback
Presets
Dim room with a bright window. Left: fixed exposure. Right: exposure from a luminance histogram with 10% tails discarded
{
"GN": 16,
"NB": 24,
"LO": 0.1,
"HI": 0.9
}Show GLSL (33 lines)
float hash(vec2 c){uvec2 u=uvec2(ivec2(floor(c)));uint h=u.x*1597334673u^u.y*3812015801u;h^=h>>15;h*=2246822519u;h^=h>>13;h*=3266489917u;h^=h>>16;return float(h)*(1./4294967296.);}
float lum(vec3 c){return dot(c,vec3(.2126,.7152,.0722));}
vec3 gam(vec3 c){return pow(clamp(c,0.,1.),vec3(1./2.2));}
const int GN=16; // P
const int NB=24; // P
const float LO=0.1; // P
const float HI=0.9; // P
vec3 hdr(vec2 p){
vec3 c=vec3(.02,.025,.03)*(1.+(p.y+.5)*.8);
if(p.y<-.3)c=vec3(.05,.035,.025)*(.6+.8*step(.5,fract((p.x+p.y)*12.)));
if(length(p-vec2(-.1,-.1))<.09)c=vec3(.5,.2,.1)*.12;
if(abs(p.x-.08)<.1&&p.y>.1&&p.y<.4)c=vec3(1.,.95,.85)*18.;
return c;}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;vec2 q=vec2(uv.x+(R?-.25:.25),uv.y);
float cnt[24];for(int b=0;b<NB;b++)cnt[b]=0.;
for(int j=0;j<GN;j++)for(int i=0;i<GN;i++){
vec2 p=vec2((float(i)+.5)/float(GN)-.5,(float(j)+.5)/float(GN)-.5)*vec2(.5,1.);
float lg=log2(max(lum(hdr(p)),1e-4));int b=int(clamp(floor((lg+8.)/14.*float(NB)),0.,float(NB-1)));cnt[b]+=1.;}
float tot=float(GN*GN),acc=0.,sum=0.,ws=0.,mx=0.;float kept[24];
for(int b=0;b<NB;b++){float a1=acc+cnt[b];float k=max(min(a1,HI*tot)-max(acc,LO*tot),0.);
kept[b]=k>0.?1.:0.;sum+=k*(-8.+(float(b)+.5)/float(NB)*14.);ws+=k;acc=a1;mx=max(mx,cnt[b]);}
float expo=.18/exp2(sum/max(ws,1e-3));
vec3 c=hdr(q)*(R?expo:1.);
vec3 col=gam(c/(1.+c));
if(R&&uv.y<-.3&&uv.x>.03&&uv.x<.47){
int b=int(floor((uv.x-.03)/.44*float(NB)));float h=cnt[b]/mx*.17;
col*=.35;
if(uv.y+.5<h) col=kept[b]>.5?vec3(.3,.9,.5):vec3(.6,.3,.3); }
if(abs(uv.x)<.0015)col=vec3(1.);
fragColor=vec4(col,1.);
}Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| auto-exposure-histogram-specimen | Tesla T4 1920x1080 | 1.20× baseline (feather) · 0.040 ms / 0.041 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| auto-exposure-histogram-specimen | NVIDIA L4 1920x1080 | 1.09× baseline (feather) · 0.017 ms / 0.018 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| auto-exposure-histogram-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 21.2× baseline (heavy) · 0.612 ms / 0.621 ms · 0.1× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- 1-bit rendering that meters like a camera: 1-bit or few-level dithered rendering that stays readable from dark caves to bright skies. The luminance histogram built for auto exposure also shapes the dither threshold curve, so dot density spreads across the scene's actual tones.
- ACES filmic tonemapping: Exposure scales scene-referred values before the tone curve.
Sources
- implementationEmbarkStudios (2021). EmbarkStudios/kajiya. 💡 Experimental real-time global illumination renderer 🦀GitHub API · license Apache-2.0 · archived · 2026-11-29