nodes: implemented mask node

This commit is contained in:
itsmattkc
2022-05-08 16:56:31 -07:00
parent f910117a58
commit 93e5351d33
10 changed files with 177 additions and 6 deletions
+1
View File
@@ -17,6 +17,7 @@
add_subdirectory(cornerpin)
add_subdirectory(crop)
add_subdirectory(flip)
add_subdirectory(mask)
add_subdirectory(transform)
set(OLIVE_SOURCES
+22
View File
@@ -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 <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/distort/mask/mask.cpp
node/distort/mask/mask.h
PARENT_SCOPE
)
+62
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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);
}
}
}
+66
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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<CategoryID> 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
@@ -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");
+3
View File
@@ -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;
+1
View File
@@ -73,6 +73,7 @@ public:
kDisplayTransform,
kOCIOGradingTransformLinear,
kChromaKey,
kMaskDistort,
// Count value
kInternalNodeCount
+8 -1
View File
@@ -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);
}
+3
View File
@@ -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;
+11
View File
@@ -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);
}