Skip to content

box-shadow clipping fix #16790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 13, 2024
Merged
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
29 changes: 20 additions & 9 deletions crates/bevy_ui/src/render/box_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl SpecializedRenderPipeline for BoxShadowPipeline {
pub struct ExtractedBoxShadow {
pub stack_index: u32,
pub transform: Mat4,
pub rect: Rect,
pub bounds: Vec2,
pub clip: Option<Rect>,
pub camera_entity: Entity,
pub color: LinearRgba,
Expand Down Expand Up @@ -323,10 +323,7 @@ pub fn extract_shadows(
transform: transform.compute_matrix()
* Mat4::from_translation(offset.extend(0.)),
color: drop_shadow.color.into(),
rect: Rect {
min: Vec2::ZERO,
max: shadow_size + 6. * blur_radius,
},
bounds: shadow_size + 6. * blur_radius,
clip: clip.map(|clip| clip.clip),
camera_entity,
radius,
Expand Down Expand Up @@ -415,9 +412,7 @@ pub fn prepare_shadows(
while item_index < ui_phase.items.len() {
let item = &mut ui_phase.items[item_index];
if let Some(box_shadow) = extracted_shadows.box_shadows.get(item.entity()) {
let uinode_rect = box_shadow.rect;

let rect_size = uinode_rect.size().extend(1.0);
let rect_size = box_shadow.bounds.extend(1.0);

// Specify the corners of the node
let positions = QUAD_VERTEX_POSITIONS
Expand Down Expand Up @@ -479,7 +474,23 @@ pub fn prepare_shadows(
box_shadow.radius.bottom_left,
];

let uvs = [Vec2::ZERO, Vec2::X, Vec2::ONE, Vec2::Y];
let uvs = [
Vec2::new(positions_diff[0].x, positions_diff[0].y),
Vec2::new(
box_shadow.bounds.x + positions_diff[1].x,
positions_diff[1].y,
),
Vec2::new(
box_shadow.bounds.x + positions_diff[2].x,
box_shadow.bounds.y + positions_diff[2].y,
),
Vec2::new(
positions_diff[3].x,
box_shadow.bounds.y + positions_diff[3].y,
),
]
.map(|pos| pos / box_shadow.bounds);

for i in 0..4 {
ui_meta.vertices.push(BoxShadowVertex {
position: positions_clipped[i].into(),
Expand Down
Loading