Oklab perceptual color space
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.
Also known as OKLCH
In the family Post-processing, color & imaging, color space
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | No built-in Oklab color-space conversion helpers. |
| Godot 4.7 | Built in | Color.from_ok_hsl(h, s, l) and Color.ok_hsl_h / ok_hsl_s / ok_hsl_l perceptual color helpers docs |
| Unity | None found | Not built in; Shader Graph uses Oklab only inside gradient helpers. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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.
Field marks
- 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
Presets
Four ramps with their OKLab lightness below: sRGB lerp, OKLab lerp, HSV hue sweep, OKLCH hue sweep
Show GLSL (28 lines)
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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| oklab-specimen | Tesla T4 1920x1080 | 1.15× baseline (feather) · 0.038 ms / 0.039 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| oklab-specimen | NVIDIA L4 1920x1080 | 1.00× baseline (feather) · 0.016 ms / 0.016 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| oklab-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 1.00× baseline (feather) · 0.029 ms / 0.029 ms · 1.3× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- 3D LUT color grading: Edit in Oklab, bake the result into a LUT.
Sources
- primaryBjörn Ottosson. A perceptual color space for image processing. bottosson.github.io.Verified via live page · 2026-11-29
- implementationbottosson (2020). bottosson/bottosson.github.io.GitHub API · no license declared · 2026-11-29