---
id: "oklab"
title: "Oklab perceptual color space"
aliases: [OKLCH]
domain: "post"
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"
cost: "cheap"
authority: "Ottosson"
url: "https://texelatlas.vercel.app/t/oklab/"
sources_verified_at: "2026-11-29"
---
# Oklab perceptual color space (Ottosson)

> 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.

## Reach for it when

- 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

## 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 it

Choose it for gradients, palette generation, hue-preserving gamut clipping, saturation controls, and any grading where perceptual predictability matters.

Prefer 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

cheap — Two 3x3 matrices and a cube root per pixel.
Measured GPU Weight: 1.15× baseline (feather) — 0.0377 ms median / 0.0393 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 1× baseline (feather) — 0.0159 ms median (2.37× faster on L4).
Ampere A100 scaling: 1× baseline (feather) — 0.0288 ms median (1.31× faster on A100).

## 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

## Engine support

- godot: builtin — `Color.from_ok_hsl(h, s, l) and Color.ok_hsl_h / ok_hsl_s / ok_hsl_l perceptual color helpers` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Color.xml, checked 2026-12-01)

## Dataflow

- Inputs: ldr-image, hdr-image
- Outputs: ldr-image
- Platforms: webgl2, webgpu, desktop-gpu, cpu, blender

## Presets

### Four ramps with their OKLab lightness below: sRGB lerp, OKLab lerp, HSV hue sweep, OKLCH hue sweep (glsl-fragment; rendered 2026-11-29)

```glsl
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));}

vec3 toLin(vec3 c){return pow(c,vec3(2.2));}
vec3 toOk(vec3 c){c=toLin(c);
  float l=.4122214708*c.r+.5363325363*c.g+.0514459929*c.b;
  float m=.2119034982*c.r+.6806995451*c.g+.1073969566*c.b;
  float s=.0883024619*c.r+.2817188376*c.g+.6299787005*c.b;
  l=pow(l,1./3.);m=pow(m,1./3.);s=pow(s,1./3.);
  return vec3(.2104542553*l+.793617785*m-.0040720468*s,1.9779984951*l-2.428592205*m+.4505937099*s,.0259040371*l+.7827717662*m-.808675766*s);}
vec3 fromOk(vec3 c){
  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;
  l=l*l*l;m=m*m*m;s=s*s*s;
  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);
  return pow(clamp(r,0.,1.),vec3(1./2.2));}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
  vec2 uv=fragCoord/iResolution.xy;float x=uv.x;
  int band=int(floor((1.-uv.y)*4.));float f=fract((1.-uv.y)*4.);
  vec3 a=vec3(0.,0.,1.),b=vec3(1.,1.,0.),col;
  if(band==0) col=mix(a,b,x);
  else if(band==1) col=fromOk(mix(toOk(a),toOk(b),x));
  else if(band==2){vec3 k=clamp(abs(mod(x*6.+vec3(0.,4.,2.),6.)-3.)-1.,0.,1.);col=k;}
  else {float h=x*6.2831853;col=fromOk(vec3(.75,.12*cos(h),.12*sin(h)));}
  if(f>.78){float L=toOk(col).x;col=vec3(L);}
  if(f<.012||f>.985)col=vec3(.08);
  fragColor=vec4(col,1.);
}
```

Attribution: written for this index

## Combines with

- [3D LUT color grading](https://texelatlas.vercel.app/t/lut-color-grading.md): Edit in Oklab, bake the result into a LUT.

## Sources

1. [primary] Björn Ottosson A perceptual color space for image processing. bottosson.github.io. https://bottosson.github.io/posts/oklab (verified via http on 2026-11-29)
2. [implementation] bottosson (2020) bottosson/bottosson.github.io. https://github.com/bottosson/bottosson.github.io (verified via github on 2026-11-29)

## Cite this entry

Texel. "Oklab perceptual color space." https://texelatlas.vercel.app/t/oklab/ (accessed 2026-12-01).
