32ae84067503b395ecf6d27d9e90bcf75e5e091f
[movit] / padding_effect.frag
1 uniform vec2 PREFIX(offset);
2 uniform vec2 PREFIX(scale);
3
4 uniform vec2 PREFIX(normalized_coords_to_texels);
5 uniform vec2 PREFIX(offset_bottomleft);
6 uniform vec2 PREFIX(offset_topright);
7
8 vec4 FUNCNAME(vec2 tc) {
9         tc -= PREFIX(offset);
10         tc *= PREFIX(scale);
11
12         vec2 tc_texels = tc * PREFIX(normalized_coords_to_texels);
13         vec2 coverage_bottomleft = clamp(tc_texels + PREFIX(offset_bottomleft), 0.0f, 1.0f);
14         vec2 coverare_topright = clamp(PREFIX(offset_topright) - tc_texels, 0.0f, 1.0f);
15         vec2 coverage_both = coverage_bottomleft * coverare_topright;
16         float coverage = coverage_both.x * coverage_both.y;
17
18         if (coverage <= 0.0f) {
19                 // Short-circuit in case the underlying function is expensive to call.
20                 return PREFIX(border_color);
21         } else {
22                 return mix(PREFIX(border_color), INPUT(tc), coverage);
23         }
24 }