Add ability to add custom shaders to ColorProcessorJobs

This commit is contained in:
Thomas Wilshaw
2022-04-24 18:50:06 +01:00
parent 1a2cd9ac3e
commit 4d2f8f775c
11 changed files with 232 additions and 11 deletions
+7
View File
@@ -21,6 +21,8 @@
#ifndef COLORTRANSFORMJOB_H
#define COLORTRANSFORMJOB_H
#include <QString>
#include "render/colorprocessor.h"
#include "render/texture.h"
@@ -40,11 +42,16 @@ public:
ColorProcessorPtr GetColorProcessor() const { return processor_; }
void SetColorProcessor(ColorProcessorPtr p) { processor_ = p; }
QString GetShaderPath() const { return shader_path_; }
void SetShaderPath(const QString shader_path) { shader_path_ = shader_path; }
private:
ColorProcessorPtr processor_;
TexturePtr input_texture_;
QString shader_path_;
};
}
+18 -8
View File
@@ -57,6 +57,11 @@ void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr so
BlitColorManagedInternal(color_processor, source, source_alpha_association, destination, destination->params(), clear_destination, matrix, crop_matrix);
}
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, Texture* destination, QString shader_path, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4 &crop_matrix)
{
BlitColorManagedInternal(color_processor, source, source_alpha_association, destination, destination->params(), clear_destination, matrix, crop_matrix, shader_path);
}
void Renderer::BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, VideoParams params, bool clear_destination, const QMatrix4x4& matrix, const QMatrix4x4 &crop_matrix)
{
BlitColorManagedInternal(color_processor, source, source_alpha_association, nullptr, params, clear_destination, matrix, crop_matrix);
@@ -103,7 +108,7 @@ TexturePtr Renderer::CreateTextureFromNativeHandle(const QVariant &v, const Vide
return std::make_shared<Texture>(this, v, params, type);
}
bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::ColorContext *ctx)
bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::ColorContext *ctx, QString shader_path)
{
QMutexLocker locker(&color_cache_mutex_);
@@ -123,11 +128,16 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
// Generate shader
color_processor->GetProcessor()->getDefaultGPUProcessor()->extractGpuShaderInfo(shader_desc);
// Generate shader code using OCIO stub and our auto-generated name
QString shader_frag = FileFunctions::ReadFileAsString(QStringLiteral(":shaders/colormanage.frag")).arg(
shader_desc->getShaderText(),
ocio_func_name
);
QString shader_frag;
if (shader_path.isEmpty()) {
// Generate shader code using OCIO stub and our auto-generated name
shader_frag = FileFunctions::ReadFileAsString(QStringLiteral(":shaders/colormanage.frag"))
.arg(shader_desc->getShaderText(), ocio_func_name);
} else {
// FIXME: Currently only supports a single function
shader_frag = FileFunctions::ReadFileAsString(shader_path)
.arg(shader_desc->getShaderText(), ocio_func_name);
}
// Try to compile shader
color_ctx.compiled_shader = CreateNativeShader(ShaderCode(shader_frag,
@@ -208,10 +218,10 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source,
AlphaAssociated source_alpha_association, Texture *destination,
VideoParams params, bool clear_destination, const QMatrix4x4& matrix,
const QMatrix4x4& crop_matrix)
const QMatrix4x4& crop_matrix, const QString shader_path)
{
ColorContext color_ctx;
if (!GetColorContext(color_processor, &color_ctx)) {
if (!GetColorContext(color_processor, &color_ctx, shader_path)) {
return;
}
+3 -2
View File
@@ -70,6 +70,7 @@ public:
};
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, Texture* destination, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4());
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, Texture* destination, QString shader_path, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4());
void BlitColorManaged(ColorProcessorPtr color_processor, TexturePtr source, AlphaAssociated source_alpha_association, VideoParams params, bool clear_destination = true, const QMatrix4x4& matrix = QMatrix4x4(), const QMatrix4x4 &crop_matrix = QMatrix4x4());
TexturePtr InterlaceTexture(TexturePtr top, TexturePtr bottom, const VideoParams &params);
@@ -126,12 +127,12 @@ private:
};
bool GetColorContext(ColorProcessorPtr color_processor, ColorContext* ctx);
bool GetColorContext(ColorProcessorPtr color_processor, ColorContext* ctx, const QString shader_path);
void BlitColorManagedInternal(ColorProcessorPtr color_processor, TexturePtr source,
AlphaAssociated source_alpha_association,
Texture* destination, VideoParams params, bool clear_destination,
const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix);
const QMatrix4x4 &matrix, const QMatrix4x4 &crop_matrix, const QString shader_path = QString());
QHash<QString, ColorContext> color_cache_;
+1 -1
View File
@@ -571,7 +571,7 @@ TexturePtr RenderProcessor::ProcessColorTransform(const Node *node, const ColorT
TexturePtr src = job.GetInputTexture();
TexturePtr dest = render_ctx_->CreateTexture(src->params());
render_ctx_->BlitColorManaged(job.GetColorProcessor(), src, Renderer::kAlphaAssociated, dest.get());
render_ctx_->BlitColorManaged(job.GetColorProcessor(), src, Renderer::kAlphaAssociated, dest.get(), job.GetShaderPath());
return dest;
}