First attempt at adding OCIO to nodes

This commit is contained in:
Thomas Wilshaw
2022-02-01 16:12:08 +00:00
parent efa74c72a8
commit ff2eac55a5
12 changed files with 429 additions and 64 deletions
+2
View File
@@ -15,6 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(colormanager)
add_subdirectory(displaytransform)
add_subdirectory(ociobase)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
@@ -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/color/displaytransform/displaytransform.cpp
node/color/displaytransform/displaytransform.h
PARENT_SCOPE
)
@@ -0,0 +1,108 @@
/***
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 "displaytransform.h"
#include "node/project/project.h"
#include "render/colorprocessor.h"
namespace olive {
const QString DisplayTransformNode::kTextureInput = QStringLiteral("tex_in");
const QString DisplayTransformNode::kDirectionInput = QStringLiteral("dir_in");
DisplayTransformNode::DisplayTransformNode()
{
AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
AddInput(kDirectionInput, NodeValue::kCombo, 0);
GenerateProcessor(true);
}
void DisplayTransformNode::GenerateProcessor(bool direction)
{
if (!project()) {
return;
}
reference_to_display_ = ColorProcessor::Create(project()->color_manager(), project()->color_manager()->GetReferenceColorSpace(),
project()->color_manager()->GetDefaultDisplay());
// Create shader description
shader_desc_ = OCIO::GpuShaderDesc::CreateShaderDesc();
shader_desc_->setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_3);
shader_desc_->setFunctionName("DisplayTransform");
shader_desc_->setResourcePrefix("ocio_");
// Generate shader
reference_to_display_->GetProcessor()->getDefaultGPUProcessor()->extractGpuShaderInfo(shader_desc_);
}
Node *DisplayTransformNode::copy() const
{
return new DisplayTransformNode();
}
QString DisplayTransformNode::Name() const
{
return tr("Display Transform");
}
QString DisplayTransformNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.disaplaytransform");
}
QVector<Node::CategoryID> DisplayTransformNode::Category() const
{
return {kCategoryColor};
}
QString DisplayTransformNode::Description() const
{
return tr("Converts an image to/from display space");
}
void DisplayTransformNode::Retranslate()
{
SetInputName(kTextureInput, tr("Input"));
SetInputName(kDirectionInput, tr("Direction"));
SetComboBoxStrings(kDirectionInput, {tr("Forward"), tr("Inverse")});
GenerateProcessor(true);
}
ShaderCode DisplayTransformNode::GetShaderCode(const QString &shader_id) const
{
Q_UNUSED(shader_id)
// Generate shader code using OCIO stub and our auto-generated name
QString shader_frag = FileFunctions::ReadFileAsString(QStringLiteral(":shaders/displaytransform.frag"))
.arg(shader_desc_->getShaderText());
return ShaderCode(shader_frag);
}
void DisplayTransformNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
{
ShaderJob job;
job.InsertValue(value);
renderer()->ShaderJobInsertTextures(reference_to_display_, &job, shader_desc_);
// If there's no texture, no need to run an operation
if (!job.GetValue(kTextureInput).data().isNull()) {
table->Push(NodeValue::kShaderJob, QVariant::fromValue(job), this);
}
}
}
@@ -0,0 +1,54 @@
/***
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 DISPLAYTRANSFORMNODE_H
#define DISPLAYTRANSFORMNODE_H
#include "node/color/ociobase/ociobase.h"
namespace olive {
class DisplayTransformNode : public OCIONodeBase {
Q_OBJECT
public:
DisplayTransformNode();
NODE_DEFAULT_DESTRUCTOR(DisplayTransformNode)
void GenerateProcessor(bool direction);
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 kDirectionInput;
const QString shader_text_;
ColorProcessorPtr reference_to_display_;
OCIO::GpuShaderDescRcPtr shader_desc_;
};
} // olive
#endif
+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/color/ociobase/ociobase.cpp
node/color/ociobase/ociobase.h
PARENT_SCOPE
)
+35
View File
@@ -0,0 +1,35 @@
/***
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 "ociobase.h"
#include "render/opengl/openglrenderer.h"
namespace olive {
OCIONodeBase::OCIONodeBase()
{
if (true){//RenderManager::instance()->backend() == RenderManager::kOpenGL) {
// Create OpenGL renderer
attached_renderer_ = new OpenGLRenderer(this);
}
}
}
+51
View File
@@ -0,0 +1,51 @@
/***
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 OCIOBASE_H
#define OCIOBASE_H
#include "node/node.h"
#include "render/rendermanager.h"
namespace olive {
class OCIONodeBase : public Node
{
public:
OCIONodeBase();
NODE_DEFAULT_DESTRUCTOR(OCIONodeBase);
protected:
Renderer* renderer() const
{
return attached_renderer_;
}
/**
* @brief Renderer abstraction
*/
Renderer* attached_renderer_;
};
} // olive
#endif // OCIOBASE_H
+3
View File
@@ -29,6 +29,7 @@
#include "block/subtitle/subtitle.h"
#include "block/transition/crossdissolve/crossdissolvetransition.h"
#include "block/transition/diptocolor/diptocolortransition.h"
#include "color/displaytransform/displaytransform.h"
#include "distort/crop/cropdistortnode.h"
#include "distort/flip/flipdistortnode.h"
#include "distort/transform/transformdistortnode.h"
@@ -261,6 +262,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
return new FlipDistortNode();
case kNoiseGenerator:
return new NoiseGeneratorNode();
case kDisplayTransform:
return new DisplayTransformNode();
case kInternalNodeCount:
break;
+1
View File
@@ -65,6 +65,7 @@ public:
kOpacityEffect,
kFlipDistort,
kNoiseGenerator,
kDisplayTransform,
// Count value
kInternalNodeCount