Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does blending order matter? Is there a way to avoid this? #11

Open
drawtheliner opened this issue Nov 18, 2022 · 2 comments
Open

Why does blending order matter? Is there a way to avoid this? #11

drawtheliner opened this issue Nov 18, 2022 · 2 comments

Comments

@drawtheliner
Copy link

drawtheliner commented Nov 18, 2022

The brown I get by adding Red, Blue and Yellow is different depending on how I add them.

If I add them all at once, I get the color on the left.
If I blend Yellow and Red (1/2), then blend that to blue (1/3), I get the color on the right.
image

All at once:

		var z1 = Mixbox.rgb_to_latent(Color(1,1,0,1))
		var z2 = Mixbox.rgb_to_latent(Color(1,0,0,1))
		var z3 = Mixbox.rgb_to_latent(Color(0,0,1,1))
		var z_mix = []
		z_mix.resize(Mixbox.LATENT_SIZE)
		for i in z_mix.size():
			z_mix[i] = (1.0/3.0*z1[i] +
						1.0/3.0*z2[i] +
						1.0/3.0*z3[i])
		color_mix = Mixbox.latent_to_rgb(z_mix)				

In two blends:

		color_mix2 = Mixbox.lerp(Color(1,1,0,1),Color(1,0,0,1),0.5)
		color_mix2 = Mixbox.lerp(color_mix2,Color(0,0,1,1),1.0/3.0)

Here's another attempt with two blends, this time doing R+B, then that +Y:
(note the brown on the right is different from both, the all-at-once mix on the left, and the previous 2-step blend)
image

@knokelmaat
Copy link

I believe that this is because while RGB -> LATENT -> RGB usually gives the same RGB value as the one you started with, LATENT -> RGB -> LATENT does not.

When doing all three in latent space you get only one traversal of this conversion:
RGB -> LATENT -> RGB

When you mix 2 followed by the third, you get two traversals of this conversion:
RGB -> LATENT -> RGB -> LATENT-> RGB

It is this extra conversion that seems to add an error to the calculations.

I don't know if this behavior is due to an error in the latent_to_rgb or rgb_to_latent code or if it is just inherent to the calculation method used...

@drawtheliner
Copy link
Author

Thank you! Removing one of the conversions eliminated the difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants