5 uniform float in_slope;
6 uniform float out_slope;
7 uniform float tolerance;
8 uniform float tolerance_in;
9 uniform float tolerance_out;
13 uniform float min_s_in;
14 uniform float min_s_out;
16 uniform float min_v_in;
17 uniform float min_v_out;
19 uniform float max_v_in;
20 uniform float max_v_out;
21 uniform float spill_distance;
22 uniform float spill_x;
23 uniform float spill_y;
24 uniform float spill_tolerance;
27 uniform bool desaturate_only;
28 uniform float alpha_offset;
29 uniform float hue_key;
30 uniform float saturation_key;
31 uniform float value_key;
35 // shortest distance between 2 hues
36 float hue_distance(float h1, float h2)
38 float result = h1 - h2;
39 if(result < -180.0) result += 360.0;
41 if(result > 180.0) result -= 360.0;
45 // shift H & S based on an X & Y offset
46 void shift_hs(out float h_shifted,
53 float h_rad = radians(h);
54 float x = cos(h_rad) * s;
55 float y = sin(h_rad) * s;
58 h_shifted = degrees(atan(y, x));
59 s_shifted = length(vec2(x, y));
65 vec4 color = texture2D(tex, gl_TexCoord[0].st);
66 /* Contribution to alpha from each component */
74 color2 = yuv_to_rgb(color);
75 color2 = rgb_to_hsv(color2);
80 // shift the color in XY to shift the wedge point
81 float h_shifted, s_shifted;
89 /* Get the difference between the current hue & the hue key */
90 float h_diff = abs(hue_distance(h_shifted, hue_key));
92 // alpha contribution from hue difference
93 // outside wedge < tolerance_out < tolerance_in < inside wedge < tolerance_in < tolerance_out < outside wedge
94 if (tolerance_out > 0.0)
96 // completely inside the wedge
97 if (h_diff < tolerance_in)
100 // between the outer & inner slope
101 if(h_diff < tolerance_out)
102 ah = (h_diff - tolerance_in) / (tolerance_out - tolerance_in);
103 if(ah > 1.0) ah = 1.0;
106 // alpha contribution from saturation
107 // outside wedge < min_s_out < min_s_in < inside wedge
108 if(s_shifted > min_s_out)
110 // saturation with offset applied
111 // completely inside the wedge
112 if(s_shifted > min_s_in)
114 // inside the gradient
115 if(s_shifted >= min_s_out)
116 as = (min_s_in - s_shifted) / (min_s_in - min_s_out);
120 // alpha contribution from brightness range
121 // brightness range is defined by 4 in/out variables
122 // outside wedge < min_v_out < min_v_in < inside wedge < max_v_in < max_v_out < outside wedge
125 if(v < min_v_in || max_v_in >= 1.0)
126 av = (min_v_in - v) / (min_v_in - min_v_out);
132 av = (v - max_v_in) / (max_v_out - max_v_in);
135 // combine the alpha contribution of every component into a single alpha
139 // Spill light processing
140 if(spill_tolerance > 0.0)
142 // get the difference between the shifted input color to the unshifted spill wedge
143 if(spill_distance != 0.0)
158 // Difference between the shifted hue & the unshifted hue key
159 h_diff = hue_distance(h_shifted, hue_key);
162 if(abs(h_diff) < spill_tolerance)
166 // the shifted input color in the unshifted wedge
167 // gives 2 unshifted border colors & the weighting
168 float blend = 0.5 + h_diff / spill_tolerance / 2.0;
169 // shift the 2 border colors to the output wedge
172 shift_hs(min_h_shifted,
180 shift_hs(max_h_shifted,
188 // blend the shifted border colors using the unshifted weighting
189 // the only thing which doesn't restore the key color & doesn't make an edge is
190 // fading the saturation to 0 in the middle
202 else // !desaturate_only
205 // fade the saturation to 0 in the middle
206 s *= abs(h_diff) / spill_tolerance;
210 if(h < 0.0) h += 360.0;
216 color2 = hsv_to_rgb(color2);
217 color.rgb = rgb_to_yuv(color2).rgb;
226 /* Convert mask into image */
227 gl_FragColor = show_mask(color, color2);