Skip to content

Commit

Permalink
Merge pull request iced-rs#2354 from Koranir/custom-shadow-fix
Browse files Browse the repository at this point in the history
Fix quad shadows
  • Loading branch information
hecrj authored Mar 27, 2024
2 parents 1df1cf8 + 39f57a2 commit 5071e3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tiny_skia/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ impl Backend {
),
size,
&radii,
);
)
.max(0.0);
let shadow_alpha = 1.0
- smoothstep(
-shadow.blur_radius * scale_factor,
Expand Down
12 changes: 9 additions & 3 deletions wgpu/src/shader/quad/solid.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,19 @@ fn solid_fs_main(
let quad_color = vec4<f32>(mixed_color.x, mixed_color.y, mixed_color.z, mixed_color.w * radius_alpha);

if input.shadow_color.a > 0.0 {
let shadow_distance = rounded_box_sdf(input.position.xy - input.pos - input.shadow_offset - (input.scale / 2.0), input.scale / 2.0, border_radius);
let shadow_radius = select_border_radius(
input.border_radius,
input.position.xy - input.shadow_offset,
(input.pos + input.scale * 0.5).xy
);
let shadow_distance = max(rounded_box_sdf(input.position.xy - input.pos - input.shadow_offset - (input.scale / 2.0), input.scale / 2.0, shadow_radius), 0.);

let shadow_alpha = 1.0 - smoothstep(-input.shadow_blur_radius, input.shadow_blur_radius, shadow_distance);
let shadow_color = input.shadow_color;
let base_color = select(
let base_color = mix(
vec4<f32>(shadow_color.x, shadow_color.y, shadow_color.z, 0.0),
quad_color,
quad_color.a > 0.0
quad_color.a
);

return mix(base_color, shadow_color, (1.0 - radius_alpha) * shadow_alpha);
Expand Down

0 comments on commit 5071e3d

Please sign in to comment.