rgb2cmyk: RGB to CMYK Color Space Conversion
Subtractive Color Model Transformation
The RGB to CMYK conversion transforms additive color values to subtractive color space used in printing. CMYK represents colors through Cyan, Magenta, Yellow, and Black (Key) ink densities that subtract wavelengths from white paper.
The mathematical transformation follows:
For RGB values where each component :
The black component represents the maximum darkness achievable by overlaying all three chromatic inks. The chromatic components are normalized by the remaining color gamut after black extraction.
const fragment = () => { const rgb = vec3(uv, iTime.sin().mul(0.5).add(0.5)) const cmyk = rgb2cmyk(rgb) const channels = vec3(cmyk.x, cmyk.y, cmyk.z) return vec4(channels.mul(cmyk.w.oneMinus()), 1) }
The conversion includes division by zero protection through step function masking. When (pure black), the chromatic components become undefined, requiring special handling to prevent numerical instabilities.
CMYK color separation enables independent control of ink densities in printing processes. The four-channel representation allows precise reproduction of colors within the printable gamut while optimizing ink usage through black substitution.