home/ atoms/ linearize-before-color-math

Color arithmetic must be done in linear light, not in gamma-encoded values

Gamma-encoded values (sRGB, DCI-P3, etc.) are compressed for storage, not for math. When you mix or interpolate two gamma-encoded colors directly, the result is incorrect — midtones appear darker than physically accurate. Fix: linearize (apply the inverse TRC) before arithmetic, then re-encode afterward. In GLSL shaders, texture samples tagged as sRGB are often auto-linearized by the hardware; if not, pow(color, vec3(2.2)) is a common approximation. This is the root cause of ‘muddy gradients’ in naive color interpolation.

Examples

Linear gradient red→green: the middle step has equal physical red and green, perceived as yellow. sRGB-encoded midpoint computed naively: physically darker, perceived as olive/brown.

Assessment

A shader lerps between two sRGB colors and the midpoint looks too dark. Describe exactly what went wrong and how to fix it.

“mathematical operations on light only make sense when done on _linear_ values, because they represent the actual intensities of light.”
corpus · color-spaces-bartosz-ciechanowski-interactive-article · chunk 2