Page 1 of 1

mixing colors

Posted: Fri Jul 11, 2014 10:01 pm
by tester
Changing the topic a little bit.

How to mix multiple colors in "light" way and "paint" way?

Let say that I have an array of RGB values (0-255 ranges; this comes out of a module):

rrr/ggg/bbb
rrr/ggg/bbb
rrr/ggg/bbb
...

And as the output reslut - I'd like to have one color as if I was mixing lights, and second color as if I was mixing paints.

From what I see - one formula is probably just to sum on all rrr/ggg/bbb channels and divide by amount of elements in the array (subtractive/paint type?). But I don't know how to approach the second one. Especially because many colors in FS are just idealistic with 0 or 255 thresholds.

Trog - I don't seek for ultra-hyper-realistic sRGB, just something brief. ;-)

Re: mixing colors

Posted: Fri Jul 11, 2014 10:28 pm
by TheOm
I would first convert the colours from RGB to HSV and then take the average values.

Re: mixing colors

Posted: Fri Jul 11, 2014 10:46 pm
by tester
Okay, thanks. Tested, and while results are not quite as expected (thus - I will keep probably only one mixing model), this conversion RGB-HSV will be useful for other thing.

BTW, @TheOm, you sound very familiar. :mrgreen:

Re: mixing colors

Posted: Sat Jul 12, 2014 10:41 am
by trogluddite
For 'light mix', summing R, G, B would be a reasonable approximation - the hue would be about right, but as you say the limited (0-255) would affect the brightness, so the values will need scaling to keep in range.

For paints, the colour depends on the light that the pigments absorb, and your eye sees the remainder that bounces off - mixing two pigments combines their 'negative' spectrum. (mixing pigments always makes the color darker - hence all oil painters always have a huge tube of white paint!).

So this 'inversion' might be worth a go...

Take (255 -R), (255 - G), (255 - B) for each colour.
Take averages.
Take (255 -R), (255 - G), (255 - B) of result.

Not tried that, it might distort the hue because the traditional painter's primary colours are Red, Blue, Yellow - not Cyan, Yellow, Magenta (opposites of R, G, B).

Mixing in the HSV color space would give other results, though. For example yellow and blue are 'complementary' colours - if you mix those ('light' method), you would get white/grey (zero saturation). But an HSV average will still give you a very saturated color of a different hue.
It is a good way to create a 'spectrum' of hues, so the results will often have more 'visual appeal', but unlikely to give results like mixing lights or pigments.