{
 "id": "agx-tonemapping",
 "title": "AgX",
 "aliases": [],
 "domain": "post",
 "subdomain": "tonemapping",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "blender"
 ],
 "year_introduced": 2022,
 "inputs": [
  "hdr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "A display transform by Troy Sobotka that maps scene-referred values through a log encoding and sigmoid in a rotated primaries space. Highlights roll off to white without hue skews or ACES-style saturation.",
 "how_it_works": "AgX first applies an inset matrix that moves colours slightly toward the neutral axis so extreme values can desaturate gracefully. The result is encoded as log2 between a fixed black and white relative exposure (about minus 12 to plus 4 stops) and normalised, then a sigmoid, fitted as a polynomial, applies the contrast curve. An outset matrix restores most chroma, and an optional look adds slope, power and saturation tweaks for punchier or flatter results. The shaders in Blender and three.js are small enough to run per fragment. The result reaches white with an even desaturation, so a bright blue light does not flip to purple.",
 "when_to_use": "Choose it when you want predictable, neutral highlights and a camera-like rendering, especially for saturated emissive content.\n\nPrefer `aces-tonemapping` when you need ACES compatibility and the punchy look. Prefer `khronos-pbr-neutral` for product viewers where albedo colours must not shift.",
 "cost": {
  "class": "cheap",
  "notes": "Two matrix multiplies and a polynomial per pixel."
 },
 "failure_modes": [
  "Flat, low-contrast default look unless a contrast look is chosen",
  "Slightly desaturated mid-tones compared with ACES or Neutral",
  "Several incompatible implementations (Blender, three.js, Filament) differ in constants",
  "Fully saturated primaries cannot reach display boundaries because of the inset"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "gh:sobotka/agx",
   "type": "code",
   "title": "sobotka/AgX",
   "description": "There Be Kraken and Dragons",
   "authors": [
    "sobotka"
   ],
   "year": 2022,
   "venue": "GitHub",
   "url": "https://github.com/sobotka/AgX",
   "ids": {
    "repo": "sobotka/AgX"
   },
   "license": null,
   "extra": {
    "stars": 337,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2025-03-26T18:55:38Z",
    "language": null,
    "homepage": null,
    "license_name": null
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sobotka/AgX",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "sobotka2022sobotka"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/three.js",
   "type": "code",
   "title": "mrdoob/three.js",
   "description": "JavaScript 3D Library.",
   "authors": [
    "mrdoob"
   ],
   "year": 2010,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/three.js",
   "ids": {
    "repo": "mrdoob/three.js"
   },
   "license": "MIT",
   "extra": {
    "stars": 119718,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T11:39:51Z",
    "language": "JavaScript",
    "homepage": "https://threejs.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mrdoob2010mrdoob"
  }
 ],
 "presets": [
  {
   "id": "three-agx-exposure-1",
   "title": "three.js AgX tone mapping, exposure 1.0",
   "runtime": "three-tonemap",
   "params": {
    "toneMapping": "AgX",
    "exposure": 1
   },
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "agx-tonemapping",
     "runtime": "three-tonemap",
     "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.682,
      "std": 0.1008,
      "unique_colors": 88
     },
     "image": "/specimens/three-agx-exposure-1.webp",
     "reason": null
    }
   }
  },
  {
   "id": "agx-tonemapping-wgsl",
   "title": "AgX inset-matrix HDR tonemapper (WGSL)",
   "runtime": "webgpu-wgsl",
   "basis": "original",
   "license_note": "written for this index",
   "params": {
    "EXPOSURE": 1,
    "PUNCH": 1.15
   },
   "code": "// WebGPU WGSL fragment specimen: AgX log-encoding + sigmoid look curve\nconst EXPOSURE: f32 = 1.0000; // P\nconst PUNCH: f32 = 1.1500; // P\n\nfn agx_map(x_in: vec3f) -> vec3f {\n  let m = mat3x3f(\n    vec3f(0.842479, 0.042328, 0.042376),\n    vec3f(0.078434, 0.878469, 0.078434),\n    vec3f(0.079224, 0.079166, 0.879143)\n  );\n  let x = max(m * max(x_in * EXPOSURE, vec3f(1e-5)), vec3f(1e-5));\n  let lv = clamp((log2(x) + 12.47393) / 16.5, vec3f(0.0), vec3f(1.0));\n  let s = lv * lv * (3.0 - 2.0 * lv);\n  return pow(clamp(s, vec3f(0.0), vec3f(1.0)), vec3f(PUNCH));\n}\n\n@fragment\nfn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {\n  let uv = (pos.xy - 0.5 * u.resolution) / u.resolution.y;\n  var col = vec3f(0.05, 0.055, 0.065);\n  var hues = array<vec3f, 5>(\n    vec3f(1.0, 0.22, 0.12),\n    vec3f(1.0, 0.76, 0.12),\n    vec3f(0.18, 0.82, 0.42),\n    vec3f(0.12, 0.54, 1.0),\n    vec3f(0.70, 0.30, 1.0)\n  );\n  for (var i: i32 = 0; i < 5; i = i + 1) {\n    let c = vec2f((f32(i) - 2.0) * 0.30, -0.06);\n    let d = uv - c;\n    let r2 = dot(d, d);\n    if (r2 < 0.018) {\n      let n = normalize(vec3f(d.x, -d.y, sqrt(0.018 - r2)));\n      let l = max(dot(n, normalize(vec3f(0.4, 0.6, 0.7))), 0.12);\n      col = hues[i] * (l * 0.75 + pow(2.0, f32(i) - 0.4));\n    }\n  }\n  if (uv.y > 0.20 && uv.y < 0.34 && abs(uv.x) < 0.72) {\n    let ev = mix(-3.0, 5.0, (uv.x + 0.72) / 1.44);\n    col = vec3f(pow(2.0, ev));\n  }\n  return vec4f(agx_map(col), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "wgsl",
    "label": "WebGPU WGSL runtime",
    "ok": true,
    "proof": null
   }
  }
 ],
 "related": [
  "aces-tonemapping",
  "khronos-pbr-neutral",
  "reinhard-tonemapping"
 ],
 "extends": [
  "aces-tonemapping"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "auto-exposure-histogram",
   "why": "Exposure feeds the log encoding range."
  },
  {
   "id": "lut-color-grading",
   "why": "AgX is commonly followed by a LUT-based look."
  }
 ],
 "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/agx-tonemapping.json"
 },
 "solves": [
  "bright saturated lights turn orange or cyan at highlights",
  "highlights shift hue instead of rolling off to white",
  "want a neutral camera-like look for hdr renders",
  "emissive colours look garish after tone mapping"
 ],
 "authority": "sobotka, 2022",
 "url": "https://texelatlas.vercel.app/t/agx-tonemapping/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 1.18,
  "tier": "feather",
  "p50_ms": 0.0387,
  "p95_ms": 0.0411,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "three-agx-exposure-1",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 1,
   "tier": "feather",
   "p50_ms": 0.0159,
   "p95_ms": 0.0162,
   "speedup_x": 2.43,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1,
   "tier": "feather",
   "p50_ms": 0.0288,
   "p95_ms": 0.0288,
   "speedup_x": 1.34,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}