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

Provide GlobalsUniform in UiMaterial shaders #10739

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

Davier
Copy link
Contributor

@Davier Davier commented Nov 25, 2023

Objective

GlobalsUniform provides the current time to shaders, which is useful for animations. UiMaterial is an abstraction that makes it easier to write custom shaders for UI elements.
This PR makes it possible to use the GlobalsUniform in UiMaterial shaders.

Solution

The GlobalsUniform is bound to @group(0) @binding(1). It is accessible in shaders with:

#import bevy_render::globals::Globals

@group(0) @binding(1)
var<uniform> globals: Globals;

Changelog

Added GlobalsUniform in UiMaterial shaders

Discussion

Should I modify the existing ui_material example to showcase this?

@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Nov 25, 2023
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A simple quality-of-life change that makes Bevy easier to use labels Nov 25, 2023
@robtfm
Copy link
Contributor

robtfm commented Nov 26, 2023

thanks for opening this!

can we please put globals in @group(0) @binding(1), there's no reason to bind a whole extra group. this is also the approach taken for Material and Material2d pipelines, and will fit better when we move to common bindings across these pipelines. it'll also remove the need for any migration for existing users, which is worthwhile when possible.

(there are also performance considerations against using group 2 for globals - rebinding the material group 1 would cause group 2 to be rebound as well)

@Davier
Copy link
Contributor Author

Davier commented Nov 27, 2023

can we please put globals in @group(0) @binding(1), there's no reason to bind a whole extra group

Done, thanks for the great suggestion!

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 27, 2023
@alice-i-cecile
Copy link
Member

@Davier once you resolve the conflicts from #10224 I'll merge this for you <3

@superdump superdump added this pull request to the merge queue Nov 28, 2023
Merged via the queue into bevyengine:main with commit e44b74f Nov 28, 2023
22 checks passed
@Davier Davier deleted the ui_material_globalsuniform branch November 28, 2023 13:58
Davier added a commit to Davier/bevy that referenced this pull request Nov 29, 2023
`GlobalsUniform` provides the current time to shaders, which is useful
for animations. `UiMaterial` is an abstraction that makes it easier to
write custom shaders for UI elements.
This PR makes it possible to use the `GlobalsUniform` in `UiMaterial`
shaders.

The `GlobalsUniform` is bound to `@group(0) @binding(1)`. It is
accessible in shaders with:
```wgsl

@group(0) @binding(1)
var<uniform> globals: Globals;
```

---

Added `GlobalsUniform` in `UiMaterial` shaders

Should I modify the existing ui_material example to showcase this?
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-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants