diff --git a/app/node/distort/CMakeLists.txt b/app/node/distort/CMakeLists.txt
index 375232ccc..de3480361 100644
--- a/app/node/distort/CMakeLists.txt
+++ b/app/node/distort/CMakeLists.txt
@@ -17,6 +17,7 @@
add_subdirectory(cornerpin)
add_subdirectory(crop)
add_subdirectory(flip)
+add_subdirectory(mask)
add_subdirectory(transform)
set(OLIVE_SOURCES
diff --git a/app/node/distort/mask/CMakeLists.txt b/app/node/distort/mask/CMakeLists.txt
new file mode 100644
index 000000000..67ff95dee
--- /dev/null
+++ b/app/node/distort/mask/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Olive - Non-Linear Video Editor
+# Copyright (C) 2021 Olive Team
+#
+# 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 3 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, see .
+
+set(OLIVE_SOURCES
+ ${OLIVE_SOURCES}
+ node/distort/mask/mask.cpp
+ node/distort/mask/mask.h
+ PARENT_SCOPE
+)
diff --git a/app/node/distort/mask/mask.cpp b/app/node/distort/mask/mask.cpp
new file mode 100644
index 000000000..df0a41cef
--- /dev/null
+++ b/app/node/distort/mask/mask.cpp
@@ -0,0 +1,62 @@
+/***
+
+ Olive - Non-Linear Video Editor
+ Copyright (C) 2021 Olive Team
+
+ 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 3 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, see .
+
+***/
+
+#include "mask.h"
+
+namespace olive {
+
+#define super PolygonGenerator
+
+MaskDistortNode::MaskDistortNode()
+{
+ // Mask should always be (1.0, 1.0, 1.0) for multiply to work correctly
+ SetInputFlags(kColorInput, InputFlags(GetInputFlags(kColorInput) | kInputFlagHidden));
+}
+
+ShaderCode MaskDistortNode::GetShaderCode(const ShaderRequest &request) const
+{
+ Q_UNUSED(request)
+ return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/multiply.frag")));
+}
+
+void MaskDistortNode::Retranslate()
+{
+ super::Retranslate();
+
+ SetInputName(kBaseInput, tr("Texture"));
+}
+
+void MaskDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
+{
+ GenerateJob job = GetGenerateJob(value);
+
+ if (!value[kBaseInput].data().isNull()) {
+ // Push as merge node
+ ShaderJob merge;
+
+ merge.SetShaderID(QStringLiteral("mrg"));
+ merge.InsertValue(QStringLiteral("tex_a"), value[kBaseInput]);
+ merge.InsertValue(QStringLiteral("tex_b"), NodeValue(NodeValue::kTexture, QVariant::fromValue(job), this));
+
+ table->Push(NodeValue::kTexture, QVariant::fromValue(merge), this);
+ }
+}
+
+}
diff --git a/app/node/distort/mask/mask.h b/app/node/distort/mask/mask.h
new file mode 100644
index 000000000..d4794ac99
--- /dev/null
+++ b/app/node/distort/mask/mask.h
@@ -0,0 +1,66 @@
+/***
+
+ Olive - Non-Linear Video Editor
+ Copyright (C) 2021 Olive Team
+
+ 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 3 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, see .
+
+***/
+
+#ifndef MASKDISTORTNODE_H
+#define MASKDISTORTNODE_H
+
+#include "node/generator/polygon/polygon.h"
+
+namespace olive {
+
+class MaskDistortNode : public PolygonGenerator
+{
+ Q_OBJECT
+public:
+ MaskDistortNode();
+
+ NODE_DEFAULT_FUNCTIONS(MaskDistortNode)
+
+ virtual QString Name() const override
+ {
+ return tr("Mask");
+ }
+
+ virtual QString id() const override
+ {
+ return QStringLiteral("org.olivevideoeditor.Olive.mask");
+ }
+
+ virtual QVector Category() const override
+ {
+ return {kCategoryDistort};
+ }
+
+ virtual QString Description() const override
+ {
+ return tr("Apply a polygonal mask.");
+ }
+
+ virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
+
+ virtual void Retranslate() override;
+
+ virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
+
+};
+
+}
+
+#endif // MASKDISTORTNODE_H
diff --git a/app/node/distort/transform/transformdistortnode.h b/app/node/distort/transform/transformdistortnode.h
index 9738c7e68..e2ae7eb93 100644
--- a/app/node/distort/transform/transformdistortnode.h
+++ b/app/node/distort/transform/transformdistortnode.h
@@ -41,11 +41,6 @@ public:
return tr("Transform");
}
- virtual QString ShortName() const override
- {
- return Node::ShortName();
- }
-
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.transform");
diff --git a/app/node/factory.cpp b/app/node/factory.cpp
index 4292d5037..042ee3175 100644
--- a/app/node/factory.cpp
+++ b/app/node/factory.cpp
@@ -34,6 +34,7 @@
#include "distort/cornerpin/cornerpindistortnode.h"
#include "distort/crop/cropdistortnode.h"
#include "distort/flip/flipdistortnode.h"
+#include "distort/mask/mask.h"
#include "distort/transform/transformdistortnode.h"
#include "effect/opacity/opacityeffect.h"
#include "generator/matrix/matrix.h"
@@ -290,6 +291,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
return new OCIOGradingTransformLinearNode();
case kChromaKey:
return new ChromaKeyNode();
+ case kMaskDistort:
+ return new MaskDistortNode();
case kInternalNodeCount:
break;
diff --git a/app/node/factory.h b/app/node/factory.h
index 54e417b3e..f9531b1e7 100644
--- a/app/node/factory.h
+++ b/app/node/factory.h
@@ -73,6 +73,7 @@ public:
kDisplayTransform,
kOCIOGradingTransformLinear,
kChromaKey,
+ kMaskDistort,
// Count value
kInternalNodeCount
diff --git a/app/node/generator/polygon/polygon.cpp b/app/node/generator/polygon/polygon.cpp
index cb294b9ed..65c1c8f58 100644
--- a/app/node/generator/polygon/polygon.cpp
+++ b/app/node/generator/polygon/polygon.cpp
@@ -89,7 +89,7 @@ void PolygonGenerator::Retranslate()
SetInputName(kColorInput, tr("Color"));
}
-void PolygonGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
+GenerateJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value) const
{
GenerateJob job;
@@ -97,6 +97,13 @@ void PolygonGenerator::Value(const NodeValueRow &value, const NodeGlobals &globa
job.SetRequestedFormat(VideoParams::kFormatFloat32);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
+ return job;
+}
+
+void PolygonGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
+{
+ GenerateJob job = GetGenerateJob(value);
+
PushMergableJob(value, QVariant::fromValue(job), table);
}
diff --git a/app/node/generator/polygon/polygon.h b/app/node/generator/polygon/polygon.h
index 0b2d98457..7107818df 100644
--- a/app/node/generator/polygon/polygon.h
+++ b/app/node/generator/polygon/polygon.h
@@ -57,6 +57,9 @@ public:
static const QString kPointsInput;
static const QString kColorInput;
+protected:
+ GenerateJob GetGenerateJob(const NodeValueRow &value) const;
+
protected slots:
virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers) override;
diff --git a/app/shaders/multiply.frag b/app/shaders/multiply.frag
new file mode 100644
index 000000000..901a310c3
--- /dev/null
+++ b/app/shaders/multiply.frag
@@ -0,0 +1,11 @@
+// Input texture
+uniform sampler2D tex_a;
+uniform sampler2D tex_b;
+
+// Input texture coordinate
+in vec2 ove_texcoord;
+out vec4 frag_color;
+
+void main() {
+ frag_color = texture(tex_a, ove_texcoord) * texture(tex_b, ove_texcoord);
+}