RGB Colorspace
Blending RGB colors
Blending colors in RGB space is straightforward. Sum like components, and then divide by the number of inputs. Simple linear algebra!Adding 2 colors evenly:
R3 = (R1 + R2)/2 G3 = (G1 + G2)/2 B3 = (B1 + B2)/2
A more flexible for would scale the inputs, as follows:
R3 = (R1*Alpha + R2*(1-Alpha))/2 G3 = (G1*Alpha + G2*(1-Alpha))/2 B3 = (B1*Alpha + B2*(1-Alpha))/2Where
Alpha
is a number between 0 and 1. This variation is
commonly called RGBA
colorspace, and can be used to define transparency as well as color.Adding RGB colors
Adding colors in RGB space is very simple. You simply add like components, and clamp the values so you don't overflow or underflow.R3 = clamp(R1 + R2) G3 = clamp(G1 + G2) B3 = clamp(B1 + B2)