Skip to content

Commit 483b23d

Browse files
committed
Minor refactor of do_clip() shader code
1 parent a5d39ff commit 483b23d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

webrender/res/clip_shared.glsl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,28 @@ float do_clip(vec2 pos) {
3434
float d_bl = distance(pos, ref_bl);
3535

3636
float pixels_per_fragment = length(fwidth(pos.xy));
37-
// TODO: compute the `nudge` separately for X and Y
3837
float nudge = 0.5 * pixels_per_fragment;
38+
vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - vClipRadius + nudge;
3939

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);
4444

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));
4747

4848
// Move the distance back into pixels.
4949
distance_from_border /= pixels_per_fragment;
50-
5150
// Apply a more gradual fade out to transparent.
5251
//distance_from_border -= 0.5;
5352

5453
float border_alpha = 1.0 - smoothstep(0.0, 1.0, distance_from_border);
5554

55+
bool repeat_mask = false; //TODO
5656
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));
5859
vec2 source_uv = clamped_mask_uv * vClipMaskUvRect.zw + vClipMaskUvRect.xy;
5960
float mask_alpha = texture(sMask, source_uv).r; //careful: texture has type A8
6061

0 commit comments

Comments
 (0)