diff --git a/app/node/block/transition/CMakeLists.txt b/app/node/block/transition/CMakeLists.txt index 760462d82..0ca1160b9 100644 --- a/app/node/block/transition/CMakeLists.txt +++ b/app/node/block/transition/CMakeLists.txt @@ -14,8 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -add_subdirectory(diptoblack) - set(OLIVE_SOURCES ${OLIVE_SOURCES} node/block/transition/externaltransition.h diff --git a/app/node/block/transition/diptoblack/CMakeLists.txt b/app/node/block/transition/diptoblack/CMakeLists.txt deleted file mode 100644 index f66dd5fc1..000000000 --- a/app/node/block/transition/diptoblack/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# 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 . - -set(OLIVE_SOURCES - ${OLIVE_SOURCES} - node/block/transition/diptoblack/diptoblack.h - node/block/transition/diptoblack/diptoblack.cpp - PARENT_SCOPE -) diff --git a/app/node/block/transition/diptoblack/diptoblack.cpp b/app/node/block/transition/diptoblack/diptoblack.cpp deleted file mode 100644 index 9252a2b58..000000000 --- a/app/node/block/transition/diptoblack/diptoblack.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "diptoblack.h" - -Node *DipToBlackTransition::copy() const -{ - DipToBlackTransition* c = new DipToBlackTransition(); - - CopyParameters(this, c); - - return c; -} - -QString DipToBlackTransition::Name() const -{ - return tr("Dip to Black"); -} - -QString DipToBlackTransition::id() const -{ - return "org.olivevideoeditor.Olive.diptoblack"; -} - -QString DipToBlackTransition::Description() const -{ - return tr("A smooth dip to transparency and back into another clip."); -} - -bool DipToBlackTransition::IsAccelerated() const -{ - return true; -} - -QString DipToBlackTransition::AcceleratedCodeFragment() const -{ - return ReadFileAsString(":/shaders/diptoblack.frag"); -} diff --git a/app/node/block/transition/diptoblack/diptoblack.h b/app/node/block/transition/diptoblack/diptoblack.h deleted file mode 100644 index 99e436cba..000000000 --- a/app/node/block/transition/diptoblack/diptoblack.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef DIPTOBLACKTRANSITION_H -#define DIPTOBLACKTRANSITION_H - -#include "../transition.h" - -class DipToBlackTransition : public TransitionBlock -{ -public: - DipToBlackTransition() = default; - - virtual Node* copy() const override; - - virtual QString Name() const override; - virtual QString id() const override; - virtual QString Description() const override; - - virtual bool IsAccelerated() const override; - virtual QString AcceleratedCodeFragment() const override; -}; - -#endif // DIPTOBLACKTRANSITION_H diff --git a/app/node/block/transition/transition.cpp b/app/node/block/transition/transition.cpp index 0b087d4ad..f6237fc45 100644 --- a/app/node/block/transition/transition.cpp +++ b/app/node/block/transition/transition.cpp @@ -19,11 +19,6 @@ Block::Type TransitionBlock::type() const return kTransition; } -QString TransitionBlock::Category() const -{ - return tr("Transition"); -} - NodeInput *TransitionBlock::out_block_input() const { return out_block_input_; diff --git a/app/node/block/transition/transition.h b/app/node/block/transition/transition.h index 21bf30c2b..21e709a09 100644 --- a/app/node/block/transition/transition.h +++ b/app/node/block/transition/transition.h @@ -9,7 +9,6 @@ public: TransitionBlock(); virtual Type type() const override; - virtual QString Category() const override; NodeInput* out_block_input() const; NodeInput* in_block_input() const; diff --git a/app/node/factory.cpp b/app/node/factory.cpp index 3b57c4e14..c7af032fe 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -26,7 +26,10 @@ void NodeFactory::Initialize() library_.append(new ExternalNode(":/shaders/boxblur.xml")); library_.append(new ExternalNode(":/shaders/opacity.xml")); library_.append(new ExternalNode(":/shaders/solid.xml")); + library_.append(new ExternalNode(":/shaders/alphaover.xml")); + library_.append(new ExternalNode(":/shaders/dropshadow.xml")); library_.append(new ExternalTransition(":/shaders/crossdissolve.xml")); + library_.append(new ExternalTransition(":/shaders/diptoblack.xml")); } void NodeFactory::Destroy() diff --git a/app/shaders/diptoblack.xml b/app/shaders/diptoblack.xml new file mode 100644 index 000000000..7a4127ded --- /dev/null +++ b/app/shaders/diptoblack.xml @@ -0,0 +1,16 @@ + + + + Dip to Black + + + Transition + + + + A smooth dip to transparency and back into another clip. + + + + + diff --git a/app/shaders/dropshadow.frag b/app/shaders/dropshadow.frag new file mode 100644 index 000000000..1b6a0d551 --- /dev/null +++ b/app/shaders/dropshadow.frag @@ -0,0 +1,59 @@ +#version 110 + +#define M_PI 3.1415926535897932384626433832795 + +uniform vec2 ove_resolution; +varying vec2 ove_texcoord; + +uniform sampler2D tex_in; +uniform vec3 color_in; +uniform float softness_in; +uniform float opacity_in; +uniform float distance_in; +uniform float direction_in; + +void main(void) { + // Use pythagoras with the distance (hypotenuse) to find the shadow offset + float direction_radians = direction_in * (M_PI/180.0); + + float opposite = sin(direction_radians) * distance_in; + float adjacent = cos(direction_radians) * distance_in; + + vec2 angle = vec2(adjacent, opposite); + + // Convert distance from pixels to 0.0 - 1.0 texture coordinates + angle /= ove_resolution; + + float shadow_alpha; + + // For a soft shadow, we use a box blur-like formula + if (softness_in > 0.0) { + float radius = ceil(softness_in); + float divider = 1.0 / pow(softness_in, 2.0); + shadow_alpha = 0.0; + + for (float x=-radius+0.5;x<=radius;x+=2.0) { + for (float y=-radius+0.5;y<=radius;y+=2.0) { + vec2 pixel_coord = ove_texcoord - angle; + pixel_coord.x += x/ove_resolution.x; + pixel_coord.y += y/ove_resolution.y; + vec4 pixel_color = texture2D(tex_in, pixel_coord); + + shadow_alpha += pixel_color.a * divider; + } + } + } else { + // Perfectly hard shadow + vec4 src_color = texture2D(tex_in, ove_texcoord - angle); + shadow_alpha = src_color.a; + } + + vec4 shadow_px = vec4(color_in, shadow_alpha * opacity_in * 0.01); + + // Get current pixel and perform an alpha over for it over the shadow we've made + vec4 dst_color = texture2D(tex_in, ove_texcoord); + shadow_px *= (1.0 - dst_color.a); + shadow_px += dst_color; + + gl_FragColor = shadow_px; +} diff --git a/app/shaders/dropshadow.xml b/app/shaders/dropshadow.xml new file mode 100644 index 000000000..31bcfb2eb --- /dev/null +++ b/app/shaders/dropshadow.xml @@ -0,0 +1,54 @@ + + + + Drop Shadow + + + Stylize + + + + Generate a drop shadow of a clip. + + + + + Input + + + + + Color + + + + + Softness + 0 + 10 + + + + + Opacity + 0 + 80 + 100 + + + + + Distance + 0 + 10 + + + + + Direction + 45 + + + + + diff --git a/app/shaders/shaders.qrc b/app/shaders/shaders.qrc index ad8cb5d88..f4ae6fab0 100644 --- a/app/shaders/shaders.qrc +++ b/app/shaders/shaders.qrc @@ -6,7 +6,10 @@ boxblur.xml crossdissolve.frag crossdissolve.xml + dropshadow.frag + dropshadow.xml diptoblack.frag + diptoblack.xml gaussianblur.frag gaussianblur.xml opacity.frag