Add Flip/Flop node (#1850)

* Add Flip/Flop node

* Rename node Flip

* Missed files

Co-authored-by: itsmattkc <34096995+itsmattkc@users.noreply.github.com>
This commit is contained in:
ThomasWilshaw
2022-01-25 15:14:54 -08:00
committed by GitHub
co-authored by itsmattkc
parent 314167be40
commit 953adf856b
7 changed files with 197 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(crop)
add_subdirectory(flip)
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/flip/flipdistortnode.cpp
node/distort/flip/flipdistortnode.h
PARENT_SCOPE
)
+95
View File
@@ -0,0 +1,95 @@
/***
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 "flipdistortnode.h"
namespace olive {
const QString FlipDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString FlipDistortNode::kHorizontalInput = QStringLiteral("horiz_in");
const QString FlipDistortNode::kVerticalInput = QStringLiteral("vert_in");
FlipDistortNode::FlipDistortNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kHorizontalInput, NodeValue::kBoolean, false);
AddInput(kVerticalInput, NodeValue::kBoolean, false);
}
Node* FlipDistortNode::copy() const
{
return new FlipDistortNode();
}
QString FlipDistortNode::Name() const
{
return tr("Flip");
}
QString FlipDistortNode::id() const
{
return QStringLiteral("org.oliveeditor.Olive.flip");
}
QVector<Node::CategoryID> FlipDistortNode::Category() const
{
return {kCategoryDistort};
}
QString FlipDistortNode::Description() const
{
return tr("Flips an image horizontally or vertically");
}
void FlipDistortNode::Retranslate()
{
SetInputName(kTextureInput, tr("Input"));
SetInputName(kHorizontalInput, tr("Horizontal"));
SetInputName(kVerticalInput, tr("Vertical"));
}
ShaderCode FlipDistortNode::GetShaderCode(const QString& shader_id) const
{
Q_UNUSED(shader_id)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/flip.frag"));
}
void FlipDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
{
ShaderJob job;
job.InsertValue(value);
// If there's no texture, no need to run an operation
if (!job.GetValue(kTextureInput).data().isNull()) {
// Only run shader if at least one of flip or flop are selected
if (job.GetValue(kHorizontalInput).data().toBool() || job.GetValue(kVerticalInput).data().toBool()) {
table->Push(NodeValue::kShaderJob, QVariant::fromValue(job), this);
} else {
// If we're not flipping or flopping just push the texture
table->Push(job.GetValue(kTextureInput));
}
}
}
}
+56
View File
@@ -0,0 +1,56 @@
/***
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 FLIPDISTORTNODE_H
#define FLIPDISTORTNODE_H
#include "node/node.h"
namespace olive {
class FlipDistortNode : public Node
{
Q_OBJECT
public:
FlipDistortNode();
NODE_DEFAULT_DESTRUCTOR(FlipDistortNode)
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual ShaderCode GetShaderCode(const QString &shader_id) const override;
virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override;
static const QString kTextureInput;
static const QString kHorizontalInput;
static const QString kVerticalInput;
};
}
#endif // FLIPDISTORTNODE_H
+3
View File
@@ -30,6 +30,7 @@
#include "block/transition/crossdissolve/crossdissolvetransition.h"
#include "block/transition/diptocolor/diptocolortransition.h"
#include "distort/crop/cropdistortnode.h"
#include "distort/flip/flipdistortnode.h"
#include "distort/transform/transformdistortnode.h"
#include "effect/opacity/opacityeffect.h"
#include "generator/matrix/matrix.h"
@@ -256,6 +257,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
return new NodeGroup();
case kOpacityEffect:
return new OpacityEffect();
case kFlipDistort:
return new FlipDistortNode();
case kNoiseGenerator:
return new NoiseGeneratorNode();
+1
View File
@@ -63,6 +63,7 @@ public:
kShapeGenerator,
kGroupNode,
kOpacityEffect,
kFlipDistort,
kNoiseGenerator,
// Count value
+19
View File
@@ -0,0 +1,19 @@
uniform sampler2D tex_in;
uniform bool horiz_in;
uniform bool vert_in;
varying vec2 ove_texcoord;
void main(void) {
if (!horiz_in && !vert_in) {
gl_FragColor = texture2D(tex_in, ove_texcoord);
return;
}
vec2 new_coord = ove_texcoord;
if (horiz_in) new_coord.x = 1.0 - new_coord.x;
if (vert_in) new_coord.y = 1.0 - new_coord.y;
gl_FragColor = texture2D(tex_in, new_coord);
}