diff --git a/effects/internal/despill.frag b/effects/internal/despill.frag new file mode 100644 index 000000000..a21c90145 --- /dev/null +++ b/effects/internal/despill.frag @@ -0,0 +1,59 @@ +/*** + Despill - for cleaning up keying residue. + Written by unfa for Olive Video Editor. +***/ + +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 @@ + + + + + + + + + + + diff --git a/effects/shaders/chromakey.frag b/effects/shaders/chromakey.frag index ea062307f..6ee8b07a2 100644 --- a/effects/shaders/chromakey.frag +++ b/effects/shaders/chromakey.frag @@ -12,6 +12,9 @@ uniform float tola; uniform float tolb; uniform bool opt; uniform int mode; + +float rgb2y (vec3 c) { + /*a utility function to convert colors in RGB into YCbCr*/ // This isn’t colour managed and is a huge mess, but in the // short term, using correct weights will give significantly @@ -20,18 +23,18 @@ uniform int mode; // The coefficients for YCbCr are calculated off of the // REC.709 values. return (0.2126*c.r + 0.7152*c.g + 0.0722*c.b); -} - +} + float rgb2cb (vec3 c) { /*a utility function to convert colors in RGB into YCbCr*/ 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.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) { /*decides if a color is close to the specified hue*/ float temp = sqrt(((Cb_key-Cb_p)*(Cb_key-Cb_p))+((Cr_key-Cr_p)*(Cr_key-Cr_p)));