Page MenuHome

Compositor: Alpha Mode
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Nov 23 2020, 12:16 PM.

Details

Summary

D9211: Compositor: Ensure keying node result is pre-multiplied introduced pre-multiplying the color for the keying node. This
pre-multiplication should also be done by other keying nodes and should be
the default operation for alpha node.

This patch will change the logic of keying nodes (Cryptomatte Node,
Channel Matte, Chroma Matte, Color Matte, Difference Matte, Distance
Matte, Luminance Matte) and breaks old files.

The Set alpha node has a mode parameter. This parameter changes
the logic to Apply Mask the alpha on the RGBA channels of the input color
or only replace the alpha channel (old behavior).

The replace mode is automatically set for older files. When adding
new files the the multiply mode is set.

Diff Detail

Repository
rB Blender

Event Timeline

Jeroen Bakker (jbakker) requested review of this revision.Nov 23 2020, 12:16 PM
Jeroen Bakker (jbakker) retitled this revision from Compositor: Premul color when Setting Alpha to Compositor: Ensure premult color when setting alpha..Nov 23 2020, 12:17 PM

This breaks file compatibility.

We should communicate better which compatibility is breaking. For example, the Keying Node (which is mentioned in the description) will behave the same. So it is only the "other" keying node, and the "Set Alpha" nodes.

To me this is inevitable breakage which we need to do sooner or later, so now is as good time as anything. But nice to confirm this with Brecht.

I don't mind breaking compatibility for the keying nodes. The files there usually don't have an alpha channel to begin with, so it's doesn't matter.

For the Set Alpha node I'm less sure how it is used in practice. We could add an enum with options Replace and Multiple on that node? Maybe that's useful for other purposes anyway.

Jeroen Bakker (jbakker) planned changes to this revision.EditedNov 23 2020, 2:21 PM

Like proposed by @Brecht Van Lommel (brecht). By default it is set to Multiply. When loading older files we set Replace.

  • Added mode to Set Alpha Node.
  • Old files will use replace mode.
  • New files will use multiply mode.
Jeroen Bakker (jbakker) retitled this revision from Compositor: Ensure premult color when setting alpha. to Compositor: Alpha Mode.Nov 23 2020, 4:23 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)

I'm starting to have doubts here.

Having an option for compatibility in Set Alpha node seems fine.

But what is expected behavior for the "new" "proper" behavior, what is the mental model? It is simple multiplication, or is it something more elaborate like: output is properly premultiplied RGBA, with A channel exactly matched to what was passed to the Alpha socket?

source/blender/makesrna/intern/rna_nodetree.c
6047

Both color and alpha (aka RGBA) are multiplied by the alpha socket. I think there should be a way to word this more explicit in the tooltip.

I think the mental model for Multiply is applying an alpha mask to an image. The alpha channel is not necessarily the same as either the RGBA image or the alpha mask, it's a combination. We could call it "Apply" if that is more clear? Not sure if there is a better term.

@Brecht Van Lommel (brecht), sure mental model of "Multiply" is "apply a mask". But I was more wondering about what is the proper mental model of the "Set Alpha" node. In other words, what is the expected behavior? Replace the alpha (keeping the premultiplication of color) or "apply the mask" behavior?

Not sure I understand the question then. Multiplying I think is by far the most useful behavior and should be the default, but not sure if that's what you mean by it being the mental model of the node.

I do think that set alpha node always did what it says it did, but with this change the name doesn't match with what the user wants or the node does. We could also see it an opportunity to rename the node to Apply Mask Node and change the modes to Color and Alpha or Alpha. But before that we should validate with @Sebastian Koenig (sebastian_k) and Andy.

Evan Wilson (EAW) added inline comments.
source/blender/compositor/operations/COM_ChannelMatteOperation.cpp
114–115
source/blender/compositor/operations/COM_ChromaMatteOperation.cpp
62–64

Same

source/blender/compositor/operations/COM_ColorMatteOperation.cpp
60–62

Same.

source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp
67–69

Same.

source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp
70–72

Same.

source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h
24–27

Comments should always start with a capital letter and end with a full stop.

this program converts an input color to an output value.

I could understand this description being used (for example) to describe the RGB to BW operation, where 3 input channels are combined into a single value output channel. I don't see how it accurately describes the SetAlphaMultiply operation, unless I am misunderstanding something, which I do admit is quite possible. 😊

it assumes we are in sRGB color space.

It does? Why? Should it? Doesn't this go against the rest of the compositor assuming a linear space?

37
source/blender/makesrna/intern/rna_nodetree.c
6047

Perhaps "Multiply the input image's RGBA channels by the alpha input value."? "Multiply the input colors & alpha by and alpha input value."? Or just show the formula "RGBA*A"?

If the node was renamed to Apply Mask Node, then I think "Apply the mask to the input color and alpha." could work.

Jeroen Bakker (jbakker) marked 7 inline comments as done.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Fixed style comments (capital + ends with '.')
  • Better descriptions for set alpha node
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Jan 5 2021, 4:00 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Jan 5 2021, 4:03 PM
Jeroen Bakker (jbakker) removed 1 blocking reviewer(s): Brecht Van Lommel (brecht).
This revision is now accepted and ready to land.Jan 5 2021, 4:03 PM
Jeroen Bakker (jbakker) marked 2 inline comments as done.
  • Renamed CMP_NODE_SETALPHA_MODE_* items.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Jan 5 2021, 4:23 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.

I'm am sorry for being so late with commenting on this.
I think it's good having that enum in that node!
I am a bit unsure of this terminology. "Replace Alpha" makes sense to me. "Apply Mask" however seems weird to me. Why not simply call it "Multiply Alpha"? Isn't that what the node is doing anyway? "Apply mask" implies that a mask is used, which in compositing is quite common indeed, and we also do have actual masks in the compositor. But more often the Set Alpha node is not used to only apply the mask from a mask node to the image, but the result of some operations with the Alpha channel of a render or an image, sometimes involving masks, sometimes not.
Also, there seem to be just 2 options in the node, which are opposites of eachother, so if the terms are not made up of the same logic and use different words for the same thing ("Alpha", "Mask"), I think it is confusing toi the user.
That's why I would suggest to use "Multiply Alpha" instead. The tooltip then makes it clear what's happening.