-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
box-shadow clipping fix #16790
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw possibly related to this PR, this line looks odd to me:
let positions = QUAD_VERTEX_POSITIONS
.map(|pos| (box_shadow.transform * (pos * rect_size).extend(1.)).xyz());
Shouldn't it be transform + (pos * rect_size)
?
|
Instead of clipping the non-visable sections of box-shadows, the shadow is scaled to fit into the remaining area after clipping because the normalized coordinates that are meant to border the unclipped subsection of the shadow are always set to `[Vec2::ZERO, Vec2::X, Vec2::ONE, Vec2::Y]`, Calculate the coordinates for the corners of the visible area. Test app: ```rust use bevy::color::palettes::css::RED; use bevy::color::palettes::css::WHITE; use bevy::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup(mut commands: Commands) { commands.spawn(Camera2d); commands .spawn(Node { ..Default::default() }) .with_children(|commands| { commands .spawn(( Node { width: Val::Px(100.), height: Val::Px(100.), margin: UiRect { left: Val::Px(100.), top: Val::Px(300.), ..Default::default() }, overflow: Overflow::clip(), ..Default::default() }, BackgroundColor(WHITE.into()), )) .with_children(|commands| { commands.spawn(( Node { position_type: PositionType::Absolute, left: Val::Px(50.), top: Val::Px(50.), width: Val::Px(100.), height: Val::Px(100.), ..Default::default() }, BackgroundColor(RED.into()), BoxShadow::from(ShadowStyle { x_offset: Val::ZERO, y_offset: Val::ZERO, spread_radius: Val::Px(50.), blur_radius: Val::Px(6.), ..Default::default() }), )); }); }); } ``` Main: <img width="103" alt="bad_shadow" src="https://github.com/user-attachments/assets/6f7ade0e-959f-4d18-92e8-903630eb8cd3" /> This PR: <img width="98" alt="clipped_shadow" src="https://github.com/user-attachments/assets/7f576c94-908c-4fe6-abaa-f18fefe05207" />
# Objective Instead of clipping the non-visable sections of box-shadows, the shadow is scaled to fit into the remaining area after clipping because the normalized coordinates that are meant to border the unclipped subsection of the shadow are always set to `[Vec2::ZERO, Vec2::X, Vec2::ONE, Vec2::Y]`, ## Solution Calculate the coordinates for the corners of the visible area. ## Testing Test app: ```rust use bevy::color::palettes::css::RED; use bevy::color::palettes::css::WHITE; use bevy::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup(mut commands: Commands) { commands.spawn(Camera2d); commands .spawn(Node { ..Default::default() }) .with_children(|commands| { commands .spawn(( Node { width: Val::Px(100.), height: Val::Px(100.), margin: UiRect { left: Val::Px(100.), top: Val::Px(300.), ..Default::default() }, overflow: Overflow::clip(), ..Default::default() }, BackgroundColor(WHITE.into()), )) .with_children(|commands| { commands.spawn(( Node { position_type: PositionType::Absolute, left: Val::Px(50.), top: Val::Px(50.), width: Val::Px(100.), height: Val::Px(100.), ..Default::default() }, BackgroundColor(RED.into()), BoxShadow::from(ShadowStyle { x_offset: Val::ZERO, y_offset: Val::ZERO, spread_radius: Val::Px(50.), blur_radius: Val::Px(6.), ..Default::default() }), )); }); }); } ``` Main: <img width="103" alt="bad_shadow" src="https://github.com/user-attachments/assets/6f7ade0e-959f-4d18-92e8-903630eb8cd3" /> This PR: <img width="98" alt="clipped_shadow" src="https://github.com/user-attachments/assets/7f576c94-908c-4fe6-abaa-f18fefe05207" />
Objective
Instead of clipping the non-visable sections of box-shadows, the shadow is scaled to fit into the remaining area after clipping because the normalized coordinates that are meant to border the unclipped subsection of the shadow are always set to
[Vec2::ZERO, Vec2::X, Vec2::ONE, Vec2::Y]
,Solution
Calculate the coordinates for the corners of the visible area.
Testing
Test app:
Main:

This PR:
