1
$\begingroup$

Okay, I can't believe I never noticed this until today but... the MixRGB node's Subtract and Difference blend modes both appear to produce the same output.

Start with white and take blue away from it... both blend modes produce yellow.

To specify precisely with hex codes: #ffffff minus #0000ff equals #ffff00 no matter which blend mode is used.

So pardon my wording but, is there any difference?

Let's consult the Blender Manual:

Subtract

Taking Blue away from white leaves Red and Green, which combined make Yellow. Taking Blue away from Purple leaves Red. Use this to desaturate an image. Taking away yellow makes an image bluer and more depressing.

Difference

It takes out a color. The color needed to turn Yellow into White is Blue. Use this to compare two very similar images to see what had been done to one to make it the other; sort of like a change log for images. You can use this to see a watermark (see Watermark images) you have placed in an image for theft detection.

So the descriptions are a little different... but I reiterate: is there any difference?

(If the answer is that they are identical, that's fine. I just want to know before I go creating a bunch of node setups based on an assumption.)

$\endgroup$
5
  • 1
    $\begingroup$ No, they are not producing the same result. It might look like it when you use white as the first color, but change that to red and you will already see a difference. $\endgroup$ Commented May 31, 2022 at 11:28
  • $\begingroup$ Thanks. I tried setting Color1 to red (#ff0000) and plugged an image into Color2. In this configuration there is a clear difference. The best I can explain it though is that Subtract takes away non-reds leaving a red and black two-tone image, while Difference takes away from red according to what the other colors are, which leaves red where darker areas of Color2's image would be. $\endgroup$
    – Mentalist
    Commented May 31, 2022 at 11:48
  • 2
    $\begingroup$ Here is a more technical description: en.wikipedia.org/wiki/Blend_modes#Subtract (Subtract simply subtracts pixel values of one layer with the other. In case of negative values, black is displayed / Difference subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value.) $\endgroup$
    – Blunder
    Commented May 31, 2022 at 11:55
  • 1
    $\begingroup$ @Mentalist Actually, when Color1 is red and you subtract a colorful image, it's not taking away non-reds from the image. All red values of the image are subtracted from the red color, and since the green and blue channels are 0 in Color1, every other color of the image gets subtracted from 0 leaving a negative value (if the node is not clamped) which shows as black. $\endgroup$ Commented May 31, 2022 at 11:55
  • $\begingroup$ I think I get the gist of it. If I have red as Color1and I want to invert it to cyan, I should use Difference, with white as Color2. I someone posts an answer that can be understood intuitively (maybe with some visual examples), I will most likely accept it. $\endgroup$
    – Mentalist
    Commented May 31, 2022 at 12:40

1 Answer 1

5
$\begingroup$

Difference is the absolute value of Subtract ie. $|\mathrm{Color1} - \mathrm{Color2}|$. So they will be the same if Color1 is >= Color2.

See this answer for more.


edit: I'll give a small example with grayscale colors.

Subtract vs Difference with grayscale colors

With Subtract, Color2 is subtracted from Color1.

  1. When Color2 is black, you get Color1.
  2. As Color2 gets brighter, the output gets darker.
  3. When Color2 reaches Color1, you get black.
  4. When Color2 is brighter than Color1, it can't get any darker so it just stays black.

Difference is the same except in case 4.

  1. (For Difference) When Color2 is brighter than Color1, instead of being stuck at black, it starts getting lighter again.

If Subtract means "subtract Color2 from Color1" then Difference means "subtract the darker from the lighter".

$\endgroup$
16
  • 1
    $\begingroup$ So you could think of Difference as entry-wise Distance? $\endgroup$ Commented May 31, 2022 at 12:34
  • 1
    $\begingroup$ @GordonBrinkmann That's what "entry-wise" means. Also that's not the right formula for Fac in Difference, Fac lerps between Color1 and |Color1-Color2|. $\endgroup$
    – scurest
    Commented May 31, 2022 at 13:23
  • 1
    $\begingroup$ @GordonBrinkmann An entry is a component, so Vectors and colors have 3 entries. Entry, or component-wise means separately for each. Vector Math > Multiply is an entry-wise operation, because it multiplies V1.x by V2.x, V1.y by V2.y, and V1.z by V2.z and that's it - you would have the same by separating V1 into 3 values, separating V2 into 3 values, using 3 scalar math > multiply nodes, and then combining the results into a vector. Vector Math > Distance isn't an entry-wise operation - you can use Subtract > Absolute, but apparently RGB Difference ix node is a single node replacement. $\endgroup$ Commented May 31, 2022 at 15:06
  • 2
    $\begingroup$ @GordonBrinkmann (1-Fac)*Color1 + Fac*|Color1-Color2| $\endgroup$
    – scurest
    Commented May 31, 2022 at 18:10
  • 1
    $\begingroup$ @GordonBrinkmann Wow, this is great! In the past I googled how Fill differs from Opacity in Photoshop and I only learned the former doesn't affect effects like shadow, while the latter does. I nodified the formula you described: i.imgur.com/UR9Vnbu.png and got the same color in Photoshop with blend mode = difference and Fill = 0.35 (factor used in Blender). So in Photoshop the opacity lerps between layers, and Fill is a color multiplier. $\endgroup$ Commented Jun 1, 2022 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .