RGB to GLSL vec3

A plain divide by 255 keeps the colour encoded. Reach for the linear form when the value takes part in lighting maths.

Hue
Alpha
100%
GLSL vec3
vec3(0.259, 0.529, 0.961)

Paste a RGB value — other formats work too.

Need every format at once? Open in the full picker

Worked examples

Common colours converted from RGB to GLSL vec3, computed with the same engine the picker uses.

ColourRGBGLSL vec3Copy
Pure redrgb(255 0 0)vec3(1.0, 0.0, 0.0)
Pure greenrgb(0 255 0)vec3(0.0, 1.0, 0.0)
Pure bluergb(0 0 255)vec3(0.0, 0.0, 1.0)
Whitergb(255 255 255)vec3(1.0)
Mid greyrgb(128 128 128)vec3(0.502)
Blackrgb(0 0 0)vec3(0.0)
Interface bluergb(66 135 245)vec3(0.259, 0.529, 0.961)
Success greenrgb(34 197 94)vec3(0.133, 0.773, 0.369)
Danger redrgb(239 68 68)vec3(0.937, 0.267, 0.267)
Warning amberrgb(245 158 11)vec3(0.961, 0.62, 0.043)
Editor blackrgb(30 30 30)vec3(0.118)
Warm sandrgb(233 196 106)vec3(0.914, 0.769, 0.416)

How the conversion works

A plain divide by 255 keeps the colour encoded. Reach for the linear form when the value takes part in lighting maths.

Both formats are computed from a single canonical representation — CIE XYZ with a D65 white point, held in floating point — rather than by chaining one format into the next. That matters because chained conversions accumulate rounding error, and because it means a colour that cannot be represented in the target format is handled deliberately rather than by accident.

When the source describes a colour outside the target's gamut, chroma is reduced in OKLCh while lightness and hue are held, following the CSS Color 4 gamut mapping algorithm. Clipping each channel independently would be simpler but visibly shifts hue on saturated colours.

Related conversions