# Exact Math formula of the MixRGB Node (Multiply Option)

I'm trying to write a GLSL shader that is supposed to do what the cycles nodes do with texture color mixing and stuff, but I'm not sure about the math involved behind the MixRGB node. I'm interested in the multiply mode of the MixRGB node. I suspect that the node is simply multiplying the input colors by default.

output = color1.rgba * color2.rgba


But what happens when I'm setting the frac as well? Is it multiplied along with the others as well like:

output = color1.rgba * color2.rgba * frac


I think the formula is:

output = (1-fac) * color1.rgba + fac * color1.rgba * color2.rgba


So with fac you interpolate between the first color and the product of two colors. You can see below how this works.

Fac = 0.0: Fac = 0.5: Fac = 1.0: • This looks like it but isn't it (1-fac) * color1? Sep 21, 2016 at 18:40
• @GregK. oops, sorry, corrected Sep 21, 2016 at 18:45

color1 *= ((1.0 - fac) + fac * color2)

/* r_col = current value, col = new value, (fac == 0) is no change */
void ramp_blend(int type, float r_col, const float fac, const float col)
{
float tmp, facm = 1.0f - fac;

switch (type) {
case MA_RAMP_BLEND:
r_col = facm * (r_col) + fac * col;
r_col = facm * (r_col) + fac * col;
r_col = facm * (r_col) + fac * col;
break;