Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions crates/rendering/src/shaders/composite-video-frame.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,32 @@ fn coverage_from_distance(distance: f32, anti_alias_width: f32) -> f32 {

fn rounded_rect_coverage(p: vec2<f32>, b: vec2<f32>, 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<f32>, b: vec2<f32>, 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<f32>(1.0, 0.0), b, r, rounding_type) - distance;
let step_y = sdf_rounded_rect(p + vec2<f32>(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<f32>,
b: vec2<f32>,
r: f32,
rounding_type: f32,
distance: f32,
anti_alias_width: f32,
) -> f32 {
if distance <= -anti_alias_width {
return 1.0;
}
Expand Down Expand Up @@ -779,7 +803,7 @@ fn sample_premultiplied(uv: vec2<f32>) -> vec4<f32> {
fn apply_rounded_corners(current_color: vec4<f32>, target_uv: vec2<f32>) -> vec4<f32> {
let centered_uv = (target_uv - vec2<f32>(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),
Expand Down
Loading