Cleanup and rename OCIO Linear Grading node

This commit is contained in:
Thomas Wilshaw
2022-04-24 21:03:00 +01:00
parent 4d2f8f775c
commit 831fe77275
9 changed files with 169 additions and 191 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
add_subdirectory(colormanager)
add_subdirectory(displaytransform)
add_subdirectory(ociobase)
add_subdirectory(ociogradingtransform)
add_subdirectory(ociogradingtransformlinear)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
@@ -1,157 +0,0 @@
/***
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 "ociogradingtransform.h"
#include "common/ocioutils.h"
#include "node/project/project.h"
#include "render/colorprocessor.h"
namespace olive {
const QString OCIOGradingTransformNode::kTypeInput = QStringLiteral("type_in");
const QString OCIOGradingTransformNode::kBrightnessInput = QStringLiteral("brightness_in");
const QString OCIOGradingTransformNode::kContrastInput = QStringLiteral("contrast_in");
const QString OCIOGradingTransformNode::kGammaInput = QStringLiteral("gamma_in");
const QString OCIOGradingTransformNode::kOffsetInput = QStringLiteral("offset_in");
const QString OCIOGradingTransformNode::kExposureInput = QStringLiteral("exposure_in");
const QString OCIOGradingTransformNode::kLiftInput = QStringLiteral("lift_in");
const QString OCIOGradingTransformNode::kGainInput = QStringLiteral("gain_in");
const QString OCIOGradingTransformNode::kSaturationInput = QStringLiteral("saturation_in");
const QString OCIOGradingTransformNode::kPivotInput = QStringLiteral("pivot_in");
const QString OCIOGradingTransformNode::kPivotBlackInput = QStringLiteral("pivot_black_in");
const QString OCIOGradingTransformNode::kPivotWhiteInput = QStringLiteral("pivot_white_in");
const QString OCIOGradingTransformNode::kClampBlackInput = QStringLiteral("clamp_black_in");
const QString OCIOGradingTransformNode::kClampWhiteInput = QStringLiteral("clamp_white_in");
#define super OCIOBaseNode
OCIOGradingTransformNode::OCIOGradingTransformNode()
{
AddInput(kTypeInput, NodeValue::kCombo, 0);
//AddInput(kBrightnessInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
AddInput(kContrastInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0}, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
SetInputProperty(kContrastInput, QStringLiteral("min"), QVector4D{0.001f, 0.001f, 0.001f, 0.001f});
//AddInput(kGammaInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0});
AddInput(kOffsetInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0}, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kExposureInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0}, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
//AddInput(kLiftInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
//AddInput(kGainInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0});
AddInput(kSaturationInput, NodeValue::kFloat, 1.0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
SetInputProperty(kSaturationInput, QStringLiteral("min"), 0.0);
AddInput(kPivotInput, NodeValue::kFloat, 0.203919098, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
// AddInput(kPivotBlackInput, NodeValue::kFloat, 0.0);
//AddInput(kPivotWhiteInput, NodeValue::kFloat, 1.0);
AddInput(kClampBlackInput, NodeValue::kFloat, 0.0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
AddInput(kClampWhiteInput, NodeValue::kFloat, 200.0, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable));
}
QString OCIOGradingTransformNode::Name() const
{
return tr("OCIO Grading Transform");
}
QString OCIOGradingTransformNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.ociogradingtransform");
}
QVector<Node::CategoryID> OCIOGradingTransformNode::Category() const
{
return {kCategoryColor};
}
QString OCIOGradingTransformNode::Description() const
{
return tr("Simple color grading using OCIO");
}
void OCIOGradingTransformNode::Retranslate()
{
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kTypeInput, tr("Type"));
//SetInputName(kBrightnessInput, tr("Brightness"));
SetInputName(kContrastInput, tr("Contrast"));
//SetInputName(kGammaInput, tr("Gamma"));
SetInputName(kOffsetInput, tr("Offset"));
SetInputName(kExposureInput, tr("Exposure"));
//SetInputName(kLiftInput, tr("Lift"));
//SetInputName(kGainInput, tr("Gain"));
SetInputName(kSaturationInput, tr("Saturation"));
SetInputName(kPivotInput, tr("Pivot"));
//SetInputName(kPivotBlackInput, tr("Black Pivot"));
//SetInputName(kPivotWhiteInput, tr("White Pivot"));
SetInputName(kClampBlackInput, tr("Black Clamp"));
SetInputName(kClampWhiteInput, tr("White Clamp"));
SetComboBoxStrings(kTypeInput, {"Linear"});
}
void OCIOGradingTransformNode::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element);
ConfigChanged();
}
void OCIOGradingTransformNode::ConfigChanged()
{
OCIO::GradingPrimaryTransformRcPtr gp = OCIO::GradingPrimaryTransform::Create(OCIO::GRADING_LIN);
//auto gp = OCIO::GradingPrimaryTransform::Create(OCIO::GRADING_LIN);
gp->setDirection(OCIO::TransformDirection::TRANSFORM_DIR_FORWARD);
//gp->makeDynamic();
OCIO::GradingPrimary gpdata{OCIO::GRADING_LIN};
//gpdata.m_lift = OCIOUtils::QVec4ToRGBM(GetStandardValue(kLiftInput).value<QVector4D>());
gpdata.m_contrast = OCIOUtils::QVec4ToRGBM(GetStandardValue(kContrastInput).value<QVector4D>());
gpdata.m_exposure = OCIOUtils::QVec4ToRGBM(GetStandardValue(kExposureInput).value<QVector4D>());
//gpdata.m_gamma = OCIOUtils::QVec4ToRGBM(GetStandardValue(kGammaInput).value<QVector4D>());
//gpdata.m_gain = OCIOUtils::QVec4ToRGBM(GetStandardValue(kGainInput).value<QVector4D>());
gpdata.m_offset = OCIOUtils::QVec4ToRGBM(GetStandardValue(kOffsetInput).value<QVector4D>());
gpdata.m_saturation = GetStandardValue(kSaturationInput).value<double>();
gpdata.m_pivot = GetStandardValue(kPivotInput).value<double>();
gpdata.m_clampBlack = GetStandardValue(kClampBlackInput).value<double>();
gpdata.m_clampWhite = GetStandardValue(kClampWhiteInput).value<double>();
//gpdata.m_pivotBlack = GetStandardValue(kPivotBlackInput).value<double>();
//gpdata.m_pivotWhite = GetStandardValue(kPivotWhiteInput).value<double>();
try {
gp->setValue(gpdata);
set_processor(ColorProcessor::Create(manager()->GetConfig()->getProcessor(gp)));
} catch (const OCIO::Exception &e) {
std::cerr << std::endl << e.what() << std::endl;
}
}
}
@@ -16,7 +16,7 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/color/ociogradingtransform/ociogradingtransform.cpp
node/color/ociogradingtransform/ociogradingtransform.h
node/color/ociogradingtransformlinear/ociogradingtransformlinear.cpp
node/color/ociogradingtransformlinear/ociogradingtransformlinear.h
PARENT_SCOPE
)
@@ -0,0 +1,125 @@
/***
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 "ociogradingtransformlinear.h"
#include "common/ocioutils.h"
#include "node/project/project.h"
#include "render/colorprocessor.h"
namespace olive {
const QString OCIOGradingTransformLinearNode::kContrastInput = QStringLiteral("contrast_in");
const QString OCIOGradingTransformLinearNode::kOffsetInput = QStringLiteral("offset_in");
const QString OCIOGradingTransformLinearNode::kExposureInput = QStringLiteral("exposure_in");
const QString OCIOGradingTransformLinearNode::kSaturationInput = QStringLiteral("saturation_in");
const QString OCIOGradingTransformLinearNode::kPivotInput = QStringLiteral("pivot_in");
const QString OCIOGradingTransformLinearNode::kClampBlackInput = QStringLiteral("clamp_black_in");
const QString OCIOGradingTransformLinearNode::kClampWhiteInput = QStringLiteral("clamp_white_in");
#define super OCIOBaseNode
OCIOGradingTransformLinearNode::OCIOGradingTransformLinearNode()
{
AddInput(kContrastInput, NodeValue::kVec4, QVector4D{1.0, 1.0, 1.0, 1.0});
SetInputProperty(kContrastInput, QStringLiteral("min"), QVector4D{0.001f, 0.001f, 0.001f, 0.001f});
AddInput(kOffsetInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
AddInput(kExposureInput, NodeValue::kVec4, QVector4D{0.0, 0.0, 0.0, 0.0});
AddInput(kSaturationInput, NodeValue::kFloat, 1.0);
SetInputProperty(kSaturationInput, QStringLiteral("min"), 0.0);
AddInput(kPivotInput, NodeValue::kFloat, 0.203919098);
AddInput(kClampBlackInput, NodeValue::kFloat, 0.0);
AddInput(kClampWhiteInput, NodeValue::kFloat, 200.0);
}
QString OCIOGradingTransformLinearNode::Name() const
{
return tr("OCIO Linear Grading Transform");
}
QString OCIOGradingTransformLinearNode::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.ociogradingtransformlinear");
}
QVector<Node::CategoryID> OCIOGradingTransformLinearNode::Category() const
{
return {kCategoryColor};
}
QString OCIOGradingTransformLinearNode::Description() const
{
return tr("Simple linearcolor grading using OCIO");
}
void OCIOGradingTransformLinearNode::Retranslate()
{
super::Retranslate();
SetInputName(kTextureInput, tr("Input"));
SetInputName(kContrastInput, tr("Contrast"));
SetInputName(kOffsetInput, tr("Offset"));
SetInputName(kExposureInput, tr("Exposure"));
SetInputName(kSaturationInput, tr("Saturation"));
SetInputName(kPivotInput, tr("Pivot"));
SetInputName(kClampBlackInput, tr("Black Clamp"));
SetInputName(kClampWhiteInput, tr("White Clamp"));
}
void OCIOGradingTransformLinearNode::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element);
GenerateProcessor();
}
void OCIOGradingTransformLinearNode::GenerateProcessor()
{
OCIO::GradingPrimaryTransformRcPtr gp = OCIO::GradingPrimaryTransform::Create(OCIO::GRADING_LIN);
gp->setDirection(OCIO::TransformDirection::TRANSFORM_DIR_FORWARD);
OCIO::GradingPrimary gpdata{OCIO::GRADING_LIN};
gpdata.m_contrast = OCIOUtils::QVec4ToRGBM(GetStandardValue(kContrastInput).value<QVector4D>());
gpdata.m_exposure = OCIOUtils::QVec4ToRGBM(GetStandardValue(kExposureInput).value<QVector4D>());
gpdata.m_offset = OCIOUtils::QVec4ToRGBM(GetStandardValue(kOffsetInput).value<QVector4D>());
gpdata.m_saturation = GetStandardValue(kSaturationInput).value<double>();
gpdata.m_pivot = GetStandardValue(kPivotInput).value<double>();
gpdata.m_clampBlack = GetStandardValue(kClampBlackInput).value<double>();
gpdata.m_clampWhite = GetStandardValue(kClampWhiteInput).value<double>();
try {
gp->setValue(gpdata);
set_processor(ColorProcessor::Create(manager()->GetConfig()->getProcessor(gp)));
} catch (const OCIO::Exception &e) {
std::cerr << std::endl << e.what() << std::endl;
}
}
void OCIOGradingTransformLinearNode::ConfigChanged()
{
GenerateProcessor();
}
}
@@ -18,22 +18,22 @@
***/
#ifndef OCIOGRADINGTRANSFORMNODE_H
#define OCIOGRADINGTRANSFORMNODE_H
#ifndef OCIOGRADINGTRANSFORMLINEARNODE_H
#define OCIOGRADINGTRANSFORMLINEARNODE_H
#include "node/color/ociobase/ociobase.h"
#include "render/colorprocessor.h"
namespace olive {
class OCIOGradingTransformNode : public OCIOBaseNode
class OCIOGradingTransformLinearNode : public OCIOBaseNode
{
Q_OBJECT
public:
OCIOGradingTransformNode();
OCIOGradingTransformLinearNode();
NODE_DEFAULT_DESTRUCTOR(OCIOGradingTransformNode)
NODE_COPY_FUNCTION(OCIOGradingTransformNode)
NODE_DEFAULT_DESTRUCTOR(OCIOGradingTransformLinearNode)
NODE_COPY_FUNCTION(OCIOGradingTransformLinearNode)
virtual QString Name() const override;
virtual QString id() const override;
@@ -42,19 +42,13 @@ class OCIOGradingTransformNode : public OCIOBaseNode
virtual void Retranslate() override;
virtual void InputValueChangedEvent(const QString &input, int element) override;
void GenerateProcessor();
static const QString kTypeInput;
static const QString kBrightnessInput;
static const QString kContrastInput;
static const QString kGammaInput;
static const QString kOffsetInput;
static const QString kExposureInput;
static const QString kLiftInput;
static const QString kGainInput;
static const QString kSaturationInput;
static const QString kPivotInput;
static const QString kPivotBlackInput;
static const QString kPivotWhiteInput;
static const QString kClampBlackInput;
static const QString kClampWhiteInput;
+3 -3
View File
@@ -30,7 +30,7 @@
#include "block/transition/crossdissolve/crossdissolvetransition.h"
#include "block/transition/diptocolor/diptocolortransition.h"
#include "color/displaytransform/displaytransform.h"
#include "color/ociogradingtransform/ociogradingtransform.h"
#include "color/ociogradingtransformlinear/ociogradingtransformlinear.h"
#include "distort/cornerpin/cornerpindistortnode.h"
#include "distort/crop/cropdistortnode.h"
#include "distort/flip/flipdistortnode.h"
@@ -282,8 +282,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
return new CornerPinDistortNode();
case kDisplayTransform:
return new DisplayTransformNode();
case kOCIOGradingTransform:
return new OCIOGradingTransformNode();
case kOCIOGradingTransformLinear:
return new OCIOGradingTransformLinearNode();
case kChromaKey:
return new ChromaKeyNode();
+1 -1
View File
@@ -71,7 +71,7 @@ public:
kTimeOffsetNode,
kCornerPinDistort,
kDisplayTransform,
kOCIOGradingTransform,
kOCIOGradingTransformLinear,
kChromaKey,
// Count value
+6 -2
View File
@@ -226,8 +226,12 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
}
ShaderJob job;
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source)));
if (shader_path.isEmpty()) {
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source)));
} else {
// If we are using a custom shader in a node use "tex_in" for consistency
job.InsertValue(QStringLiteral("tex_in"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source)));
}
job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, matrix));
job.InsertValue(QStringLiteral("ove_cropmatrix"), NodeValue(NodeValue::kMatrix, crop_matrix.inverted()));
job.InsertValue(QStringLiteral("ove_maintex_alpha"), NodeValue(NodeValue::kInt, source_alpha_association));
+24 -12
View File
@@ -1,8 +1,12 @@
// Main texture input
uniform sampler2D tex_in;
// Main texture coordinate
in vec2 ove_texcoord;
out vec4 frag_color;
// OCIO shader code
// Program will replace this with OCIO's auto-generated shader code
%1
// Assume D65 white point
@@ -19,16 +23,24 @@ float func(float t) {
}
}
void main() {
vec4 col = texture2D(tex_in, ove_texcoord);
vec4 new_col;
new_col = %2(col);
vec4 CIExyz_to_Lab(vec4 CIE) {
vec4 lab;
lab.r = 116.0 * func(col.g / Yn) - 16.0;
lab.g = 500.0 * (func(col.r / Xn) - func(col.g / Yn));
lab.b = 200.0 * (func(col.g / Yn) - func(col.b / Zn));
lab.w = 1.0;
frag_color = col;
lab.r = 116.0 * func(CIE.g / Yn) - 16.0;
lab.g = 500.0 * (func(CIE.r / Xn) - func(CIE.g / Yn));
lab.b = 200.0 * (func(CIE.g / Yn) - func(CIE.b / Zn));
lab.w = CIE.w;
return lab;
}
void main() {
vec4 col = texture(tex_in, ove_texcoord);
// Perform color conversion
vec4 cie_xyz = %2(col);
vec4 lab = CIExyz_to_Lab(cie_xyz);
frag_color = vec4(lab.r);
}