algorithmcolors

Algorithm for Additive Color Mixing for RGB Values


I'm looking for an algorithm to do additive color mixing for RGB values.

Is it as simple as adding the RGB values together to a max of 256?

(r1, g1, b1) + (r2, g2, b2) =
    (min(r1+r2, 256), min(g1+g2, 256), min(b1+b2, 256))  

Solution

  • It depends on what you want, and it can help to see what the results are of different methods.

    If you want

    Red + Black        = Red
    Red + Green        = Yellow
    Red + Green + Blue = White
    Red + White        = White 
    Black + White      = White
    

    then adding with a clamp works (e.g. min(r1 + r2, 255)) This is more like the light model you've referred to.

    If you want

    Red + Black        = Dark Red
    Red + Green        = Dark Yellow
    Red + Green + Blue = Dark Gray
    Red + White        = Pink
    Black + White      = Gray
    

    then you'll need to average the values (e.g. (r1 + r2) / 2) This works better for lightening/darkening colors and creating gradients.