← All packages

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.

v1.2.0 Unity 2021.3+ No dependencies namespace: DawgTools.OKLab

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.

ProblemHSV/HSLOKLab
Darkening blue shifts to purpleYesNo
Yellow and blue at same L look equally brightYesNo
Lerping red to green produces muddy brownYesNo
50% lightness varies wildly by hueYesNo

Core API - OKLabColor

Static class. All methods are pure functions with no side effects.

Color space conversion

MethodDescription
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

MethodDescription
LerpOKLab(Color a, Color b, float t)Perceptually uniform interpolation
LerpLinearRGB(Color a, Color b, float t)Linear-light RGB interpolation

Adjustments

MethodDescription
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

MethodDescription
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

ModeColorsDescription
Complementary2Opposite on the hue wheel (180 degrees)
Triadic3Three equally-spaced hues (120 degrees apart)
Analogous3Adjacent hues (30 degrees apart)
Split-Complementary3Complement split into two (150 and 210 degrees)
Tetradic4Two complementary pairs (90 degrees apart)

Ramp generation

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