Hello all, my name is Ronald van Wijnen and I’m the author of spectral.js GitHub.
Spectral.js is a javascript library for realistic paint like color mixing using the Kubelka-Munk equations.
It is already being used by the generative art scene and is well received.
With the help from a Krita developer (thank you Dmitry!) I have integrated this library in Krita.
Some technical details: a sRGB triplet is converted to spectral space by combining three (red, green and blue) premade reflectance curves (380 to 730 wavelengths in 10 nm steps) where the input sRGB triplet is the weight for the generated destination spectral curve.
These generated curves are than mixed using the Kubelka-Munk equations, which give a nice saturated color mix with the characteristics of real life paint.
To get a perceptually even distribution between the two colors spectral.js uses a concentration function which calculates the concentration for a color using the lightness value (a lighter color needs more ‘parts’ for the mix then a darker color).
The round-trip (sRGB → spectral → XYZ → sRGB) error is 0% for any given input.
A mixed color can be out of the sRGB gamut, this was the case for 0.025% in my tests, when out of gamut the deviation is maximum 0.05%, therefor clipping is used, gamut mapping is too computational heavy for this little deviance.
The reason for this little out of gamut results is because of the smooth and optimized red, green and blue base spectral reflectance curves.
Pictures say more than a thousand words:
I have been in discussions regarding this topic on this forum before and those discussion were, although unfruitful, very informative and were the basis for my implementation (thank you @urzeye for laying the groundwork).
I’m not very familiar with the Krita source code and could use some help on optimizing this and further development.
The merge request can be found here: invent.kde.org
A windows executable for testing can be found here: disk.yandex.ru
(Note by Krita developer: colour smudge brush in this build does not work in non-spectral mode, this is not a replacemtent for the current version and should be used for testing only.)
To use spectral blending create a new layer and choose Spectral as blending mode, the opacity will control the mixing factor.
Other interesting topics on this forum:
I realized the spectral mixing of mypaint in krita - Develop - Krita Artists (krita-artists.org)
Rebelle 5 Pigments - Physical Color Mixing - General Forums / off-topic talks - Krita Artists (krita-artists.org)
One more note regarding MyPaint: MyPaint has spectral mixing already but they are using the Weighted Geometric Mean (WGM) for their mixing function, in my opinion the WGM (although easy to implement and not computational heavy) give desaturated colors as seen in this example:
To my best knowledge Krita will be the first open source painting software which utilizes the Kubelka-Munk algorithm and this is big in my opinion!
Sorry for being this lengthy and technical but I’m a programmer and have been researching this for over a year now.
Looking forward to the discussion,
Ronald