From 7479cf5933d37e967fb3cb3f4e075f824254a906 Mon Sep 17 00:00:00 2001 From: unfa Date: Sun, 28 Apr 2019 18:49:07 +0200 Subject: [PATCH 1/4] A single despill effect for improving efects of chroma keying. Works for Green, Blue and Red backgrounds, no other controls yet. Tested. --- effects/internal/despill.frag | 59 +++++++++++++++++++++++++++++++++++ effects/internal/despill.xml | 11 +++++++ 2 files changed, 70 insertions(+) create mode 100644 effects/internal/despill.frag create mode 100644 effects/internal/despill.xml diff --git a/effects/internal/despill.frag b/effects/internal/despill.frag new file mode 100644 index 000000000..7efafbdf2 --- /dev/null +++ b/effects/internal/despill.frag @@ -0,0 +1,59 @@ +/*** + Despill - for cleaning up keying residue. + Implementation by unfa for Olive-Editor Community +***/ + +uniform sampler2D tex; +varying vec2 uTexCoord; +uniform vec2 resolution; +uniform int channel; + +const vec2 renderScale = vec2(1,1); + +void main(void) +{ + vec2 uv = gl_FragCoord.xy/resolution.xy; + + vec4 col = texture2D(tex, uv); + + // separate channels + + float r = col.r; + float g = col.g; + float b = col.b; + float a = col.a; + + // Select despilled channel: 0 = RED; 1 = GREEN; 2 = BLUE; + + if (channel == 0) // RED + { + // replace new green channel by avaraging between existing red and blue channels + float r2 = (g + b) * 0.5; + + // now composite the original and new gree channel using the "darken" mode + r = min(r, r2); + } + + if (channel == 1) // GREEN + { + // replace new green channel by avaraging between existing red and blue channels + float g2 = (r + b) * 0.5; + + // now composite the original and new gree channel using the "darken" mode + g = min(g, g2); + } + + if (channel == 2) // BLUE + { + // replace new green channel by avaraging between existing red and blue channels + float b2 = (r + g) * 0.5; + + // now composite the original and new gree channel using the "darken" mode + b = min(b, b2); + } + + + // and return the result + + gl_FragColor = vec4(r, g, b, a); +} diff --git a/effects/internal/despill.xml b/effects/internal/despill.xml new file mode 100644 index 000000000..280d5fb42 --- /dev/null +++ b/effects/internal/despill.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + From b8114f63a4a55db20d538e35e1d0454fe6bf86cf Mon Sep 17 00:00:00 2001 From: unfa Date: Sun, 28 Apr 2019 19:03:11 +0200 Subject: [PATCH 2/4] Update despill.frag Changed comment. --- effects/internal/despill.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/effects/internal/despill.frag b/effects/internal/despill.frag index 7efafbdf2..a21c90145 100644 --- a/effects/internal/despill.frag +++ b/effects/internal/despill.frag @@ -1,6 +1,6 @@ /*** Despill - for cleaning up keying residue. - Implementation by unfa for Olive-Editor Community + Written by unfa for Olive Video Editor. ***/ uniform sampler2D tex; From 5e060d3d29d0d4f53b44a25ef31eb0cbcf6d4030 Mon Sep 17 00:00:00 2001 From: Troy James Sobotka Date: Sun, 28 Apr 2019 10:42:51 -0700 Subject: [PATCH 3/4] Update to REC.709, not batshit crazy REC.601 Update to use REC.709 coefficients. --- effects/shaders/chromakey.frag | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/effects/shaders/chromakey.frag b/effects/shaders/chromakey.frag index 4f57d8b1e..98c77dc7a 100644 --- a/effects/shaders/chromakey.frag +++ b/effects/shaders/chromakey.frag @@ -15,17 +15,24 @@ uniform int mode; float rgb2y (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.299*c.r + 0.587*c.g + 0.114*c.b); + +// This isn’t colour managed and is a huge mess, but in the +// short term, using correct weights will give significantly +// more ideal results. The correct weights for REC.709 are +// 0.2126 R, 0.7152 G, and 0.722 B. Easy change. +// The coefficients for YCbCr are calculated off of the +// REC.709 values. + return (0.2126*c.r + 0.7152*c.g + 0.0.722*c.b); } float rgb2cb (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.5 + -0.168736*c.r - 0.331264*c.g + 0.5*c.b); + return (0.5 + -0.1145721061*c.r - 0.3854278939*c.g + 0.5*c.b); } float rgb2cr (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ - return (0.5 + 0.5*c.r - 0.418688*c.g - 0.081312*c.b); + return (0.5 + 0.5*c.r - 0.4541529083*c.g - 0.0458470917*c.b); } float colorclose(float Cb_p,float Cr_p,float Cb_key,float Cr_key,float tola,float tolb) { @@ -62,4 +69,4 @@ void main(void) { } gl_FragColor = texture_color; -} \ No newline at end of file +} From e5152bc0c0bf3b61facccb6e4de0803f97afe6d1 Mon Sep 17 00:00:00 2001 From: Troy James Sobotka Date: Mon, 29 Apr 2019 17:40:02 -0700 Subject: [PATCH 4/4] Fix typo in effects/shaders/chromakey.frag Fix typo pointed out by @brimsonbhin. --- effects/shaders/chromakey.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/effects/shaders/chromakey.frag b/effects/shaders/chromakey.frag index 98c77dc7a..88b9fdd0f 100644 --- a/effects/shaders/chromakey.frag +++ b/effects/shaders/chromakey.frag @@ -22,7 +22,7 @@ float rgb2y (vec3 c) { // 0.2126 R, 0.7152 G, and 0.722 B. Easy change. // The coefficients for YCbCr are calculated off of the // REC.709 values. - return (0.2126*c.r + 0.7152*c.g + 0.0.722*c.b); + return (0.2126*c.r + 0.7152*c.g + 0.0722*c.b); } float rgb2cb (vec3 c) {