diff --git a/crates/rendering/src/shaders/composite-video-frame.wgsl b/crates/rendering/src/shaders/composite-video-frame.wgsl index 147be1963bf..3099daee89b 100644 --- a/crates/rendering/src/shaders/composite-video-frame.wgsl +++ b/crates/rendering/src/shaders/composite-video-frame.wgsl @@ -113,8 +113,32 @@ fn coverage_from_distance(distance: f32, anti_alias_width: f32) -> f32 { fn rounded_rect_coverage(p: vec2, b: vec2, r: f32, rounding_type: f32) -> f32 { let distance = sdf_rounded_rect(p, b, r, rounding_type); - let anti_alias_width = max(fwidth(distance), 1.0); + return rounded_rect_coverage_within(p, b, r, rounding_type, distance, max(fwidth(distance), 1.0)); +} + +// rounded_rect_coverage for the motion blur taps, which run after per-pixel +// returns that leave fwidth undefined: the distance's change over one pixel +// in x and y instead. A pixel changes the distance by at most 1 per axis, so +// at 2 or more from the edge the result is decided without them. +fn rounded_rect_tap_coverage(p: vec2, b: vec2, r: f32, rounding_type: f32) -> f32 { + let distance = sdf_rounded_rect(p, b, r, rounding_type); + if abs(distance) >= 2.0 { + return select(0.0, 1.0, distance < 0.0); + } + let step_x = sdf_rounded_rect(p + vec2(1.0, 0.0), b, r, rounding_type) - distance; + let step_y = sdf_rounded_rect(p + vec2(0.0, 1.0), b, r, rounding_type) - distance; + let anti_alias_width = max(abs(step_x) + abs(step_y), 1.0); + return rounded_rect_coverage_within(p, b, r, rounding_type, distance, anti_alias_width); +} +fn rounded_rect_coverage_within( + p: vec2, + b: vec2, + r: f32, + rounding_type: f32, + distance: f32, + anti_alias_width: f32, +) -> f32 { if distance <= -anti_alias_width { return 1.0; } @@ -779,7 +803,7 @@ fn sample_premultiplied(uv: vec2) -> vec4 { fn apply_rounded_corners(current_color: vec4, target_uv: vec2) -> vec4 { let centered_uv = (target_uv - vec2(0.5)) * uniforms.target_size; let half_size = uniforms.target_size * 0.5; - let coverage = rounded_rect_coverage( + let coverage = rounded_rect_tap_coverage( centered_uv, half_size, corner_radius_for(centered_uv),