{
 "id": "linear-color-workflow",
 "title": "Linear-space rendering and gamma correction",
 "aliases": [
  "linear workflow",
  "gamma-correct rendering",
  "sRGB framebuffer",
  "linear light"
 ],
 "domain": "post",
 "subdomain": "colour management",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "blender",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2007,
 "inputs": [
  "texture",
  "hdr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Do lighting, blending and filtering on values proportional to physical light, decoding sRGB inputs on read and encoding the result for display only at the end.",
 "how_it_works": "Display values (sRGB, roughly a 2.2 power curve) are perceptually spaced, not proportional to emitted light, so adding or averaging them gives wrong brightness. A linear workflow keeps every arithmetic stage in linear radiometric units: colour textures tagged sRGB are decoded when sampled (hardware does this for sRGB texture formats, including correct filtering), data textures such as normals, roughness and masks stay untouched, lighting accumulates in a floating-point linear buffer, and a final step applies tone mapping (see `agx-tonemapping`, `khronos-pbr-neutral`) and the sRGB opto-electronic transfer on output, either through an sRGB framebuffer or a manual shader function. Constant colours picked by artists in a UI are also decoded first. The same discipline applies to blending, mipmapping, MSAA resolve and bloom, which are only correct on linear data; the sRGB piecewise curve (a linear toe plus 2.4 exponent) is used rather than a plain 2.2 power when exact round trips matter.",
 "when_to_use": "Use it in every renderer, always; it is a prerequisite for physically plausible lighting, correct falloff, accurate alpha blending and `ggx-trowbridge-reitz`-style PBR to look right. Add `lut-color-grading` and a tonemapper after it rather than instead of it. Choose a wider working gamut and `hdr-display-output-pq` only when targeting HDR panels; `oklab` is the space for perceptual operations such as gradients, not for light transport.",
 "cost": {
  "class": "cheap",
  "notes": "Free with sRGB texture and framebuffer formats on modern GPUs; manual encode/decode is a few ALU instructions per pixel."
 },
 "failure_modes": [
  "Washed-out, over-bright mid-tones when lighting is computed on sRGB-encoded textures",
  "Dark fringes or halos around alpha-blended edges and particles blended in gamma space",
  "Banding in dark regions when linear data is stored in an 8-bit non-sRGB target",
  "Double gamma: encoding twice (renderer plus sRGB framebuffer or compositor) crushes shadows",
  "Normal maps and roughness textures wrongly decoded as sRGB, producing lighting errors",
  "Gradients between saturated colours dip in brightness or look muddy when blended in encoded space"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear",
   "type": "web",
   "title": "Chapter 24. The Importance of Being Linear",
   "authors": [
    "Larry Gritz",
    "Eugene d'Eon"
   ],
   "year": null,
   "venue": "developer.nvidia.com",
   "url": "https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261019160901/https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear",
     "timestamp": "20261019160901"
    },
    "page_title": "Chapter 24. The Importance of Being Linear",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear → 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://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear → 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": 1,
   "__bib": "gritzchapter"
  },
  {
   "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": "srgb-vs-linear-blend-comparison",
   "title": "sRGB-space vs linear-light gradient and checker comparison",
   "runtime": "glsl-fragment",
   "params": {
    "colorA": [
     1,
     0.1,
     0.1
    ],
    "colorB": [
     0.1,
     0.9,
     0.2
    ]
   },
   "code": "// GLSL ES 3.0, Shadertoy-style. Top: red-green blend done in sRGB-encoded vs linear light.\n// Bottom: a 50% black/white checker (true 0.5 linear light) next to flat 0.5 encoded and 0.5 linear-encoded patches.\nconst vec3 A = vec3(1.0, 0.1, 0.1);   // sRGB-encoded colour A\nconst vec3 B = vec3(0.1, 0.9, 0.2);   // sRGB-encoded colour B\n\nvec3 toLinear(vec3 c) { return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c)); }\nvec3 toSRGB(vec3 c)   { return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c)); }\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = fragCoord / iResolution.xy;\n  vec3 col;\n  if (uv.y > 0.5) {\n    float t = uv.x;\n    vec3 naive = mix(A, B, t);                                  // blended directly on encoded values\n    vec3 lin = toSRGB(mix(toLinear(A), toLinear(B), t));        // blended in linear light, then encoded\n    col = (uv.y > 0.75) ? naive : lin;\n  } else {\n    float cell = floor(fragCoord.x / 2.0) + floor(fragCoord.y / 2.0);\n    float checker = mod(cell, 2.0);                             // physical 50% mix of 0 and 1\n    float x = uv.x * 3.0;\n    if (x < 1.0) col = vec3(checker);\n    else if (x < 2.0) col = vec3(0.5);                          // encoded 0.5 = only ~21% linear light: too dark\n    else col = vec3(toSRGB(vec3(0.5)).x);                       // encoded 0.735 matches the checker's average\n  }\n  if (abs(uv.y - 0.5) < 0.004 || abs(uv.y - 0.75) < 0.002) col = vec3(0.0);\n  fragColor = vec4(col, 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index; transfer function is the standard piecewise sRGB curve",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "linear-color-workflow",
     "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.5563,
      "std": 0.243,
      "unique_colors": 65
     },
     "image": "/specimens/srgb-vs-linear-blend-comparison.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "aces-tonemapping",
  "agx-tonemapping",
  "khronos-pbr-neutral",
  "reinhard-tonemapping",
  "hable-filmic-tonemapping",
  "lut-color-grading",
  "oklab",
  "hdr-display-output-pq"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "agx-tonemapping",
   "why": "Linear scene radiance from a linear workflow is what the tonemapper compresses into display range before sRGB encoding."
  },
  {
   "id": "dual-filter-bloom",
   "why": "Bloom downsample and blur chains are only energy-correct when run on linear HDR values."
  }
 ],
 "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/linear-color-workflow.json"
 },
 "solves": [
  "my lighting looks too dark and contrasty in mid tones",
  "blended colours look muddy or too dark in the middle",
  "gradient between two saturated colours dips in brightness",
  "textures look washed out after adding lights",
  "alpha blended edges show dark fringes around sprites"
 ],
 "authority": "Gritz & d'Eon",
 "url": "https://texelatlas.vercel.app/t/linear-color-workflow/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 0.88,
  "tier": "feather",
  "p50_ms": 0.0291,
  "p95_ms": 0.0299,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "srgb-vs-linear-blend-comparison",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 0.96,
   "tier": "feather",
   "p50_ms": 0.0152,
   "p95_ms": 0.0153,
   "speedup_x": 1.91,
   "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.01,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}