nodes: added distort nodes
Adds nodes for cropping and transforming
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <QVector2D>
|
||||
|
||||
#include "common/tohex.h"
|
||||
#include "node/distort/transform/transformdistortnode.h"
|
||||
#include "render/color.h"
|
||||
|
||||
namespace olive {
|
||||
@@ -48,7 +49,17 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInp
|
||||
// No-op frag shader (can we return QString() instead?)
|
||||
operation = QStringLiteral("texture(%1, ove_texcoord)").arg(tex_in->id());
|
||||
|
||||
vert = FileFunctions::ReadFileAsString(":/shaders/matrix.vert").arg(mat_in->id(), tex_in->id());
|
||||
vert = QStringLiteral("uniform mat4 %1;\n"
|
||||
"\n"
|
||||
"in vec4 a_position;\n"
|
||||
"in vec2 a_texcoord;\n"
|
||||
"\n"
|
||||
"out vec2 ove_texcoord;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = %1 * a_position;\n"
|
||||
" ove_texcoord = a_texcoord;\n"
|
||||
"}\n").arg(mat_in->id());
|
||||
|
||||
} else {
|
||||
switch (op) {
|
||||
@@ -287,22 +298,32 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
bool operation_is_noop = false;
|
||||
|
||||
const NodeValue& number_val = val_a.type() == NodeParam::kTexture ? val_b : val_a;
|
||||
const NodeValue& texture_val = val_a.type() == NodeParam::kTexture ? val_a : val_b;
|
||||
TexturePtr texture = texture_val.data().value<TexturePtr>();
|
||||
|
||||
if (pairing == kPairTextureNumber) {
|
||||
if (!texture) {
|
||||
operation_is_noop = true;
|
||||
} else if (pairing == kPairTextureNumber) {
|
||||
if (NumberIsNoOp(operation, RetrieveNumber(number_val))) {
|
||||
operation_is_noop = true;
|
||||
}
|
||||
} else if (pairing == kPairTextureMatrix) {
|
||||
// Only allow matrix multiplication
|
||||
bool matrix_is_identity = false;
|
||||
QVector2D sequence_res = value[QStringLiteral("global")].Get(NodeParam::kVec2, QStringLiteral("resolution")).value<QVector2D>();
|
||||
QVector2D texture_res(texture->params().width() * texture->pixel_aspect_ratio().toDouble(), texture->params().height());
|
||||
|
||||
// FIXME: The matrix in the shader is transformed around footage+sequence resolution so we
|
||||
// need to do that here to determine if the matrix is truly identity. But to do that,
|
||||
// we need access to the texture parameters which is currently not possible.
|
||||
QMatrix4x4 adjusted_matrix = TransformDistortNode::AdjustMatrixByResolutions(number_val.data().value<QMatrix4x4>(),
|
||||
sequence_res,
|
||||
texture_res,
|
||||
false);
|
||||
|
||||
if (operation != kOpMultiply || matrix_is_identity) {
|
||||
if (operation != kOpMultiply || adjusted_matrix.isIdentity()) {
|
||||
operation_is_noop = true;
|
||||
} else {
|
||||
// Replace with adjusted matrix
|
||||
job.InsertValue(val_a.type() == NodeParam::kTexture ? param_b_in : param_a_in,
|
||||
ShaderValue(adjusted_matrix, NodeParam::kMatrix));
|
||||
|
||||
// It's likely an alpha channel will result from this operation
|
||||
job.SetAlphaChannelRequired(true);
|
||||
}
|
||||
@@ -310,7 +331,7 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
|
||||
if (operation_is_noop) {
|
||||
// Just push texture as-is
|
||||
output.Push(val_a.type() == NodeParam::kTexture ? val_a : val_b);
|
||||
output.Push(texture_val);
|
||||
} else {
|
||||
// Push shader job
|
||||
output.Push(NodeParam::kShaderJob, QVariant::fromValue(job), this);
|
||||
|
||||
Reference in New Issue
Block a user