Manipulate RGBA color channels with mathematical precision using SVG feColorMatrix filter primitives. Includes Spotify duotone presets, Brettel/Vienot color blindness simulation matrices (protanopia, deuteranopia, tritanopia), and live custom 4x5 matrix sliders with CSS export.
Color Matrix Shaders
Duotone StylesA11y Color Blindness SimulationStylized & Thermal FX
SVG feColorMatrix RGBA Transformation & Color Vision Accessibility
Technical guide on 4x5 linear color matrices, duotone shaders, and dichromatic simulation algorithms.
Architecture Overview
The SVG <feColorMatrix> filter primitive provides hardware-accelerated linear algebraic color transformations on RGBA channels directly in the browser DOM. Unlike simple CSS opacity or hue-rotate filters, a 4x5 color matrix enables independent remapping of all color components, allowing advanced duotone styling, high-contrast thermal visualizations, and precise WCAG color blindness simulations.
Core Mechanics & Implementation Details
The 4x5 Linear Color Matrix Equation
The filter computes output color values [R', G', B', A'] by multiplying the input pixel vector [R, G, B, A, 1] by a 20-element transformation matrix: R' = a00*R + a01*G + a02*B + a03*A + a04. The first four columns represent scale multipliers for each channel, while the fifth column provides a constant additive bias value.
Duotone Shader Mathematics
Duotone effects map luminance to a two-color gradient. Luminance Y is first calculated via human perceptual weights (0.2126R + 0.7152G + 0.0722B). The target highlights and shadows colors (C_high, C_low) are then linearly blended along the luminance axis: Output = Y * C_high + (1 - Y) * C_low.
Dichromatic Color Blindness Simulation (Brettel & Vienot)
Simulating human color vision deficiency requires projecting the trichromatic sRGB color space onto a dichromatic confusion plane. For protanopia (missing L-cones), reds and greens collapse along confusion lines. The matrix multiplies input colors by physiologically measured transformation coefficients to render what color-blind users experience.