Skip to content
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

Merged
merged 53 commits into from
Oct 8, 2024
Merged

box shadow #15204

merged 53 commits into from
Oct 8, 2024

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Sep 14, 2024

Objective

UI box shadow support

Adds a new component BoxShadow:

pub struct BoxShadow {
    /// The shadow's color
    pub color: Color,
    /// Horizontal offset
    pub x_offset: Val,
    /// Vertical offset
    pub y_offset: Val,
    /// Horizontal difference in size from the occluding uninode
    pub spread_radius: Val,
    /// Blurriness of the shadow
    pub blur_radius: Val,
}

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

  • I'm not super happy with the field names. Maybe we need a struct Size { width: Val, height: Val } type or something.
  • The shader isn't very optimised but I don't see that it's too important for now as the number of shadows being rendered is not going to be massive most of the time. I think it's more important to get the API and geometry correct with this PR.
  • I didn't implement an inset property, it's not essential and can easily be added in a follow up.
  • Shadows are only rendered for uinodes, not for images or text.
  • Batching isn't supported, it would need out-of-the-scope-of-this-pr changes to the way the UI handles z-ordering for it to be effective.

Showcase

cargo run --example box_shadow -- --samples 4

br

cargo run --example box_shadow -- --samples 10

s10

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets M-Needs-Release-Note Work that should be called out in the blog due to impact X-Contentious There are nontrivial implications that should be thought through labels Sep 14, 2024
@JMS55
Copy link
Contributor

JMS55 commented Sep 15, 2024

If you need a reference, there's linebender/vello#665, although idk if it's suitable for games/is fast or not.

@alice-i-cecile alice-i-cecile added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Sep 15, 2024
Copy link
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@ickshonpe ickshonpe marked this pull request as ready for review September 16, 2024 13:59
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Oct 8, 2024

Does this work for boxes with transparent backgrounds? (shadow should not render beneath content)

No, atm this is very simple it just draws a shadow below any node with the BoxShadow component, not around the node. It's not difficult to support only drawing around and I agree that it's desirable, but adds a lot of extra complexity to the shader so I'd rather get this basic version merged first and address that in a follow up.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Oct 8, 2024

If you need a reference, there's linebender/vello#665, although idk if it's suitable for games/is fast or not.

I think the approach they are using isn't that different, except it has to fit into their big unified shader. I'm not sure if a unified UI shader would be right for bevy because game UI tends to be much more diverse etc.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 8, 2024
@alice-i-cecile alice-i-cecile added the C-Feature A new feature, making something new possible label Oct 8, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 8, 2024
Merged via the queue into bevyengine:main with commit 99b9a2f Oct 8, 2024
30 checks passed
@alice-i-cecile
Copy link
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1721 if you'd like to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Shaders This code uses GPU shader languages M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants