I realized the spectral mixing of mypaint in krita

Hello everyone, I have submitted the code and fixed the error of using Z instead of Y for calculating luminosity before. Now that I have done all the work I can, I will devote more time to painting in the future.

13 Likes

Don’t stare yourself blind on precision!

The color gets converted to a spectral power distribution and back to linear and it’s off by 0.0001% which will be multiplied by 255 and then rounded to get the actual color.
The difference is negligible in my opinion.

You used the 81 length spectral set which isn’t accurate at all. It was made for a spectral renderer where all rgb added should sum up to 1 which isn’t accurate at all.

4 Likes

Hi @rvanwijnen, sorry, I don’t think you should be so definitive, all spectral add up to 1 which I think is an advantage as it ensures that all blends don’t go outside the srgb gamut i.e. no clipping, no tonal distortion, if they go outside a certain range they will be forced to clip, the mixbox paper explains that they use oklab for gamut compression to avoid going outside the gamut. In addition to the srgb colour gamut, the dataset I use can also be calculated for the corresponding colour gamut of P3, REC2020, etc, using these datasets is more to the advantage of krita.

There are also several other similar studies: [Subtractive Color Mixture Computation (Page 5) – Project Docs (scottburns.us)](Subtractive Color Mixture Computation (Page 5) – Project Docs)

https://github.com/FocalPaint/spectralSolver

1 Like

Looking back, I feel that CSP does not achieve pigment blending…
It’s hard to imagine that real pigments will maintain brightness during mixing.


And it has an option to adjust brightness, which sounds like SubAdd:
image
Perhaps they just found an algorithm that blends yellow and blue to create green, and then brightened up the middle (like Krita’s geometric mean and parallel, which can also create green)

One characteristic of pigment mixing is that most dark and bright colors have a high saturation in the middle when mixed:

I guessed at first that it was geometric mean. But if it is called ‘visual’ and the brightness remains unchanged, it is highly likely to be oklch (if its red and green colors can blend into a bright yellow)

3 Likes

Regarding Artstudio, it is indeed a pigment spectrum and uses a method similar to Mixbox. They sometimes experience significant hue shifts.
image
image
Perhaps the spectra of certain real pigments were sampled. But it’s not necessarily a good thing. I do know that certain paint colors that look the same will shift in different directions when mixed (cold or warm)But it is impossible to add all the pigments to the algorithm. So a stable color scheme is meaningful. Moreover, it is difficult to distinguish colors under low brightness and saturation conditions.

3 Likes

I am not an expert in code. I would like to have Spectral mixing to get the “real mixing” of course. Technical side is not for me. But i find more useful other things like Mask brush in color smudge, or Overlay mode in RGBA. if people is interested on what do i need this would be my request. Of course the community is what decides.

3 Likes

I also think so. It should be a technology similar to Mixbox, but I still prefer spectra based on rgb, and as you said, sometimes controlling hue is important

1 Like

If it is oklch, it does not need brightness correction option. I prefer geometric mean, or if there is no gamma conversion, it will become black if there is no gamma conversion and mixing

This is the mixed result of oklch:

2 Likes

In paint red and blue doesn’t make purple.
The green is off on the blue and yellow mix.

I will implement the 7 channel mixer myself and start a new thread.

3 Likes

Spectral doesn’t use oklch, the mixing takes place in spectral space with the Kubelka-Munk theory.
Kubelka-Munk makes for the saturation and brightness in the middle. No other colorspace is used. All is based on the CIE XYZ colorspace.

3 Likes

In the build provided by @urzeye, I had a second layer with the “over spectral” blend mode. Does this mean that the spectral mix was being done for each pixel? And there was no noticeable performance issue.

The real problem lies in the smudge brush engine, especially the blur brush

ok , there are problems with the smudge engine, but even if it only works with the pixel engine, this is still a big deal:

Don’t let perfectionism prevent the release of this…

2 Likes

Thanks for all your efforts @rvanwijnen and @urzeye the results look very promising! I am really looking forward to eventually see this being available in Krita! :smiley:
I don’t know which mixing is the most accurate, as long as it is consistent (when using the software you get to know which colour will result from mixing) and that it is pleasing to the eye, I am fine with whatever implementation you decide to use.

I don’t think perfectionism is a problem here, but correctness. Not being correct should prevent the release of this in my opinion.

7 Likes

I conducted some experiments on CSP, despite issues such as testing accuracy, sampling algorithms, and differences in pigment spectral data, it seems to be a mixture of pigments.

(adjust from high to low)



When compared to spectral.js, they always have similar curves. The difference is that the dark color of spectral.js will increase its brightness at the beginning.‘Adjust brightness’ will make the blending curve of CSP more exaggerated
image
blue:spectral.js////////////red:csp/////////// green:csp with high ‘Adjust brightness’

‘Adjust brightness’ should be a change that occurred purely on HSV. It will change the hue of the color and often reduce the saturation of the color. Unless the mixed color is very dark, its effect is poor.

2 Likes

Spectral.js does not adjust hue or brightness in a direct way.

It is an implementation of the Kubelka-Munk theory.

It’s using this theory to mix two spectral curves.

Nothing more, nothing less

1 Like

I feel that the effect seems unsatisfactory, possibly due to the small amount of data per channel. To be honest, I uninstalled it after experiencing it, and the effect of spectral.js is much better.

1 Like

This explains what’s happening on the spectrum.

5 Likes