# I'd like to understand the expression of mix RGB node.

Hello. Thanks for watching.
Now I’m trying to understand what is happening in calculating in mix RGB nodes.

Mix RGB nodes have three sockets; fac, top, bottom. the value of bottom is affected by fac. I assumed that that means the bottom is multiplied by fac. Is this right?

I experimented that using this blend file. untitled.blend (505 KB)
When the blend type was add, it worked well. (because the result of A and B was the same)
However, when the blend type was multiply, it didn’t work. (the result of C and D was different).

I’d appreciate if you could tell me what’s wrong in this.
Type add and multiply, etc have the different expression for fac?
Sorry for confusing nodes.

the math involved changes a lot from function to function…

But most of them just result in the interpolation of the color A and the function(A, B) by the Fac.

In your example: you have C= interp(CA, CACB, Noise) and D=interp(CANoise, CANoiseCB, 1)…
C= ((1 - Noise) * CA) + (Noise * CA * CB) == CA * ((1-Noise)+(Noise*CB))
D= ((1 - 1) * CA * Noise) + (Noise * CA * CB) == CA * (Noise * CB)

as (1-Noise)+(CBNoise) is different from (NoiseCB), the results should be different also.

with A and B:
A= (1-Noise)(CA) + Noise(CA+CB)
B= (Noise * CB) + CA
which yield also different results…

Noise will give values around 0.5, and it’s possible to get near the following condition:
(2CA+CB)/ 2 = CA + (CB/2) => CA+CB/2 =CA+CB/2

if you still want to know what the node really does, you can have a look into the source code:
https://svn.blender.org/svnroot/bf-blender/trunk/blender/intern/cycles/kernel/svm/svm_mix.h
(if you understand a bit of math, the svm_mix.h is not difficult to read ;))

Thank you very much for your detailed reply. You’re very kind.

I’m sorry but the expressions and codes used here were difficult for me to understand especialy in English.
Is it possible to express it using node trees just like I tried in the blend file?

Also, I want to make sure that each type like add, multiply, overlay, burn, etc have each different expression for fac and bottom socket?

For D, change the first node from Multiply to Screen and I think it’s a match. (Don’t ask me to explain it mathematically, though.)

Thank you for your answer. Looks a little bit different for me though.
I’m going to study it with my fridends.
Thank you and sorry for confusing question.

just for fun… here’s a file with all the blending modes of the RGBmixer, reduced to the basic math.

Blender_RGBmix_Example.blend (959 KB)

All Nodegroups could be replaced by nodes that are already in blender, but for illustration purposes I recreated them with the most basic elements of math!! (+, -, *, /)

Have fun!

Thanks. But… I can find nothing in the blend file… looking like almost default.
Seems it has disappeared…?

the file has only nodegroups… you need to add them in your materials, or append them into your file.
Add a new cycles material, and then add the node groups (add node > group > RGB_*).
there are some utility groups, but the one you should look into are the ones that start with ‘RGB_’

Oh, I found it! looks interesting! Thank you very much!

Hi

you can find some of the math here https://en.m.wikipedia.org/wiki/Blend_modes. I think that this math is mostly universal across applications including blender. i got some more info on this pm if you want.