diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-01-05 18:16:18 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-01-05 18:34:55 +0300 |
commit | 9dbea1db66da5e277e8279811d66096751f38d29 (patch) | |
tree | 4fe64c2cb671e0c08f91a37d80c180689c9dec1d /source/blender/compositor | |
parent | 357e519575411cc338acfe899fde6e5ea3476801 (diff) |
Compositor: Alpha Mode
{D9211} 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.
Reviewed By: Sergey Sharybin
Differential Revision: https://developer.blender.org/D9630
Diffstat (limited to 'source/blender/compositor')
19 files changed, 73 insertions, 62 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 26d29f72efb..19eeb90c822 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -355,8 +355,6 @@ set(SRC operations/COM_KeyingDespillOperation.h operations/COM_KeyingOperation.cpp operations/COM_KeyingOperation.h - operations/COM_KeyingSetAlphaOperation.cpp - operations/COM_KeyingSetAlphaOperation.h operations/COM_ColorSpillOperation.cpp operations/COM_ColorSpillOperation.h @@ -461,8 +459,10 @@ set(SRC operations/COM_MapRangeOperation.h operations/COM_MapValueOperation.cpp operations/COM_MapValueOperation.h - operations/COM_SetAlphaOperation.cpp - operations/COM_SetAlphaOperation.h + operations/COM_SetAlphaMultiplyOperation.cpp + operations/COM_SetAlphaMultiplyOperation.h + operations/COM_SetAlphaReplaceOperation.cpp + operations/COM_SetAlphaReplaceOperation.h # Distort operation operations/COM_DisplaceOperation.cpp diff --git a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp index c927865489b..598cd7b7745 100644 --- a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ChannelMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ChannelMatteNode::ChannelMatteNode(bNode *editorNode) : Node(editorNode) { @@ -64,7 +64,7 @@ void ChannelMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)node->storage, node->custom2); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); if (convert != nullptr) { diff --git a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp index 75d161d7d4d..83e88b35f92 100644 --- a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ChromaMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ChromaMatteNode::ChromaMatteNode(bNode *editorNode) : Node(editorNode) { @@ -48,7 +48,7 @@ void ChromaMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)editorsnode->storage); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.mapInputSocket(inputSocketImage, operationRGBToYCC_Image->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp index f5cb84975e9..865eee5427f 100644 --- a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ColorMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ColorMatteNode::ColorMatteNode(bNode *editorNode) : Node(editorNode) { @@ -46,7 +46,7 @@ void ColorMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)editorsnode->storage); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.mapInputSocket(inputSocketImage, operationRGBToHSV_Image->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp index 7ca4e1f76fc..27ef98af8f3 100644 --- a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp +++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp @@ -19,13 +19,13 @@ #include "COM_CryptomatteNode.h" #include "COM_ConvertOperation.h" #include "COM_CryptomatteOperation.h" -#include "COM_SetAlphaOperation.h" #include "BLI_assert.h" #include "BLI_hash_mm3.h" #include "BLI_listbase.h" #include "BLI_string.h" +#include "COM_SetAlphaMultiplyOperation.h" #include <iterator> CryptomatteNode::CryptomatteNode(bNode *editorNode) : Node(editorNode) @@ -61,13 +61,13 @@ void CryptomatteNode::convertToOperations(NodeConverter &converter, separateOperation->setChannel(3); converter.addOperation(separateOperation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.addLink(operation->getOutputSocket(0), separateOperation->getInputSocket(0)); converter.addLink(separateOperation->getOutputSocket(0), operationAlpha->getInputSocket(1)); - SetAlphaOperation *clearAlphaOperation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *clearAlphaOperation = new SetAlphaMultiplyOperation(); converter.addOperation(clearAlphaOperation); converter.addInputValue(clearAlphaOperation->getInputSocket(1), 1.0f); diff --git a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp index b579502e068..3d538e9b4a0 100644 --- a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp @@ -19,7 +19,7 @@ #include "COM_DifferenceMatteNode.h" #include "BKE_node.h" #include "COM_DifferenceMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" DifferenceMatteNode::DifferenceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -43,7 +43,7 @@ void DifferenceMatteNode::convertToOperations(NodeConverter &converter, converter.mapInputSocket(inputSocket2, operationSet->getInputSocket(1)); converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0)); - SetAlphaOperation *operation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operation = new SetAlphaMultiplyOperation(); converter.addOperation(operation); converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp index 946d55d33fc..37aeb5c8504 100644 --- a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp @@ -21,7 +21,7 @@ #include "COM_ConvertOperation.h" #include "COM_DistanceRGBMatteOperation.h" #include "COM_DistanceYCCMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -39,7 +39,7 @@ void DistanceMatteNode::convertToOperations(NodeConverter &converter, NodeOutput *outputSocketImage = this->getOutputSocket(0); NodeOutput *outputSocketMatte = this->getOutputSocket(1); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); /* work in RGB color space */ diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cpp b/source/blender/compositor/nodes/COM_KeyingNode.cpp index 9f0cdcbd552..4e81a412c29 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingNode.cpp @@ -32,7 +32,7 @@ #include "COM_DilateErodeOperation.h" -#include "COM_KeyingSetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" #include "COM_GaussianAlphaXBlurOperation.h" #include "COM_GaussianAlphaYBlurOperation.h" @@ -323,7 +323,7 @@ void KeyingNode::convertToOperations(NodeConverter &converter, } /* set alpha channel to output image */ - KeyingSetAlphaOperation *alphaOperation = new KeyingSetAlphaOperation(); + SetAlphaMultiplyOperation *alphaOperation = new SetAlphaMultiplyOperation(); converter.addOperation(alphaOperation); converter.mapInputSocket(inputImage, alphaOperation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp index e435cefeefe..8bfea1eff49 100644 --- a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ConvertOperation.h" #include "COM_LuminanceMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" LuminanceMatteNode::LuminanceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -42,7 +42,7 @@ void LuminanceMatteNode::convertToOperations(NodeConverter &converter, converter.mapInputSocket(inputSocket, operationSet->getInputSocket(0)); converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0)); - SetAlphaOperation *operation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operation = new SetAlphaMultiplyOperation(); converter.addOperation(operation); converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_SetAlphaNode.cpp b/source/blender/compositor/nodes/COM_SetAlphaNode.cpp index 7b722fe4440..233a5e96ff4 100644 --- a/source/blender/compositor/nodes/COM_SetAlphaNode.cpp +++ b/source/blender/compositor/nodes/COM_SetAlphaNode.cpp @@ -18,12 +18,23 @@ #include "COM_SetAlphaNode.h" #include "COM_ExecutionSystem.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" +#include "COM_SetAlphaReplaceOperation.h" void SetAlphaNode::convertToOperations(NodeConverter &converter, const CompositorContext & /*context*/) const { - SetAlphaOperation *operation = new SetAlphaOperation(); + const bNode *editorNode = this->getbNode(); + const NodeSetAlpha *storage = static_cast<const NodeSetAlpha *>(editorNode->storage); + NodeOperation *operation = nullptr; + switch (storage->mode) { + case CMP_NODE_SETALPHA_MODE_APPLY: + operation = new SetAlphaMultiplyOperation(); + break; + case CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA: + operation = new SetAlphaReplaceOperation(); + break; + } if (!this->getInputSocket(0)->isLinked() && this->getInputSocket(1)->isLinked()) { operation->setResolutionInputSocketIndex(1); diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp index 956a2cc86ee..a2c6fd47771 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp @@ -111,10 +111,10 @@ void ChannelMatteOperation::executePixelSampled(float output[4], alpha = (alpha - limit_min) / limit_range; } - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ - /* don't make something that was more transparent less transparent */ + /* Don't make something that was more transparent less transparent. */ output[0] = min(alpha, inColor[3]); } diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp index 389aeaf6fed..29e18047578 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp @@ -60,8 +60,8 @@ void ChromaMatteOperation::executePixelSampled(float output[4], this->m_inputKeyProgram->readSampled(inKey, x, y, sampler); this->m_inputImageProgram->readSampled(inImage, x, y, sampler); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /* Algorithm from book "Video Demistified," does not include the spill reduction part */ diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp index b8749bec4b8..17ada8d89b2 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp @@ -58,8 +58,8 @@ void ColorMatteOperation::executePixelSampled(float output[4], this->m_inputImageProgram->readSampled(inColor, x, y, sampler); this->m_inputKeyProgram->readSampled(inKey, x, y, sampler); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ if ( diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp index 7d79dcc657d..ecc2fc2e85f 100644 --- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp @@ -65,8 +65,8 @@ void DistanceRGBMatteOperation::executePixelSampled(float output[4], distance = this->calculateDistance(inKey, inImage); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /*make 100% transparent */ diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp index f7cc6e2d4de..096930d0a83 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp @@ -68,8 +68,8 @@ void LuminanceMatteOperation::executePixelSampled(float output[4], alpha = (luminance - low) / (high - low); } - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /* don't make something that was more transparent less transparent */ diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp index 47daef8d190..3853a953c26 100644 --- a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp @@ -13,12 +13,12 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright 2020, Blender Foundation. + * Copyright 2011, Blender Foundation. */ -#include "COM_KeyingSetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" -KeyingSetAlphaOperation::KeyingSetAlphaOperation() +SetAlphaMultiplyOperation::SetAlphaMultiplyOperation() { this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_VALUE); @@ -28,16 +28,16 @@ KeyingSetAlphaOperation::KeyingSetAlphaOperation() this->m_inputAlpha = nullptr; } -void KeyingSetAlphaOperation::initExecution() +void SetAlphaMultiplyOperation::initExecution() { this->m_inputColor = getInputSocketReader(0); this->m_inputAlpha = getInputSocketReader(1); } -void KeyingSetAlphaOperation::executePixelSampled(float output[4], - float x, - float y, - PixelSampler sampler) +void SetAlphaMultiplyOperation::executePixelSampled(float output[4], + float x, + float y, + PixelSampler sampler) { float color_input[4]; float alpha_input[4]; @@ -48,7 +48,7 @@ void KeyingSetAlphaOperation::executePixelSampled(float output[4], mul_v4_v4fl(output, color_input, alpha_input[0]); } -void KeyingSetAlphaOperation::deinitExecution() +void SetAlphaMultiplyOperation::deinitExecution() { this->m_inputColor = nullptr; this->m_inputAlpha = nullptr; diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h index b786240f215..db58b18688a 100644 --- a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h @@ -13,7 +13,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright 2020, Blender Foundation. + * Copyright 2011, Blender Foundation. */ #pragma once @@ -21,16 +21,17 @@ #include "COM_NodeOperation.h" /** - * Operation which is used by keying node to modify image's alpha channels. - * It keeps color properly pre-multiplied. + * This operation will apply a mask to its input image. + * + * `output color.rgba = input color.rgba * input alpha` */ -class KeyingSetAlphaOperation : public NodeOperation { +class SetAlphaMultiplyOperation : public NodeOperation { private: SocketReader *m_inputColor; SocketReader *m_inputAlpha; public: - KeyingSetAlphaOperation(); + SetAlphaMultiplyOperation(); void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp index bf8fbacbfe1..cd6e82902cc 100644 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp @@ -16,9 +16,9 @@ * Copyright 2011, Blender Foundation. */ -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaReplaceOperation.h" -SetAlphaOperation::SetAlphaOperation() +SetAlphaReplaceOperation::SetAlphaReplaceOperation() { this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_VALUE); @@ -28,26 +28,25 @@ SetAlphaOperation::SetAlphaOperation() this->m_inputAlpha = nullptr; } -void SetAlphaOperation::initExecution() +void SetAlphaReplaceOperation::initExecution() { this->m_inputColor = getInputSocketReader(0); this->m_inputAlpha = getInputSocketReader(1); } -void SetAlphaOperation::executePixelSampled(float output[4], - float x, - float y, - PixelSampler sampler) +void SetAlphaReplaceOperation::executePixelSampled(float output[4], + float x, + float y, + PixelSampler sampler) { - float alphaInput[4]; + float alpha_input[4]; this->m_inputColor->readSampled(output, x, y, sampler); - this->m_inputAlpha->readSampled(alphaInput, x, y, sampler); - - output[3] = alphaInput[0]; + this->m_inputAlpha->readSampled(alpha_input, x, y, sampler); + output[3] = alpha_input[0]; } -void SetAlphaOperation::deinitExecution() +void SetAlphaReplaceOperation::deinitExecution() { this->m_inputColor = nullptr; this->m_inputAlpha = nullptr; diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.h b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h index a84fb0f2228..b4cab82855b 100644 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h @@ -24,7 +24,7 @@ * this program converts an input color to an output value. * it assumes we are in sRGB color space. */ -class SetAlphaOperation : public NodeOperation { +class SetAlphaReplaceOperation : public NodeOperation { private: SocketReader *m_inputColor; SocketReader *m_inputAlpha; @@ -33,7 +33,7 @@ class SetAlphaOperation : public NodeOperation { /** * Default constructor */ - SetAlphaOperation(); + SetAlphaReplaceOperation(); /** * the inner loop of this program |