From 97dadace1f1ac89eacfd608db7f8a4bb641df3e0 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 14 Feb 2020 19:13:30 +1100 Subject: [PATCH] shaders: added stroke shader --- app/node/factory.cpp | 1 + app/shaders/dropshadow.xml | 4 ++- app/shaders/shaders.qrc | 2 ++ app/shaders/stroke.frag | 61 ++++++++++++++++++++++++++++++++++++++ app/shaders/stroke.xml | 43 +++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 app/shaders/stroke.frag create mode 100644 app/shaders/stroke.xml diff --git a/app/node/factory.cpp b/app/node/factory.cpp index 273e8ab69..d0d7b12aa 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -27,6 +27,7 @@ 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/stroke.xml")); library_.append(new ExternalNode(":/shaders/alphaover.xml")); library_.append(new ExternalNode(":/shaders/dropshadow.xml")); library_.append(new ExternalTransition(":/shaders/crossdissolve.xml")); diff --git a/app/shaders/dropshadow.xml b/app/shaders/dropshadow.xml index 31bcfb2eb..5a35a66ef 100644 --- a/app/shaders/dropshadow.xml +++ b/app/shaders/dropshadow.xml @@ -5,6 +5,7 @@ Stylize + Stylise @@ -16,9 +17,10 @@ Input - + Color + Colour diff --git a/app/shaders/shaders.qrc b/app/shaders/shaders.qrc index f4ae6fab0..19a9782f5 100644 --- a/app/shaders/shaders.qrc +++ b/app/shaders/shaders.qrc @@ -16,6 +16,8 @@ opacity.xml solid.frag solid.xml + stroke.frag + stroke.xml videoinput.frag videoinput.vert diff --git a/app/shaders/stroke.frag b/app/shaders/stroke.frag new file mode 100644 index 000000000..20ff1607f --- /dev/null +++ b/app/shaders/stroke.frag @@ -0,0 +1,61 @@ +#version 110 + +// Standard inputs +uniform vec2 ove_resolution; +varying vec2 ove_texcoord; +uniform int ove_iteration; + +// Node parameter inputs +uniform sampler2D tex_in; +uniform vec3 color_in; +uniform float radius_in; +uniform float opacity_in; + +void main(void) { + if (radius_in == 0.0 || opacity_in == 0.0) { + // No-op, do nothing + gl_FragColor = texture2D(tex_in, ove_texcoord); + return; + } + + float radius = ceil(radius_in); + + float stroke_weight = 0.0; + + // Loop over box + for (float i=-radius + 0.5; i<=radius; i += 2.0) { + float x_coord = i / ove_resolution.x; + + for (float j=-radius + 0.5; j<=radius; j += 2.0) { + float y_coord = j / ove_resolution.y; + + if (abs(length(vec2(i, j))) < radius) { + // Get pixel here + stroke_weight += texture2D(tex_in, ove_texcoord + vec2(x_coord, y_coord)).a; + + if (stroke_weight >= 1.0) { + break; + } + } + } + + if (stroke_weight >= 1.0) { + stroke_weight = 1.0; + break; + } + } + + stroke_weight *= opacity_in * 0.01; + + // Make RGBA color + vec4 stroke_col = vec4(vec3(1.0) * stroke_weight, stroke_weight); + //vec4 stroke_col = vec4(color_in * stroke_weight, stroke_weight); + + // Alpha over color here + vec4 pixel_here = texture2D(tex_in, ove_texcoord); + + stroke_col *= 1.0 - pixel_here.a; + stroke_col += pixel_here; + + gl_FragColor = stroke_col; +} diff --git a/app/shaders/stroke.xml b/app/shaders/stroke.xml new file mode 100644 index 000000000..a31e0355e --- /dev/null +++ b/app/shaders/stroke.xml @@ -0,0 +1,43 @@ + + + + Stroke + + + Stylize + Stylise + + + + Creates a stroke outline around an image. + + + + + Input + + + + + Color + Colour + + + + + Radius + 0 + 10 + + + + + Opacity + 0 + 100 + 100 + + + + +