filled out alpha over and opacity nodes

This commit is contained in:
itsmattkc
2019-08-31 14:45:13 +10:00
parent f6db7b6893
commit a4369c4d79
13 changed files with 355 additions and 4 deletions
+3
View File
@@ -220,6 +220,7 @@ void Core::CreateNewFolder()
// FIXME: Test code
#include "node/blend/alphaover/alphaover.h"
#include "node/color/opacity/opacity.h"
#include "node/output/timeline/timeline.h"
#include "node/output/track/track.h"
#include "node/output/viewer/viewer.h"
@@ -309,6 +310,8 @@ void Core::CreateNewSequence()
// FIXME: Test code
AlphaOverBlend* blend = new AlphaOverBlend();
new_sequence->AddNode(blend);
OpacityNode* opac = new OpacityNode();
new_sequence->AddNode(opac);
// End test code
vo->AttachViewer(olive::panel_focus_manager->MostRecentlyFocused<ViewerPanel>());
+1
View File
@@ -16,6 +16,7 @@
add_subdirectory(blend)
add_subdirectory(block)
add_subdirectory(color)
add_subdirectory(generator)
add_subdirectory(input)
add_subdirectory(output)
+71 -3
View File
@@ -1,8 +1,32 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "alphaover.h"
#include "node/processor/renderer/renderer.h"
#include "render/gl/functions.h"
#include "render/rendertexture.h"
#include "render/gl/shadergenerators.h"
AlphaOverBlend::AlphaOverBlend()
AlphaOverBlend::AlphaOverBlend() :
shader_(nullptr)
{
}
@@ -22,10 +46,54 @@ QString AlphaOverBlend::Description()
return tr("A blending node that composites one texture over another using its alpha channel.");
}
void AlphaOverBlend::Release()
{
shader_ = nullptr;
}
QVariant AlphaOverBlend::Value(NodeOutput *param, const rational &time)
{
Q_UNUSED(param)
Q_UNUSED(time)
// Find the current Renderer instance
RenderInstance* renderer = RendererProcessor::CurrentInstance();
// If nothing is available, don't return a texture
if (renderer == nullptr) {
return 0;
}
// The only parameter should be texture output, but for future proofing we put this here
if (param == texture_output()) {
RenderTexturePtr base = base_input()->get_value(time).value<RenderTexturePtr>();
RenderTexturePtr blend = blend_input()->get_value(time).value<RenderTexturePtr>();
// Set compositing strategy to alpha over
renderer->context()->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Attach framebuffer to the backbuffer of base
renderer->buffer()->Attach(base);
renderer->buffer()->Bind();
// Bind blend
blend->Bind();
// Get default pipeline shader
// FIXME: Come up with a good way to share pipeline shaders since a lot of nodes will just use the default
if (shader_ == nullptr) {
shader_ = olive::ShaderGenerator::DefaultPipeline();
}
// Draw blend on base
olive::gl::Blit(shader_);
// Release all
blend->Release();
renderer->buffer()->Detach();
renderer->buffer()->Release();
// Return base texture which now has blend composited on top
// NOTE: Blend texture will be implicitly deleted here (if it's not used anywhere else)
return QVariant::fromValue(base);
}
return 0;
}
+26
View File
@@ -1,7 +1,28 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 ALPHAOVER_H
#define ALPHAOVER_H
#include "node/blend/blend.h"
#include "render/gl/shaderptr.h"
class AlphaOverBlend : public BlendNode
{
@@ -12,8 +33,13 @@ public:
virtual QString id() override;
virtual QString Description() override;
virtual void Release() override;
protected:
virtual QVariant Value(NodeOutput* param, const rational& time) override;
private:
ShaderPtr shader_;
};
#endif // ALPHAOVER_H
+20
View File
@@ -1,3 +1,23 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "blend.h"
BlendNode::BlendNode()
+20
View File
@@ -1,3 +1,23 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 BLEND_H
#define BLEND_H
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 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/>.
add_subdirectory(opacity)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
PARENT_SCOPE
)
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 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/opacity/opacity.h
node/color/opacity/opacity.cpp
PARENT_SCOPE
)
+98
View File
@@ -0,0 +1,98 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "opacity.h"
#include "node/processor/renderer/renderer.h"
#include "render/gl/functions.h"
#include "render/rendertexture.h"
OpacityNode::OpacityNode()
{
opacity_input_ = new NodeInput("opacity_in");
opacity_input_->add_data_input(NodeParam::kFloat);
AddParameter(opacity_input_);
texture_input_ = new NodeInput("tex_in");
texture_input_->add_data_input(NodeParam::kTexture);
AddParameter(texture_input_);
texture_output_ = new NodeOutput("tex_out");
texture_output_->set_data_type(NodeParam::kTexture);
AddParameter(texture_output_);
}
QString OpacityNode::Name()
{
return tr("Opacity");
}
QString OpacityNode::Category()
{
return tr("Color");
}
QString OpacityNode::Description()
{
return tr("Adjust an image's opacity.");
}
QString OpacityNode::id()
{
return "org.olivevideoeditor.Olive.opacity";
}
QVariant OpacityNode::Value(NodeOutput *output, const rational &time)
{
// Find the current Renderer instance
RenderInstance* renderer = RendererProcessor::CurrentInstance();
// If nothing is available, don't return a texture
if (renderer == nullptr) {
return 0;
}
if (output == texture_output_) {
RenderTexturePtr input_tex = texture_input_->get_value(time).value<RenderTexturePtr>();
// Attach texture's back buffer as frame buffer
renderer->buffer()->AttachBackBuffer(input_tex);
renderer->buffer()->Bind();
// Bind texture's front buffer to draw with
input_tex->Bind();
// Set opacity to value
ShaderPtr pipeline = renderer->default_pipeline();
pipeline->setUniformValue("opacity", opacity_input_->get_value(time).toFloat()*0.01f);
// Blit
olive::gl::Blit(renderer->default_pipeline());
// Reset to full opacity
pipeline->setUniformValue("opacity", 1.0f);
input_tex->Release();
renderer->buffer()->Release();
renderer->buffer()->Detach();
}
return 0;
}
+50
View File
@@ -0,0 +1,50 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 OPACITYNODE_H
#define OPACITYNODE_H
#include "node/node.h"
#include "render/gl/shaderptr.h"
class OpacityNode : public Node
{
Q_OBJECT
public:
OpacityNode();
virtual QString Name() override;
virtual QString Category() override;
virtual QString Description() override;
virtual QString id() override;
virtual QVariant Value(NodeOutput *output, const rational &time) override;
private:
NodeInput* opacity_input_;
NodeInput* texture_input_;
NodeOutput* texture_output_;
};
#endif // OPACITYNODE_H
+3 -1
View File
@@ -26,9 +26,9 @@
#include "decoder/ffmpeg/ffmpegdecoder.h"
#include "node/processor/renderer/renderer.h"
#include "project/item/footage/footage.h"
#include "render/pixelservice.h"
#include "render/gl/shadergenerators.h"
#include "render/gl/functions.h"
#include "render/pixelservice.h"
MediaInput::MediaInput() :
decoder_(nullptr),
@@ -220,6 +220,8 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time)
pipeline_ = olive::ShaderGenerator::DefaultPipeline();
}
renderer->context()->functions()->glBlendFunc(GL_ONE, GL_ZERO);
// Draw onto the output texture using the renderer's framebuffer
renderer->buffer()->Attach(output_texture);
renderer->buffer()->Bind();
+14
View File
@@ -22,6 +22,8 @@
#include <QDebug>
#include "render/gl/shadergenerators.h"
RenderInstance::RenderInstance(const int& width,
const int& height,
const olive::PixelFormat& format,
@@ -70,13 +72,20 @@ bool RenderInstance::Start()
buffer_.Create(&ctx_);
// Set viewport to the compositing dimensions
ctx_.functions()->glViewport(0, 0, width_, height_);
// Set up default pipeline
default_pipeline_ = olive::ShaderGenerator::DefaultPipeline();
return true;
}
void RenderInstance::Stop()
{
// Destroy pipeline
default_pipeline_ = nullptr;
// Destroy buffer
buffer_.Destroy();
@@ -121,3 +130,8 @@ const olive::RenderMode &RenderInstance::mode() const
{
return mode_;
}
ShaderPtr RenderInstance::default_pipeline() const
{
return default_pipeline_;
}
+5
View File
@@ -25,6 +25,7 @@
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include "render/gl/shaderptr.h"
#include "render/renderframebuffer.h"
#include "render/rendermodes.h"
@@ -63,6 +64,8 @@ public:
const olive::RenderMode& mode() const;
ShaderPtr default_pipeline() const;
private:
QOpenGLContext ctx_;
@@ -81,6 +84,8 @@ private:
olive::RenderMode mode_;
int divider_;
ShaderPtr default_pipeline_;
};
#endif // GLINSTANCE_H