diff options
author | Sergey Sharybin <sergey@blender.org> | 2020-10-22 12:13:34 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2020-10-22 12:57:01 +0300 |
commit | f68c3d557aa847743b09d8b837278ea785ec40f6 (patch) | |
tree | 225ce03a4eef0a3a74c5e418a202c32a8d26b17d /source/blender/compositor/operations | |
parent | 6c178bf439d5701b4bbedd6cf1f656b9cccc7177 (diff) |
Compositor: Ensure keying node result is pre-multiplied
Historically the result of the keying node was violating alpha
pre-multiplication rules in Blender: it was simply overriding
the alpha channel of input.
This change makes it so keying node mixes alpha into the input,
which solves the following issues:
- The result is properly pre-multiplied, no need in separate
alpha-convert node anymore.
- Allows to more easily stack keying nodes.
This usecase was never really investigated, but since previously
alpha is always overwritten it was never possible to easily stack
nodes. Now it is at something to be tried.
Unfortunately, this breaks compatibility with existing files, where
alpha-convert node is to be manually removed.
From implementation side this is done as a dedicated operation since
there was no ready-to-use operation. Maybe in the future it might
be replaced with some sort of vector math node.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D9211
Diffstat (limited to 'source/blender/compositor/operations')
-rw-r--r-- | source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp | 55 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h | 39 |
2 files changed, 94 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp new file mode 100644 index 00000000000..dff88d49e80 --- /dev/null +++ b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp @@ -0,0 +1,55 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * 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. + */ + +#include "COM_KeyingSetAlphaOperation.h" + +KeyingSetAlphaOperation::KeyingSetAlphaOperation() : NodeOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_COLOR); + + this->m_inputColor = NULL; + this->m_inputAlpha = NULL; +} + +void KeyingSetAlphaOperation::initExecution() +{ + this->m_inputColor = getInputSocketReader(0); + this->m_inputAlpha = getInputSocketReader(1); +} + +void KeyingSetAlphaOperation::executePixelSampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + float color_input[4]; + float alpha_input[4]; + + this->m_inputColor->readSampled(color_input, x, y, sampler); + this->m_inputAlpha->readSampled(alpha_input, x, y, sampler); + + mul_v4_v4fl(output, color_input, alpha_input[0]); +} + +void KeyingSetAlphaOperation::deinitExecution() +{ + this->m_inputColor = NULL; + this->m_inputAlpha = NULL; +} diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h new file mode 100644 index 00000000000..b786240f215 --- /dev/null +++ b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h @@ -0,0 +1,39 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * 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. + */ + +#pragma once + +#include "COM_NodeOperation.h" + +/** + * Operation which is used by keying node to modify image's alpha channels. + * It keeps color properly pre-multiplied. + */ +class KeyingSetAlphaOperation : public NodeOperation { + private: + SocketReader *m_inputColor; + SocketReader *m_inputAlpha; + + public: + KeyingSetAlphaOperation(); + + void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); + + void initExecution(); + void deinitExecution(); +}; |