Breaking

Thursday, 30 January 2025

Digital Paint Mixing Has Been Greatly Improved With 1930s Math

You might not have noticed if you’re not a digital artist, but most painting and image apps still get color mixing wrong. As we all learned in kindergarten, blue paint and yellow paint makes green paint. Try doing that in Photoshop, and you’ll get something altogether different—a vague, uninspiring brownish-grey. It’s the same story in just about every graphics package out there.

As it turns out, there’s a good reason the big art apps haven’t tackled this—because it’s really hard! However, a team of researchers at Czech Technical University has finally cracked this long-standing problem. The result of their hard work is Mixbox, a digital model for pigment-based color mixing. Once again, creative application of mathematics has netted aesthetically beautiful results!

Come Up Off Your Color Chart

Combine yellow and blue paint, and the only light reflected by the pigments will be wavelengths in the green range. This is referred to as “subtractive” color mixing because each pigment is taking something away from white light. Credit: Lewin Day

The core issue lies in how digital art apps handle color. Most are built around the RGB color model, which is exactly how our monitors display color—but it’s nothing like how paint and color work in the real world. When you mix blue and yellow light, you get gray – exactly what happens in most digital painting software. Actual paint pigments interact with light in a much more complex way.

What we see when we look at paint is the light reflected from the pigments, not what was absorbed. Mixing paints ends up with a more complex situation, with the combined paint absorbing and scattering different wavelengths as light bounces around between pigment particles. Combine two paints, and you’re left with less reflected light because each different pigment absorbs a different part of the spectrum. You only see what’s left. This is also why you get a murky brown or black result when you mix a whole ton of different colors—the different pigments absorb light from all different parts of the spectrum, and reflect precious little to your eyes.

There’s actually been a mathematical model for the behavior of mixed paints since 1931 – the Kubelka-Munk (K-M) equations. Computer graphics researchers have known about it for decades, but it’s never widely been implemented in commercial software. That’s because implementing it would require tracking multiple pigment channels for every pixel instead of just three channels to cover red, green, and blue values. That was a particular deal-breaker in the early days of computing, but it remains a hurdle to this day. Most art software still relies on graphics pipelines built entirely around RGB. Beyond that, pigments don’t readily map to the whole gamut of available RGB colors.

Left, you can see the results of standard RGB color mixing, while to the right, you can see the results of the K-M method. The latter is far more representative of how paint mixes in real life. Credit: Research paper

The breakthrough came when researchers realized they could knit the principles of the K-M model into the RGB space. Their hack works by decomposing RGB colors into a combination of four basic pigments. The team chose Phthalo Blue, Quinacridone Magenta, Hansa Yellow, and Titanium White as a reasonable basis. Then, they coded a routine to calculate how RGB colors should mix based on their component pigments, using the K-M model. For RGB colors that can’t be made up purely with pigments, there’s also a special “residual” term that accounts for “the missing part of red, green, and blue light that needs to be supplemented to the light reflected off of the pigment mixture in order to exactly match the original RGB color.” It lets the K-M model do its mixing magic without compromising the color space available to the user. The team then had to perform some pigment manipulations to ensure their model wouldn’t end up creating colors that lived outside of the RGB color space, either.

 

Getting this model to run at speed was a must; after all, nobody wants art software that lags when dragging a brush across the screen. The biggest hurdle to overcome was the mathematical operation to decompose RGB colors into their base pigments. To run this quickly, they pre-compute massive lookup tables that handle all the complex K-M math ahead of time. At runtime, the software only needs to do a few quick table lookups to figure out how colors should blend. The whole system acts as a drop-in replacement for regular RGB color mixing, requiring minimal changes to existing software.

The performance overhead is surprisingly minimal, with the model running only about two to three times slower than regular RGB mixing. On modern hardware, that translates to just milliseconds of lag. In most cases, the model can run at over 60 frames per second on a modern computer. The lookup tables add about 96MB of memory overhead, which is pretty much unnoticeable compared to the gigabytes of memory bloat in most modern software.

The K-M model proves far more authentic than standard color-mixing algorithms in commercial software. Credit: research paper

The team has released their implementation on GitHub, opening the door for other developers to integrate proper pigment mixing into their own projects. The code has also been implemented in a simple web painting app that you can try for yourself, right in a browser.  Alternatively, the system has been implemented in a commercial painting app called Rebelle. Whichever way you try it out, though, the results are equally impressive. With the mixing model at play, not only do blue and yellow finally make green, but you get all sorts of subtle effects that happen with real paint. For example, colors actually become more saturated when mixed with white instead of getting washed out.

The main limitation is that the system can only handle four base pigments at a time – adding more would make the lookup tables impractically large. More pigments might make it easier to cover the whole RGB gamut, but they also introduce issues for handling the maths in a neat and tidy manner. The researchers have suggested such expansion might be a valuable area for future work.

It’s quite easy to compare the validity of the K-M model simply by putting it next to real paint as an example. Credit: research paper

In any case, this could be a game-changer for new digital artists coming from traditional media, where color mixing is so much more intuitive. It’s beautiful to see vibrant colors erupting from a canvas, whether real or digital. Now, the latter can more accurately approach the former, giving digital artists greater opportunity for rich expression, colors and all.

 



No comments:

Post a Comment