]> git.sesse.net Git - movit/blob - padding_effect.frag
There's no need to #undef PREFIX, since we do the token pasting ourselves.
[movit] / padding_effect.frag
1 // Implicit uniforms:
2 // uniform vec2 PREFIX(offset);
3 // uniform vec2 PREFIX(scale);
4 //
5 // uniform vec2 PREFIX(normalized_coords_to_texels);
6 // uniform vec2 PREFIX(offset_bottomleft);
7 // uniform vec2 PREFIX(offset_topright);
8
9 vec4 FUNCNAME(vec2 tc) {
10         tc -= PREFIX(offset);
11         tc *= PREFIX(scale);
12
13         vec2 tc_texels = tc * PREFIX(normalized_coords_to_texels);
14         vec2 coverage_bottomleft = clamp(tc_texels + PREFIX(offset_bottomleft), 0.0f, 1.0f);
15         vec2 coverage_topright = clamp(PREFIX(offset_topright) - tc_texels, 0.0f, 1.0f);
16         vec2 coverage_both = coverage_bottomleft * coverage_topright;
17         float coverage = coverage_both.x * coverage_both.y;
18
19         if (coverage <= 0.0f) {
20                 // Short-circuit in case the underlying function is expensive to call.
21                 return PREFIX(border_color);
22         } else {
23                 return mix(PREFIX(border_color), INPUT(tc), coverage);
24         }
25 }