mirror of
https://github.com/brunoherbelin/vimix.git
synced 2026-06-16 04:27:23 +02:00
BugFix luma and chroma key
making alpha filters compatible with alpha fading of media
This commit is contained in:
@@ -42,16 +42,24 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec4 texColor0 = texture(iChannel0, fragCoord.xy / iResolution.xy);
|
||||
|
||||
// RGB is alpha-premultiplied : revert
|
||||
vec4 col = vec4( texColor0.rgb / max(texColor0.a, 0.001), 1.0);
|
||||
|
||||
//convert from RGB to YCvCr/YUV
|
||||
vec4 keyYUV = RGBtoYUV * chromaKey;
|
||||
vec4 yuv = RGBtoYUV * texColor0;
|
||||
vec4 yuv = RGBtoYUV * col;
|
||||
|
||||
// correction of color
|
||||
float t = (1. - Tolerance) * 0.2;
|
||||
float mask = 1.0 - colordistance(yuv.rgb, keyYUV.rgb, vec2(t, t + 0.2));
|
||||
vec4 col = max(texColor0 - mask * chromaKey, 0.0);
|
||||
col = max(col - mask * chromaKey, 0.0);
|
||||
|
||||
// correction of alpha
|
||||
t = Threshold * Threshold * 0.2;
|
||||
col.a -= 1.0 - colordistance(yuv.rgb, keyYUV.rgb, vec2(t, t + 0.25));
|
||||
|
||||
// restore texture alpha
|
||||
col.a *= texColor0.a;
|
||||
|
||||
fragColor = col;
|
||||
}
|
||||
|
||||
@@ -9,40 +9,42 @@ uniform float Threshold;
|
||||
uniform float Tolerance;
|
||||
|
||||
|
||||
//float sRGBtoLin( in float v ) {
|
||||
// // Send this function a decimal sRGB gamma encoded color value
|
||||
// // between 0.0 and 1.0, and it returns a linearized value.
|
||||
// if ( v <= 0.04045 ) {
|
||||
// return v / 12.92;
|
||||
// } else {
|
||||
// return pow((( v + 0.055)/1.055),2.4);
|
||||
// }
|
||||
//}
|
||||
float sRGBtoLin( in float v ) {
|
||||
// Send this function a decimal sRGB gamma encoded color value
|
||||
// between 0.0 and 1.0, and it returns a linearized value.
|
||||
if ( v <= 0.04045 ) {
|
||||
return v / 12.92;
|
||||
} else {
|
||||
return pow((( v + 0.055)/1.055),2.4);
|
||||
}
|
||||
}
|
||||
|
||||
//// returns L* which is "perceptual lightness"
|
||||
//float lightness ( in vec3 color )
|
||||
//{
|
||||
// float Y = 0.2126 * sRGBtoLin(color.r)
|
||||
// + 0.7152 * sRGBtoLin(color.g)
|
||||
// + 0.0722 * sRGBtoLin(color.b);
|
||||
// returns L* which is "perceptual lightness"
|
||||
float lightness ( in vec3 color )
|
||||
{
|
||||
float Y = 0.2126 * sRGBtoLin(color.r)
|
||||
+ 0.7152 * sRGBtoLin(color.g)
|
||||
+ 0.0722 * sRGBtoLin(color.b);
|
||||
|
||||
// if ( Y <= (216./24389.) ) { // The CIE standard states 0.008856 but 216/24389 is the intent for 0.008856451679036
|
||||
// Y = Y * (24389./27.); // The CIE standard states 903.3, but 24389/27 is the intent, making 903.296296296296296
|
||||
// } else {
|
||||
// Y = pow(Y,(1./3.)) * 116. - 16.;
|
||||
// }
|
||||
if ( Y <= (216./24389.) ) { // The CIE standard states 0.008856 but 216/24389 is the intent for 0.008856451679036
|
||||
Y = Y * (24389./27.); // The CIE standard states 903.3, but 24389/27 is the intent, making 903.296296296296296
|
||||
} else {
|
||||
Y = pow(Y,(1./3.)) * 116. - 16.;
|
||||
}
|
||||
|
||||
// return 0.01 * Y;
|
||||
//}
|
||||
return 0.01 * Y;
|
||||
}
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
||||
{
|
||||
vec2 fragPos = fragCoord.xy / iResolution.xy;
|
||||
vec3 RGB = texture(iChannel0, fragPos).rgb;
|
||||
vec4 texColor0 = texture(iChannel0, fragCoord.xy / iResolution.xy);
|
||||
|
||||
// RGB is alpha-premultiplied : revert
|
||||
texColor0 = vec4( texColor0.rgb / max(texColor0.a, 0.001), texColor0.a);
|
||||
|
||||
float L = dot(RGB, vec3(0.299, 0.587, 0.114));
|
||||
// float L = lightness( RGB );
|
||||
// modify alpha by the lightness of the image
|
||||
float L = lightness( texColor0.rgb );
|
||||
texColor0.a *= smoothstep( Threshold, Threshold + Tolerance * Tolerance, abs(Luminance - L) );
|
||||
|
||||
fragColor = vec4( RGB, smoothstep( Threshold, Threshold + Tolerance * Tolerance, abs(Luminance - L) ) );
|
||||
fragColor = texColor0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user