srgb2rgb: sRGB to Linear RGB Color Space Conversion
Standard RGB Gamma Correction Removal
The sRGB to linear RGB conversion transforms standard web color values to linear color space for accurate mathematical operations. sRGB applies gamma correction to match human visual perception, while linear RGB maintains proportional light intensity relationships.
The transformation follows a piecewise function:
For sRGB values :
The linear threshold at prevents numerical discontinuities near black values. Below this threshold, simple division by provides linear mapping. Above this threshold, the power function removes gamma correction applied for perceptual uniformity.
const fragment = () => { const web_color = vec3(uv.x, uv.y, iTime.sin().mul(0.3).add(0.7)) const linear_color = srgb2rgb(web_color) const comparison = uv.x.mul(20).sin().greaterThan(0) const result = web_color.select(linear_color, comparison) return vec4(result, 1) }
The conversion includes epsilon addition () to prevent floating-point precision issues near zero values. This ensures numerical stability across different hardware implementations while maintaining color accuracy.
sRGB to linear RGB conversion enables proper color blending, lighting calculations, and texture filtering operations that require linear light intensity relationships rather than perceptually uniform color distribution.