{
 "id": "oklab",
 "title": "Oklab perceptual color space",
 "aliases": [
  "OKLCH"
 ],
 "domain": "post",
 "subdomain": "color space",
 "stage": "post",
 "realtime": "interactive",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu",
  "blender"
 ],
 "year_introduced": 2020,
 "inputs": [
  "ldr-image",
  "hdr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "A perceptually uniform opponent color space with a simple two-matrix, cube-root transform. Lightness, chroma and hue are predictable, which makes gradients, palettes and gamut mapping look right.",
 "how_it_works": "Oklab takes linear sRGB through a 3x3 matrix to approximate cone responses (LMS), applies a cube root to each channel, and applies a second 3x3 matrix to get L (perceived lightness), a (green-red) and b (blue-yellow). It was fitted to data from a more complex colour model with the goal of better hue linearity and lightness prediction than CIELAB, at a similar cost. Converting a, b to polar form gives OKLCH: chroma and hue. Interpolating in Oklab avoids the muddy mid-point of RGB gradients and the hue drift of HSV, and changing L alone changes lightness without hue shift. Because the cube root is not defined for HDR scaling, modifications exist for high dynamic range.",
 "when_to_use": "Choose it for gradients, palette generation, hue-preserving gamut clipping, saturation controls, and any grading where perceptual predictability matters.\n\nPrefer CIELAB when you need compatibility with established colour-difference metrics (the Delta E formulas). Prefer sRGB linear for light transport, since Oklab is not additive.",
 "cost": {
  "class": "cheap",
  "notes": "Two 3x3 matrices and a cube root per pixel."
 },
 "failure_modes": [
  "Not additive, so lighting maths must stay in linear RGB",
  "Gamut boundaries are complex in a, b space and need a dedicated clip function",
  "Blue hues are less uniform than elsewhere and drift when lightness changes",
  "Designed for the SDR range; HDR values need an extended variant"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://bottosson.github.io/posts/oklab",
   "type": "web",
   "title": "A perceptual color space for image processing",
   "authors": [
    "Björn Ottosson"
   ],
   "year": null,
   "venue": "bottosson.github.io",
   "url": "https://bottosson.github.io/posts/oklab",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261104030601/https://bottosson.github.io/posts/oklab/",
     "timestamp": "20261104030601"
    },
    "page_title": "A perceptual color space for image processing",
    "host": "bottosson.github.io",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://bottosson.github.io/posts/oklab → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://bottosson.github.io/posts/oklab → 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://bottosson.github.io/posts/oklab → 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": "ottossonperceptual"
  },
  {
   "role": "implementation",
   "key": "gh:bottosson/bottosson.github.io",
   "type": "code",
   "title": "bottosson/bottosson.github.io",
   "description": "",
   "authors": [
    "bottosson"
   ],
   "year": 2020,
   "venue": "GitHub",
   "url": "https://github.com/bottosson/bottosson.github.io",
   "ids": {
    "repo": "bottosson/bottosson.github.io"
   },
   "license": null,
   "extra": {
    "stars": 183,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2025-05-26T08:35:57Z",
    "language": "HTML",
    "homepage": null,
    "license_name": null
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/bottosson/bottosson.github.io",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "bottosson2020bottosson"
  }
 ],
 "presets": [
  {
   "id": "oklab-specimen",
   "title": "Four ramps with their OKLab lightness below: sRGB lerp, OKLab lerp, HSV hue sweep, OKLCH hue sweep",
   "runtime": "glsl-fragment",
   "params": {},
   "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\nvec3 toLin(vec3 c){return pow(c,vec3(2.2));}\nvec3 toOk(vec3 c){c=toLin(c);\n  float l=.4122214708*c.r+.5363325363*c.g+.0514459929*c.b;\n  float m=.2119034982*c.r+.6806995451*c.g+.1073969566*c.b;\n  float s=.0883024619*c.r+.2817188376*c.g+.6299787005*c.b;\n  l=pow(l,1./3.);m=pow(m,1./3.);s=pow(s,1./3.);\n  return vec3(.2104542553*l+.793617785*m-.0040720468*s,1.9779984951*l-2.428592205*m+.4505937099*s,.0259040371*l+.7827717662*m-.808675766*s);}\nvec3 fromOk(vec3 c){\n  float l=c.x+.3963377774*c.y+.2158037573*c.z,m=c.x-.1055613458*c.y-.0638541728*c.z,s=c.x-.0894841775*c.y-1.291485548*c.z;\n  l=l*l*l;m=m*m*m;s=s*s*s;\n  vec3 r=vec3(4.0767416621*l-3.3077115913*m+.2309699292*s,-1.2684380046*l+2.6097574011*m-.3413193965*s,-.0041960863*l-.7034186147*m+1.707614701*s);\n  return pow(clamp(r,0.,1.),vec3(1./2.2));}\nvoid mainImage(out vec4 fragColor,in vec2 fragCoord){\n  vec2 uv=fragCoord/iResolution.xy;float x=uv.x;\n  int band=int(floor((1.-uv.y)*4.));float f=fract((1.-uv.y)*4.);\n  vec3 a=vec3(0.,0.,1.),b=vec3(1.,1.,0.),col;\n  if(band==0) col=mix(a,b,x);\n  else if(band==1) col=fromOk(mix(toOk(a),toOk(b),x));\n  else if(band==2){vec3 k=clamp(abs(mod(x*6.+vec3(0.,4.,2.),6.)-3.)-1.,0.,1.);col=k;}\n  else {float h=x*6.2831853;col=fromOk(vec3(.75,.12*cos(h),.12*sin(h)));}\n  if(f>.78){float L=toOk(col).x;col=vec3(L);}\n  if(f<.012||f>.985)col=vec3(.08);\n  fragColor=vec4(col,1.);\n}",
   "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": "oklab",
     "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.5771,
      "std": 0.2321,
      "unique_colors": 144
     },
     "image": "/specimens/oklab-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "lut-color-grading",
  "agx-tonemapping"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "lut-color-grading",
   "why": "Edit in Oklab, bake the result into a LUT."
  }
 ],
 "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/oklab.json"
 },
 "solves": [
  "gradients turn muddy or change hue unexpectedly",
  "need perceptually even palette generation",
  "saturation changes shift the apparent brightness",
  "gamut clipping alters hue",
  "colour mixing that looks natural to the eye"
 ],
 "authority": "Ottosson",
 "url": "https://texelatlas.vercel.app/t/oklab/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 1.15,
  "tier": "feather",
  "p50_ms": 0.0377,
  "p95_ms": 0.0393,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "oklab-specimen",
  "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.37,
   "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.0289,
   "speedup_x": 1.31,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}