Author Topic: Help me suck less (5) - Blending - My turn to help others  (Read 4054 times)

I intended to do this after episode 3 of my quest to suck less:
https://forum.allegorithmic.com/index.php?topic=6276.0

Part of original confusion over the blending was a great tutorial that accidentally mislead me in one place.  It talked using the "Add Sub" blend mode, when the affect being achieved was actually due to the Opacity mask being applied.

But that got me looking into the various blend modes, and I was having trouble finding good documentation on them.


WHAT THIS THREAD IS REALLY ABOUT:

I decided to take matters into my own hands, and have created a grayscale example of each of the 12 Blending Modes.

I simply took a "Gradient Linear 1" made a rotated copy, and blended them together as shown in the first attached image.  Then I went through each of the 12 blend modes and captured the result.

I did not adjust Opacity or make any other changes, so it's still a bit rudimentary, but hopefully someone else can find this useful.


QUESTIONS:
  • Add Sub - This was described as, "The add/sub blend mode acts as if any color above mid grey is positive and any color darker than mid grey is negative.  What defines the "mid gray"?  How bright and how dark does it have to be to no longer be positive or negative?
  • Copy vs. Switch - In my example, these give the same results.  Copy I understand pretty well.  Can someone explain more what Switch actually does and why you'd use it?  I read the words, but they aren't help me much.

CLOSING:

Thanks for any additional insight people can add to this, and I hope someone finds my examples and this thread useful.
Last Edit: August 17, 2015, 09:11:06 pm
Hobbyist
----------
Common "Help" suggestions:
- LOG FILE tips - https://forum.allegorithmic.com/index.php/topic,22451.0.html
- LICENSING issues https://www.allegorithmic.com/contact
- ATTACH files and pictures to posts: https://forum.allegorithmic.com/index.php/topic,23670.0.html

Add/Sub will add values above 0.5 and subtract values below 0.5. The mid grey is 0.5 (or 127 in 8bit if you prefer).
Product Manager - Allegorithmic

Add/Sub will add values above 0.5 and subtract values below 0.5. The mid grey is 0.5 (or 127 in 8bit if you prefer).

That's what is sounds like, but that's not what it looks like.

Why do I end up with a diagonal "band" instead of one thin line where grey is exactly 50%?

It looks more like it's using the middle-third of the scale as the gray zone.

So that's why I was wondering if something like "35-65% = Gray."

I know I'm being dim-witted on this, but I'm not seeing the math that was used to arrive at these locations.  Is the "50%" threshold applied to the background, foreground, both, or on a temporary result that is used to determine whether to add or subtract?

Maybe I'm over-thinking this.

Results above 1 or below 0 are capped in the 0-to-1 range.

1:  0.7 + 0.7 = 1.4  ("1") = White
2:  0.7 + 0.5 = 1.2 ("1") = White
3:  0.7 + 0.2 = 0.9 = Gray
4:  0.5 + 0.7 =
5:  0.5 + 0.5 = Why is the center gray instead of either black or white?
6:  0.5 + 0.2 =
7:  0.2 + 0.7 =>  -0.2 + 0.7 = 0.5 = Gray
8:  0.2 + 0.5 => -0.2 -0.5 = -0.7 ("0") = Black
9:  0.2 + 0.2 => -0.2 -0.2 = 0 = Black

Last Edit: August 17, 2015, 03:29:08 am
Hobbyist
----------
Common "Help" suggestions:
- LOG FILE tips - https://forum.allegorithmic.com/index.php/topic,22451.0.html
- LICENSING issues https://www.allegorithmic.com/contact
- ATTACH files and pictures to posts: https://forum.allegorithmic.com/index.php/topic,23670.0.html

Still obsessing over the "Add Sub" blend mode...

I thought I was closer, but when I tried to work through some cases, it fell apart again.

Restating the rule more verbosely, this is what I thought I'd figured out...
  • If the Foreground is above 50%, it will be added to the Background.
  • If the Foreground is below 50%, it will be subtracted from the Background.

Results above 1 or below 0 are capped in the 0-to-1 range, as usual

I'm left with some puzzles:
  • If both the Foreground and Background are near 50%, shouldn't the result be either near-black or near-white?
  • I am having trouble explaining the resulting middle row of results.
  • Every time I do the math "manually" I seem to run into an issue.  For example, when you transition from under to over 50%, why don't you get a sudden transition from black to white?

I used a color-picker and, assuming a linear scale, I decided my "0.2" value in my previous post should be close to 0.3.

Also, to further illustrate my problems, I used some "mid-gray" examples slightly above and slightly below the 50% level.

In this example, I am listing Background first:

1:  0.7 + 0.7 = 1.4 = "1"  =  White
2:  0.5 + 0.7 = 0.8 = Bright Gray
3:  0.3 + 0.7 = 0.6 = Light Gray

4a:  0.7 + 0.51 = 1.21 = "1" = White ---> But it's gray
4b:  0.7 - 0.49 = 0.31 = Gray... Should we have darkish-gray right next to white (4a)?

5a:  0.5 + 0.5 = 1.0 Why is the center gray instead of either black or white?
5a:  0.5 -  0.5 = 0.0 Why is the center gray instead of either black or white?

6a:  0.3 + 0.51 = 0.81 = gray... Should we have darkish-gray right next to black (6b)?
6a:  0.3 - 0.49 = -0.19 = "0" = Black ---> But it's rather dark

7:  0.7 - 0.3 =>  0.4 = Gray
8:  0.5 - 0.3 =>  0.2 = Dark Gray
9:  0.3 - 0.3 =>  0.0 = Black
Last Edit: August 17, 2015, 05:40:53 am
Hobbyist
----------
Common "Help" suggestions:
- LOG FILE tips - https://forum.allegorithmic.com/index.php/topic,22451.0.html
- LICENSING issues https://www.allegorithmic.com/contact
- ATTACH files and pictures to posts: https://forum.allegorithmic.com/index.php/topic,23670.0.html

Hey justaviking,

for me it seems the AddSub behaves strange, too. You're not alone :P

What I think it does is actually quite simple. I tested that with just plain colours so everyone understand that better.
(screenshot 1)

The Background is a plain colour with a value of 128.
If I change the foreground value to 100, the AddSub result is 73.

The AddSub takes the difference between 128 (50%) and the foreground (128/100 = -28) and adds this difference value to the foreground. 100 + -28 = 73.

If the foreground is higher than 128, the result will be a positive number and so the result is higher.

Background: 128
Foreground: 150
AddSub Result: 173

150/128 Difference: 22

Foreground + Difference = 150 + 22 = 173/172

So the AddSub does Subtract & Add correctly all the values below/above 128/50% but the result is nothing I would expect when reading the Description
"Add/Sub will add values above 0.5 and subtract values below 0.5. The mid grey is 0.5 (or 127 in 8bit if you prefer)."

EDIT:
After changing the Background value from 128 to any other number, the calculation becomes even more complicated.

Simple number:
Foreground: 150
Background: 120

Differences to 128:
Foreground: +22
Background: -8
Differences added together: +22 + -8 = 15

AddSub Result: 165

Foreground + Difference = 150 + 15 = 165.

My conclusion: Both, the foreground and the background, will calculate the difference between the input values and the mid-grey (127/128).  If the value is higher (150), the difference will be positive (22), if the value is lower than 128 (100, for instance) the difference will be a negative number (-28). Add together the differences and then add the result to the foreground.
(22 + -28 = -6)
150 + -6 = 145/144

Maybe I'm doing something wrong... Does it even sound plausible?


Best Regards
Last Edit: August 17, 2015, 11:57:12 am
Environment Artist - Twitter

The Add/Sub mode maps the "black to white" range to the "-1 to 1" range. So if you blend :
  • black on black => -1 + -1 = -2 => clamped to -1 (because of saturation) => black
  • black on grey => -1 + 0 = -1 => black
  • grey on grey => 0 + 0 = 0 => grey
  • white on white  => 1 + 1 = 2 => clamped to 1 (because of saturation) => white
This is not an uncommon way to encode signed values. For example, this is how tangential normal maps encode the x and y values of normals in the red and green channels.

@Cryilla,

Thanks for the -1 to +1 range info. For this discussion I'll continue to normalize 0-->255 as 0-->1.




ABOUT THE "ADD SUB" BLEND MODE MYSTERY


A MAJOR CLUE (and what I was doing wrong):

@Fabian,

You supplied the detail I was missing. THANKS!

It is the "distance from the middle" that gets added or subtracted.

That means if you have a value of 0.4, you subtract 0.1 because that is the distance away from 0.5.  I kept trying to subtract the 0.4 because it was less than 0.5.



MYSTERY SOLVED -- FIGURED OUT THE MATH

Here is the math for "Add Sub" as I see it, and it fits the results I got (now switching to a 0-to-255 scale)...

Blended value = Background + (Foreground  - 128)

Now it makes sense.
If foreground is >50%, the value in parentheses is positive, so you are adding.
If foreground is <50%, the value in parentheses is negative, so you are "subtracting."

Based in the trials I did, you get the same result if you swap Background and Foreground in the equation above.

If you were at exactly the midpoint, you would add or subtract zero, so no change.  (Actual midpoint is 127.5, right?)

I believe the mystery is now solved.  Now to figure out "Switch" and we will have perfect knowledge.   ;)
Last Edit: August 17, 2015, 09:21:03 pm
Hobbyist
----------
Common "Help" suggestions:
- LOG FILE tips - https://forum.allegorithmic.com/index.php/topic,22451.0.html
- LICENSING issues https://www.allegorithmic.com/contact
- ATTACH files and pictures to posts: https://forum.allegorithmic.com/index.php/topic,23670.0.html

Hey justaviking,

would you like to add the 'Help me suck less'-Series to the Community Tutorial Section?
You could create a post in that for every new episode and therefore collect all the knowledge you gained during your learning path.
This could help new and advanced Substance users equally and the stuff is written down nicely in one location.

I like the idea behind your threads and enjoyed testing your latest one myself :P
If you would like, I could help doing that.


Best Regards
Environment Artist - Twitter

@Fabian,

I'm honored that you think there might be some value in my string of posts.  I has some visions of turning them into a pseudo-tutorial by creating a "Master Post" to introduce the topic and the goal of making the mesh fabric, and then using it like a table of contents to link to the specific threads.

I haven't explored the Community Tutorial section.   :-[   I really need to explore this forum some more, obviously.  I'll follow your guidance, and if others can benefit as I go through my learning process, that would be great.
Hobbyist
----------
Common "Help" suggestions:
- LOG FILE tips - https://forum.allegorithmic.com/index.php/topic,22451.0.html
- LICENSING issues https://www.allegorithmic.com/contact
- ATTACH files and pictures to posts: https://forum.allegorithmic.com/index.php/topic,23670.0.html

The Add/sub blend work great with Curvature so the white add and dark sub

all middle grey (128) doesn't effect anything

I know this forum is for Designer, but still... Could anyone kindly explain what's the practical difference between AddSub and Linear Light modes in Painter? From what I see above, I would assume they should produce identical results. Maybe there are some specific cases when one of them should be used and other one shouldn't? Thanks in advance.

here are the exact formulas :)

s : source
d : destination

Linear Light :   s<0.5 ? max(d+2.0*s-1.0,0.0) : min(d+2.0*(s-0.5),1.0)
Add Sub:   2.0*s+d-1.0
Product Manager - Allegorithmic

Thanks! However, I'm still a bit confused. From what I see both formulas produce the same results for numbers between 0.0 and 1.0 (for what my math skills is worth :) ). What about the practical differences? Will there be a case when the result between the Linear Light and AddSub will be different?

It'll be different in case you are working with hdr values :)
Product Manager - Allegorithmic

Oh... I think I'm starting to get it. HDR values are to be found in something like Height channel, because it uses floating point data (L32F by default). So, I would assume that AddSub is a special-case blend mode that acts like Linear Light in non-float channels like L8 or RGB8 and acts differently in floating point channels, like Height L32F. Will something like this be a correct assumption?

By the way, thank you for taking your time to explain this. I'm not confortable when there's just a tiny bit of something that I don't understand, and you're helping me with that a lot ::)
Last Edit: April 29, 2016, 11:56:39 am