{
 "id": "auto-exposure-histogram",
 "title": "Auto exposure from luminance histogram",
 "aliases": [
  "eye adaptation"
 ],
 "domain": "post",
 "subdomain": "exposure",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2016,
 "inputs": [
  "hdr-image"
 ],
 "outputs": [
  "hdr-image"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "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.",
 "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_use": "Choose it when scene brightness varies a lot and you want eye-adaptation with outlier rejection.\n\nPrefer 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-tonemapping`.",
 "cost": {
  "class": "cheap",
  "notes": "One histogram compute pass and one tiny reduction; cost dominated by memory bandwidth of reading the frame."
 },
 "failure_modes": [
  "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://bruop.github.io/exposure",
   "type": "web",
   "title": "Automatic Exposure",
   "authors": [
    "Bruno Opsenica"
   ],
   "year": null,
   "venue": "bruop.github.io",
   "url": "https://bruop.github.io/exposure",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260527194625/https://bruop.github.io/exposure/",
     "timestamp": "20260527194625"
    },
    "page_title": "Automatic Exposure Using a Luminance Histogram",
    "host": "bruop.github.io",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://bruop.github.io/exposure → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://bruop.github.io/exposure → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://bruop.github.io/exposure → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "opsenicaautomatic"
  },
  {
   "role": "implementation",
   "key": "gh:embarkstudios/kajiya",
   "type": "code",
   "title": "EmbarkStudios/kajiya",
   "description": "💡 Experimental real-time global illumination renderer 🦀",
   "authors": [
    "EmbarkStudios"
   ],
   "year": 2021,
   "venue": "GitHub",
   "url": "https://github.com/EmbarkStudios/kajiya",
   "ids": {
    "repo": "EmbarkStudios/kajiya"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 5337,
    "stars_checked": "2026-11-29",
    "archived": true,
    "fork": false,
    "pushed_at": "2025-07-07T21:27:20Z",
    "language": "Rust",
    "homepage": null,
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/EmbarkStudios/kajiya",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "embarkstudios2021embarkstudios"
  }
 ],
 "presets": [
  {
   "id": "auto-exposure-histogram-specimen",
   "title": "Dim room with a bright window. Left: fixed exposure. Right: exposure from a luminance histogram with 10% tails discarded",
   "runtime": "glsl-fragment",
   "params": {
    "GN": 16,
    "NB": 24,
    "LO": 0.1,
    "HI": 0.9
   },
   "code": "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.);}\nfloat lum(vec3 c){return dot(c,vec3(.2126,.7152,.0722));}\nvec3 gam(vec3 c){return pow(clamp(c,0.,1.),vec3(1./2.2));}\n\nconst int GN=16; // P\nconst int NB=24; // P\nconst float LO=0.1; // P\nconst float HI=0.9; // P\nvec3 hdr(vec2 p){\n  vec3 c=vec3(.02,.025,.03)*(1.+(p.y+.5)*.8);\n  if(p.y<-.3)c=vec3(.05,.035,.025)*(.6+.8*step(.5,fract((p.x+p.y)*12.)));\n  if(length(p-vec2(-.1,-.1))<.09)c=vec3(.5,.2,.1)*.12;\n  if(abs(p.x-.08)<.1&&p.y>.1&&p.y<.4)c=vec3(1.,.95,.85)*18.;\n  return c;}\nvoid mainImage(out vec4 fragColor,in vec2 fragCoord){\n  vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;vec2 q=vec2(uv.x+(R?-.25:.25),uv.y);\n  float cnt[24];for(int b=0;b<NB;b++)cnt[b]=0.;\n  for(int j=0;j<GN;j++)for(int i=0;i<GN;i++){\n    vec2 p=vec2((float(i)+.5)/float(GN)-.5,(float(j)+.5)/float(GN)-.5)*vec2(.5,1.);\n    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.;}\n  float tot=float(GN*GN),acc=0.,sum=0.,ws=0.,mx=0.;float kept[24];\n  for(int b=0;b<NB;b++){float a1=acc+cnt[b];float k=max(min(a1,HI*tot)-max(acc,LO*tot),0.);\n    kept[b]=k>0.?1.:0.;sum+=k*(-8.+(float(b)+.5)/float(NB)*14.);ws+=k;acc=a1;mx=max(mx,cnt[b]);}\n  float expo=.18/exp2(sum/max(ws,1e-3));\n  vec3 c=hdr(q)*(R?expo:1.);\n  vec3 col=gam(c/(1.+c));\n  if(R&&uv.y<-.3&&uv.x>.03&&uv.x<.47){\n    int b=int(floor((uv.x-.03)/.44*float(NB)));float h=cnt[b]/mx*.17;\n    col*=.35;\n    if(uv.y+.5<h) col=kept[b]>.5?vec3(.3,.9,.5):vec3(.6,.3,.3); }\n  if(abs(uv.x)<.0015)col=vec3(1.);\n  fragColor=vec4(col,1.);\n}",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "auto-exposure-histogram",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.373,
      "std": 0.2518,
      "unique_colors": 21
     },
     "image": "/specimens/auto-exposure-histogram-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "agx-tonemapping",
  "aces-tonemapping",
  "dual-filter-bloom"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "aces-tonemapping",
   "why": "Exposure scales scene-referred values before the tone curve."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/post/auto-exposure-histogram.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Opsenica",
 "url": "https://texelatlas.vercel.app/t/auto-exposure-histogram/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 1.2,
  "tier": "feather",
  "p50_ms": 0.0396,
  "p95_ms": 0.0409,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "auto-exposure-histogram-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1.09,
   "tier": "feather",
   "p50_ms": 0.0174,
   "p95_ms": 0.0175,
   "speedup_x": 2.28,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 21.24,
   "tier": "heavy",
   "p50_ms": 0.6118,
   "p95_ms": 0.6209,
   "speedup_x": 0.06,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}