@@ -34,27 +34,28 @@ float do_clip(vec2 pos) {
34
34
float d_bl = distance (pos, ref_bl);
35
35
36
36
float pixels_per_fragment = length (fwidth (pos.xy));
37
- // TODO: compute the `nudge` separately for X and Y
38
37
float nudge = 0.5 * pixels_per_fragment;
38
+ vec4 distances = vec4 (d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;
39
39
40
- bool out0 = pos.x < ref_tl.x && pos.y < ref_tl.y && d_tl > vClipRadius.x - nudge;
41
- bool out1 = pos.x > ref_tr.x && pos.y < ref_tr.y && d_tr > vClipRadius.y - nudge;
42
- bool out2 = pos.x > ref_br.x && pos.y > ref_br.y && d_br > vClipRadius.z - nudge;
43
- bool out3 = pos.x < ref_bl.x && pos.y > ref_bl.y && d_bl > vClipRadius.w - nudge ;
40
+ bvec4 is_out = bvec4 ( pos.x < ref_tl.x && pos.y < ref_tl.y,
41
+ pos.x > ref_tr.x && pos.y < ref_tr.y,
42
+ pos.x > ref_br.x && pos.y > ref_br.y,
43
+ pos.x < ref_bl.x && pos.y > ref_bl.y) ;
44
44
45
- vec4 distances = vec4 (d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;
46
- float distance_from_border = dot (vec4 (out0, out1, out2, out3 ), distances);
45
+ float distance_from_border = dot ( vec4 (is_out),
46
+ max (vec4 (0.0 , 0.0 , 0.0 , 0.0 ), distances) );
47
47
48
48
// Move the distance back into pixels.
49
49
distance_from_border /= pixels_per_fragment;
50
-
51
50
// Apply a more gradual fade out to transparent.
52
51
// distance_from_border -= 0.5;
53
52
54
53
float border_alpha = 1.0 - smoothstep (0.0 , 1.0 , distance_from_border);
55
54
55
+ bool repeat_mask = false; // TODO
56
56
vec2 vMaskUv = (pos - vClipMaskScreenRect.xy) / vClipMaskScreenRect.zw;
57
- vec2 clamped_mask_uv = clamp (vMaskUv, vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
57
+ vec2 clamped_mask_uv = repeat_mask ? fract (vMaskUv) :
58
+ clamp (vMaskUv, vec2 (0.0 , 0.0 ), vec2 (1.0 , 1.0 ));
58
59
vec2 source_uv = clamped_mask_uv * vClipMaskUvRect.zw + vClipMaskUvRect.xy;
59
60
float mask_alpha = texture(sMask, source_uv).r; // careful: texture has type A8
60
61
0 commit comments