From 5b4d80edadf21ca218204da0335b0dd903d1f307 Mon Sep 17 00:00:00 2001 From: oc1024 Date: Wed, 23 Jan 2019 08:25:18 -0300 Subject: [PATCH 1/5] Added luma key effect --- effects/lumakey.frag | 21 +++++++++++++++++++++ effects/lumakey.xml | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 effects/lumakey.frag create mode 100644 effects/lumakey.xml diff --git a/effects/lumakey.frag b/effects/lumakey.frag new file mode 100644 index 000000000..3e7b0d266 --- /dev/null +++ b/effects/lumakey.frag @@ -0,0 +1,21 @@ +/* Luma key simple program +Based on Edward Cannon's Simple Chroma Key (adaptation by Olive Team) +Feel free to modify and use at will */ + +uniform sampler2D tex; +varying vec2 vTexCoord; + +uniform float loc; +uniform float hic; + +void main(void) { + vec4 texture_color = texture2D(tex,vTexCoord); + + float luma = max(max(texture_color.r,texture_color.g), texture_color.b) + min(min(texture_color.r,texture_color.g), texture_color.b); + + luma /= 2.0; + + texture_color.a = (luma >= loc && luma <= hic) ? luma : 0.0; + + gl_FragColor = texture_color; +} \ No newline at end of file diff --git a/effects/lumakey.xml b/effects/lumakey.xml new file mode 100644 index 000000000..03b933877 --- /dev/null +++ b/effects/lumakey.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file From 728a3fee949b54cc5086936c598752631a9a4f02 Mon Sep 17 00:00:00 2001 From: oc1024 Date: Wed, 23 Jan 2019 11:53:25 -0300 Subject: [PATCH 2/5] upper limit is now full alpha --- effects/lumakey.frag | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/effects/lumakey.frag b/effects/lumakey.frag index 3e7b0d266..3ded5dac5 100644 --- a/effects/lumakey.frag +++ b/effects/lumakey.frag @@ -15,7 +15,13 @@ void main(void) { luma /= 2.0; - texture_color.a = (luma >= loc && luma <= hic) ? luma : 0.0; + if (luma > hic) { + texture_color.a = 1.0; + } else if (luma < loc) { + texture_color.a = 0.0; + } else { + texture_color.a = luma; + } gl_FragColor = texture_color; -} \ No newline at end of file +} From ac12a734869b0d72fd79d22896c0e69ac916e2d7 Mon Sep 17 00:00:00 2001 From: oc1024 Date: Wed, 23 Jan 2019 23:26:05 -0200 Subject: [PATCH 3/5] Color Selection filter --- effects/colorsel.frag | 89 +++++++++++++++++++++++++++++++++++++++++++ effects/colorsel.xml | 21 ++++++++++ 2 files changed, 110 insertions(+) create mode 100644 effects/colorsel.frag create mode 100644 effects/colorsel.xml diff --git a/effects/colorsel.frag b/effects/colorsel.frag new file mode 100644 index 000000000..801c96b73 --- /dev/null +++ b/effects/colorsel.frag @@ -0,0 +1,89 @@ +/* Filter by color characteristic simple program +Based on Edward Cannon's Simple Chroma Key (adaptation by Olive Team) +RGB to HSV based on MattKC's toonify source code +Feel free to modify and use at will */ +#version 150 + +uniform sampler2D tex; +varying vec2 vTexCoord; + +uniform float loc; +uniform float hic; +uniform int compo; + +float rgb2luma(vec3 c) { + return (max(max(c.r,c.g), c.b) + min(min(c.r,c.g), c.b))/2.0; +} + +vec3 rgb2hsv(vec3 c) +{ + float r = c.r; + float b = c.b; + float g = c.g; + float minv, maxv, delta; + vec3 res; + + minv = min(min(r, g), b); + maxv = max(max(r, g), b); + res.z = maxv; // v + + delta = maxv - minv; + + if( maxv != 0.0 ) + res.y = delta / maxv; // s + else { + // r = g = b = 0 // s = 0, v is undefined + res.y = 0.0; + res.x = -1.0; + return res; + } + + if( r == maxv ) + res.x = ( g - b ) / delta; // between yellow & magenta + else if( g == maxv ) + res.x = 2.0 + ( b - r ) / delta; // between cyan & yellow + else + res.x = 4.0 + ( r - g ) / delta; // between magenta & cyan + + res.x = res.x * 60.0; // degrees + if( res.x < 0.0 ) + res.x = res.x + 360.0; + + return res; +} + +bool isNotIncreasingSequence(float a, float b, float c) { + return (c < b || a > b); +} + +void main(void) { + vec4 tc = texture2D(tex,vTexCoord); + vec3 color = tc.rgb; + float toCheck = 0.0; + + switch(compo) { + case 0 : + toCheck = rgb2luma(color); + break; + case 4 : + toCheck = color.r; + break; + case 5 : + toCheck = color.g; + break; + case 6 : + toCheck = color.b; + break; + case 1 : + toCheck = rgb2hsv(color).z; + break; + case 2 : + toCheck = rgb2hsv(color).x/360.0; + break; + case 3 : + toCheck = rgb2hsv(color).y; + break; + } + tc.a = isNotIncreasingSequence(loc, toCheck, hic) ? 0.0 : tc.a; + gl_FragColor = tc; +} diff --git a/effects/colorsel.xml b/effects/colorsel.xml new file mode 100644 index 000000000..2a486afd2 --- /dev/null +++ b/effects/colorsel.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + From e6df7de6bcb752a27c75226a56c6828d9a01f87e Mon Sep 17 00:00:00 2001 From: oc1024 Date: Fri, 25 Jan 2019 09:13:24 -0200 Subject: [PATCH 4/5] 0-100 thresholds + invert checkboxes Removes the need for piping the effect between Invert effects, which makes a unnecessary performance hit. --- effects/colorsel.frag | 17 +++++++++-------- effects/colorsel.xml | 7 +++++-- effects/lumakey.frag | 11 ++++++----- effects/lumakey.xml | 9 ++++++--- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/effects/colorsel.frag b/effects/colorsel.frag index 801c96b73..05ddff90d 100644 --- a/effects/colorsel.frag +++ b/effects/colorsel.frag @@ -10,6 +10,7 @@ varying vec2 vTexCoord; uniform float loc; uniform float hic; uniform int compo; +uniform bool invert; float rgb2luma(vec3 c) { return (max(max(c.r,c.g), c.b) + min(min(c.r,c.g), c.b))/2.0; @@ -63,27 +64,27 @@ void main(void) { switch(compo) { case 0 : - toCheck = rgb2luma(color); + toCheck = rgb2luma(color)*100.0; break; case 4 : - toCheck = color.r; + toCheck = color.r*100.0; break; case 5 : - toCheck = color.g; + toCheck = color.g*100.0; break; case 6 : - toCheck = color.b; + toCheck = color.b*100.0; break; case 1 : - toCheck = rgb2hsv(color).z; + toCheck = rgb2hsv(color).z*100.0; break; case 2 : - toCheck = rgb2hsv(color).x/360.0; + toCheck = rgb2hsv(color).x/3.6; break; case 3 : - toCheck = rgb2hsv(color).y; + toCheck = rgb2hsv(color).y*100.0; break; } - tc.a = isNotIncreasingSequence(loc, toCheck, hic) ? 0.0 : tc.a; + tc.a = isNotIncreasingSequence(loc, toCheck, hic) ? (invert ? tc.a : 0.0) : (invert ? 0.0 : tc.a); gl_FragColor = tc; } diff --git a/effects/colorsel.xml b/effects/colorsel.xml index 2a486afd2..00a4c865a 100644 --- a/effects/colorsel.xml +++ b/effects/colorsel.xml @@ -12,10 +12,13 @@ - + - + + + + diff --git a/effects/lumakey.frag b/effects/lumakey.frag index 3ded5dac5..d8092c4cb 100644 --- a/effects/lumakey.frag +++ b/effects/lumakey.frag @@ -7,6 +7,7 @@ varying vec2 vTexCoord; uniform float loc; uniform float hic; +uniform bool invert; void main(void) { vec4 texture_color = texture2D(tex,vTexCoord); @@ -15,12 +16,12 @@ void main(void) { luma /= 2.0; - if (luma > hic) { - texture_color.a = 1.0; - } else if (luma < loc) { - texture_color.a = 0.0; + if (luma > hic/100.0) { + texture_color.a = (invert ? 0.0 : 1.0); + } else if (luma < loc/100.0) { + texture_color.a = (invert ? 1.0 : 0.0); } else { - texture_color.a = luma; + texture_color.a = (invert ? 1.0-luma : luma); } gl_FragColor = texture_color; diff --git a/effects/lumakey.xml b/effects/lumakey.xml index 03b933877..0c3175c2e 100644 --- a/effects/lumakey.xml +++ b/effects/lumakey.xml @@ -1,10 +1,13 @@ - + - + + + + - \ No newline at end of file + From 3d2ec7aee3a0457b1abb81d49dadadda9334193c Mon Sep 17 00:00:00 2001 From: oc1024 Date: Wed, 30 Jan 2019 00:30:38 -0200 Subject: [PATCH 5/5] Premultiply alpha + GLSL1.1 Support for Olive's new blend-mode infrastructure. Plus, `switch (compo) {` has been replaced with `if {} else if {}` in Color Finder so it runs on OpenGL 2.0 hardware. --- effects/colorsel.frag | 35 ++++++++++++++--------------------- effects/lumakey.frag | 1 + 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/effects/colorsel.frag b/effects/colorsel.frag index 05ddff90d..903e4a0f8 100644 --- a/effects/colorsel.frag +++ b/effects/colorsel.frag @@ -2,7 +2,7 @@ Based on Edward Cannon's Simple Chroma Key (adaptation by Olive Team) RGB to HSV based on MattKC's toonify source code Feel free to modify and use at will */ -#version 150 +#version 110 uniform sampler2D tex; varying vec2 vTexCoord; @@ -58,33 +58,26 @@ bool isNotIncreasingSequence(float a, float b, float c) { } void main(void) { - vec4 tc = texture2D(tex,vTexCoord); - vec3 color = tc.rgb; + vec4 texture_color = texture2D(tex,vTexCoord); + vec3 color = texture_color.rgb; float toCheck = 0.0; - switch(compo) { - case 0 : + if (compo == 0) { toCheck = rgb2luma(color)*100.0; - break; - case 4 : + } else if (compo == 4) { toCheck = color.r*100.0; - break; - case 5 : + } else if (compo == 5) { toCheck = color.g*100.0; - break; - case 6 : + } else if (compo == 6) { toCheck = color.b*100.0; - break; - case 1 : + } else if (compo == 1) { toCheck = rgb2hsv(color).z*100.0; - break; - case 2 : + } else if (compo == 2) { toCheck = rgb2hsv(color).x/3.6; - break; - case 3 : + } else if (compo == 3) { toCheck = rgb2hsv(color).y*100.0; - break; - } - tc.a = isNotIncreasingSequence(loc, toCheck, hic) ? (invert ? tc.a : 0.0) : (invert ? 0.0 : tc.a); - gl_FragColor = tc; + } + texture_color.a = isNotIncreasingSequence(loc, toCheck, hic) ? (invert ? texture_color.a : 0.0) : (invert ? 0.0 : texture_color.a); + texture_color.rgb *= texture_color.a; + gl_FragColor = texture_color; } diff --git a/effects/lumakey.frag b/effects/lumakey.frag index d8092c4cb..16dfdfa08 100644 --- a/effects/lumakey.frag +++ b/effects/lumakey.frag @@ -24,5 +24,6 @@ void main(void) { texture_color.a = (invert ? 1.0-luma : luma); } + texture_color.rgb *= texture_color.a; gl_FragColor = texture_color; }