ported dip to black transition to external type and reimplemented drop shadow shader
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
# 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(diptoblack)
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
node/block/transition/externaltransition.h
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
node/block/transition/diptoblack/diptoblack.h
|
||||
node/block/transition/diptoblack/diptoblack.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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
|
||||
@@ -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_;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<effect id="org.olivevideoeditor.Olive.diptoblack">
|
||||
<!-- Effect Name -->
|
||||
<name lang="en_US">Dip to Black</name>
|
||||
|
||||
<!-- Effect Category -->
|
||||
<category lang="en_US">Transition</category>
|
||||
|
||||
<!-- Effect Description -->
|
||||
<description lang="en_US">
|
||||
A smooth dip to transparency and back into another clip.
|
||||
</description>
|
||||
|
||||
<!-- Qt Resource path to fragment shader -->
|
||||
<fragment url=":/shaders/diptoblack.frag"/>
|
||||
</effect>
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<effect id="org.olivevideoeditor.Olive.dropshadow">
|
||||
<!-- Effect Name -->
|
||||
<name lang="en_US">Drop Shadow</name>
|
||||
|
||||
<!-- Effect Category -->
|
||||
<category lang="en_US">Stylize</category>
|
||||
|
||||
<!-- Effect Description -->
|
||||
<description lang="en_US">
|
||||
Generate a drop shadow of a clip.
|
||||
</description>
|
||||
|
||||
<!-- Parameter: Texture Input -->
|
||||
<param id="tex_in" type="texture">
|
||||
<name lang="en_US">Input</name>
|
||||
</param>
|
||||
|
||||
<!-- Parameter: Softness Input -->
|
||||
<param id="color_in" type="color">
|
||||
<name lang="en_US">Color</name>
|
||||
</param>
|
||||
|
||||
<!-- Parameter: Softness Input -->
|
||||
<param id="softness_in" type="float">
|
||||
<name lang="en_US">Softness</name>
|
||||
<min>0</min>
|
||||
<default>10</default>
|
||||
</param>
|
||||
|
||||
<!-- Parameter: Opacity Input -->
|
||||
<param id="opacity_in" type="float">
|
||||
<name lang="en_US">Opacity</name>
|
||||
<min>0</min>
|
||||
<default>80</default>
|
||||
<max>100</max>
|
||||
</param>
|
||||
|
||||
<!-- Parameter: Distance Input -->
|
||||
<param id="distance_in" type="float">
|
||||
<name lang="en_US">Distance</name>
|
||||
<min>0</min>
|
||||
<default>10</default>
|
||||
</param>
|
||||
|
||||
<!-- Parameter: Direction Input -->
|
||||
<param id="direction_in" type="float">
|
||||
<name lang="en_US">Direction</name>
|
||||
<default>45</default>
|
||||
</param>
|
||||
|
||||
<!-- Qt Resource path to fragment shader -->
|
||||
<fragment url=":/shaders/dropshadow.frag"/>
|
||||
</effect>
|
||||
@@ -6,7 +6,10 @@
|
||||
<file>boxblur.xml</file>
|
||||
<file>crossdissolve.frag</file>
|
||||
<file>crossdissolve.xml</file>
|
||||
<file>dropshadow.frag</file>
|
||||
<file>dropshadow.xml</file>
|
||||
<file>diptoblack.frag</file>
|
||||
<file>diptoblack.xml</file>
|
||||
<file>gaussianblur.frag</file>
|
||||
<file>gaussianblur.xml</file>
|
||||
<file>opacity.frag</file>
|
||||
|
||||
Reference in New Issue
Block a user