-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 #15204
base: main
Are you sure you want to change the base?
box shadow #15204
Conversation
…hader and rendering.
If you need a reference, there's linebender/vello#665, although idk if it's suitable for games/is fast or not. |
The generated |
return exp(-(x * x) / (2. * sigma * sigma)) / (sqrt(2. * PI) * sigma); | ||
} | ||
|
||
fn erf(p: vec2<f32>) -> vec2<f32> { |
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.
Comment about what erf is, or a more descriptive name please.
fn erf(p: vec2<f32>) -> vec2<f32> { | ||
let s = sign(p); | ||
let a = abs(p); | ||
var result = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a; |
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.
Comment or constants for these comments please.
pub x_offset: Val, | ||
pub y_offset: Val, | ||
/// Difference in size from occluding uninode | ||
pub x_spread: Val, |
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.
Hmm, I don't like this field name either. It's fine though and I can't think of anything better.
derive(serde::Serialize, serde::Deserialize), | ||
reflect(Serialize, Deserialize) | ||
)] | ||
pub struct BoxShadow { |
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.
Needs doc comments with a brief description and an explanation of how it's used. In particular, I want to know if this goes on my Node component, or as a child, and any limitations.
I'd also like to have a note about what Val
's dimensions are computed relative to.
// The size of the node in pixels. Order is width, height. | ||
@location(2) @interpolate(flat) size: vec2<f32>, | ||
@location(3) @interpolate(flat) size: vec2<f32>, |
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.
Can / should we avoid swapping this by moving the new border_radius
binding to slot 3 rather than displacing size
?
} | ||
|
||
#[derive(Component)] | ||
pub struct UiShadowsBatch { |
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.
Doc strings please
} | ||
|
||
#[derive(Resource)] | ||
pub struct BoxShadowMeta { |
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.
Doc strings for public types :)
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.
Generally looking good: nice example and I'm happy with the scope of this. I have a few cleanup suggestions, and I'd like at least minimal docs for all public types and functions.
Does this work for boxes with transparent backgrounds? (shadow should not render beneath content) |
I read through it, and I agree with the comments by @alice-i-cecile. Other than that, I test-ran this in the browser and on linux and saw no issues. Looking forward to this! |
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.
Was confused about the changes to ui_vertex_output
, but since those have been reverted, looks good to me!
/// Number of shadow samples. | ||
/// A larger value will result in higher quality shadows. | ||
#[derive(Resource, Copy, Clone, Debug, Reflect, ExtractResource)] | ||
pub struct BoxShadowSamples(pub u32); |
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.
This should be camera driven.
Objective
UI box shadow support
Adds a new component
BoxShadow
:To use
BoxShadow
, add the component to any Bevy UI node and a shadow will be drawn beneath that node.Also adds a resource
BoxShadowSamples
that can be used to adjust the shadow quality.Notes
struct Size { width: Val, height: Val }
type or something.prepare_shadows
.Showcase
cargo run --example box_shadow -- --samples 4
cargo run --example box_shadow -- --samples 10