added options to chroma key

This commit is contained in:
itsmattkc
2018-11-18 17:47:55 +11:00
parent 456103df2f
commit bcbaf7473e
3 changed files with 39 additions and 26 deletions
+31 -25
View File
@@ -11,45 +11,51 @@ uniform vec3 key_color;
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*/
return (0.299*c.r + 0.587*c.g + 0.114*c.b);
/*a utility function to convert colors in RGB into YCbCr*/
return (0.299*c.r + 0.587*c.g + 0.114*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);
/*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);
}
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);
/*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);
}
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)));
if (temp < tola) {return (0.0);}
if (temp < tolb) {return ((temp-tola)/(tolb-tola));}
return (1.0);
/*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)));
if (temp < tola) {return (0.0);}
if (temp < tolb) {return ((temp-tola)/(tolb-tola));}
return (1.0);
}
void main(void) {
float cb_key = rgb2cb(key_color);
float cr_key = rgb2cr(key_color);
vec4 texture_color = texture2D(tex, vTexCoord);
float cb_key = rgb2cb(key_color);
float cr_key = rgb2cr(key_color);
vec4 texture_color = texture2D(tex, vTexCoord);
float cb = rgb2cb(texture_color.rgb);
float cr = rgb2cr(texture_color.rgb);
float mask = colorclose(cb, cr, cb_key, cr_key, (tola/100.0), (tolb/100.0));
float submask = 1.0-mask;
float cb = rgb2cb(texture_color.rgb);
float cr = rgb2cr(texture_color.rgb);
float mask = colorclose(cb, cr, cb_key, cr_key, (tola/100.0), (tolb/100.0));
texture_color.r = max(texture_color.r - submask*key_color.r, 0.0) + submask;
texture_color.g = max(texture_color.g - submask*key_color.g, 0.0) + submask;
texture_color.b = max(texture_color.b - submask*key_color.b, 0.0) + submask;
texture_color.a *= mask;
gl_FragColor = texture_color;
if (mode == 0) { // composite
float submask = 1.0-mask;
texture_color.r = max(texture_color.r - submask*key_color.r, 0.0) + submask;
texture_color.g = max(texture_color.g - submask*key_color.g, 0.0) + submask;
texture_color.b = max(texture_color.b - submask*key_color.b, 0.0) + submask;
texture_color.a *= mask;
} else if (mode == 1) { // alpha
texture_color.rgb = vec3(mask);
} else if (mode == 2) { // original
}
gl_FragColor = texture_color;
}
+7
View File
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Chroma Key" category="Keying">
<row name="Mode">
<field type="combo" default="0" id="mode">
<option>Composite</option>
<option>Alpha</option>
<option>Original</option>
</field>
</row>
<row name="Key Color">
<field type="color" r="0" g="255" b="0" id="key_color"/>
</row>
+1 -1
View File
@@ -31,7 +31,7 @@ void ColorButton::set_button_color() {
}
void ColorButton::open_dialog() {
QColor new_color = QColorDialog::getColor(color, NULL);
QColor new_color = QColorDialog::getColor(color, NULL, "Set Color");
if (new_color.isValid() && color != new_color) {
set_color(new_color);
set_button_color();