let cmd_min = cmd_rect.position;
let cmd_max = cmd_rect.position + cmd_rect.bound;
- if (all(sample_center >= cmd_min) && all(sample_center <= cmd_max)) {
+ let cmd_min_clipped = max(scissor.offset_min, cmd_min);
+ let cmd_max_clipped = min(scissor.offset_max, cmd_max);
+
+ if (all(sample_center >= cmd_min_clipped) && all(sample_center <= cmd_max_clipped)) {
let border_width = float((cmd.packed_type >> 16) & 0xff);
let border_radii = unpackUnorm4x8ToFloat(cmd_rect.border_radii) * 255.0;
let max_border_radius = max(border_radii.x, max(border_radii.y, max(border_radii.z, border_radii.w)));
let shrink = (2.0 - sqrt(2.0)) * max_border_radius;
let background_color = unpackUnorm4x8ToFloat(cmd_rect.background_color).bgra;
- let cmd_min_clipped = max(scissor.offset_min, cmd_min + border_width + shrink);
- let cmd_max_clipped = min(scissor.offset_max, cmd_max - border_width - shrink);
+ // We calculate a safe region where samples are fully inside
+ // the background. For this region we can just write out the
+ // background color without any sdf evaluation.
+ let cmd_min_safe = max(scissor.offset_min, cmd_min + border_width + shrink);
+ let cmd_max_safe = min(scissor.offset_max, cmd_max - border_width - shrink);
- if (all(sample_center >= cmd_min_clipped) && all(sample_center <= cmd_max_clipped)) {
+ if (all(sample_center >= cmd_min_safe) && all(sample_center <= cmd_max_safe)) {
primitive_color = background_color;
} else {
let b = cmd_rect.bound / 2.0;
let border = lerp(float4(0.0), border_color, alpha_border);
primitive_color = lerp(border, background_color, alpha);
-
- let clip_b = (scissor.offset_max - scissor.offset_min) / 2.0;
- let clip_p = scissor.offset_min + clip_b - sample_center;
- d = max(d, sdf::box(clip_p, clip_b));
- primitive_color = d < 0.0 ? primitive_color : float4(0.0);
}
}
break;