OKLab Color Inspector Pro
Perceptual color for Unity, based on Bjorn Ottosson's OKLab color space. No muddy midpoints, no hue shifts on darkening, uniform brightness steps. The same color science behind CSS Color Level 4 and Figma.
Quick start
One using statement, zero setup. Works in any render pipeline.
using DawgTools.OKLab; using UnityEngine; // Perceptually uniform lerp (no muddy midpoints) Color midpoint = OKLabColor.LerpOKLab(Color.red, Color.green, 0.5f); // Darken without hue shift Color darker = OKLabColor.AdjustLightness(myColor, -0.15f); // WCAG contrast check float ratio = OKLabColor.WcagContrastRatio(textColor, bgColor); bool passesAA = ratio >= 4.5f; // Auto-pick readable text color Color text = OKLabColor.BestTextColor(backgroundColor); // Generate palette from one accent color Color[] harmony = OKLabPalette.GenerateHarmony(accent, HarmonyMode.Triadic);
Why OKLab over HSV/HSL?
Standard color spaces lie about perceptual uniformity. OKLab doesn't.
| Problem | HSV/HSL | OKLab |
|---|---|---|
| Darkening blue shifts to purple | Yes | No |
| Yellow and blue at same L look equally bright | Yes | No |
| Lerping red to green produces muddy brown | Yes | No |
| 50% lightness varies wildly by hue | Yes | No |
Core API - OKLabColor
Static class. All methods are pure functions with no side effects.
Color space conversion
| Method | Description |
|---|---|
RGBToOKLab(Color) | Convert RGB to OKLab (L, a, b) |
OKLabToRGB(L, a, b) | Convert OKLab to RGB |
OKLabToRGBSafe(L, a, b) | Convert with gamut clamping (stays in sRGB) |
Interpolation
| Method | Description |
|---|---|
LerpOKLab(Color a, Color b, float t) | Perceptually uniform interpolation |
LerpLinearRGB(Color a, Color b, float t) | Linear-light RGB interpolation |
Adjustments
| Method | Description |
|---|---|
AdjustLightness(Color, float delta) | Change lightness, preserve hue |
AdjustChroma(Color, float delta) | Change saturation, preserve hue and lightness |
GetLightness(Color) | Get OKLab lightness (0-1) |
GetChroma(Color) | Get OKLab chroma |
GetHue(Color) | Get hue angle (0-360) |
Accessibility
| Method | Description |
|---|---|
WcagContrastRatio(Color fg, Color bg) | WCAG 2.1 luminance contrast ratio |
WcagRelativeLuminance(Color) | Relative luminance per WCAG spec |
BestTextColor(Color bg) | Returns black or white for best readability |
PerceptualDelta(Color a, Color b) | Perceptual distance (delta E in OKLab) |
EnsureMinDelta(Color, Color, float) | Binary-search to enforce minimum separation |
Palette API - OKLabPalette
Build harmonies, ramps, and full UI themes from a single accent color.
Harmony generation
| Mode | Colors | Description |
|---|---|---|
| Complementary | 2 | Opposite on the hue wheel (180 degrees) |
| Triadic | 3 | Three equally-spaced hues (120 degrees apart) |
| Analogous | 3 | Adjacent hues (30 degrees apart) |
| Split-Complementary | 3 | Complement split into two (150 and 210 degrees) |
| Tetradic | 4 | Two complementary pairs (90 degrees apart) |
Ramp generation
| Method | Description |
|---|---|
GenerateRamp(Color a, Color b, steps, BlendConstraint) | Blend between colors with constraint (Free, ConstantHue, ConstantChroma, ConstantLightness) |
GenerateLightnessRamp(Color, steps) | Dark-to-light ramp at constant hue and chroma |
HueRotate(Color, float degrees) | Rotate hue at constant lightness and chroma |
Editor tools
Color Inspector
Window > DAWG Tools > OKLab Color Inspector
Side-by-side comparison of Gamma RGB vs Linear RGB vs OKLab lerp.
Interactive slice with click/drag. Lock Lightness and Lock Chroma modes.
Gamut clipping indicators, WCAG contrast display, perceptual delta metrics.
Palette Builder
Window > DAWG Tools > OKLab Palette Builder
OKLCH sliders with hex input and gamut warnings. Build tab (manual), Generate tab
(harmony/ramp/UI theme), Ship tab (WCAG validation matrix, distance warnings).
Export to .hex, .gpl, C# snippet, or ScriptableObject.
One-click UI theme generation
Feed in a single accent color and get a complete 10-color UI theme with backgrounds, surfaces, text, borders, and accent variants. Automatically generates both light and dark variants. WCAG auto-fix adjusts colors via binary search to meet AA contrast requirements.
Installation
// Unity Package Manager > Add package from disk // Navigate to package.json and select it // Then import the demo scene: // Package Manager > OKLab Color Inspector PRO > Samples > Import
Requires Unity 2021.3 LTS or newer. No external dependencies. Works with Built-in, URP, and HDRP render pipelines.