-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
UI Texture 9 slice #11600
UI Texture 9 slice #11600
Conversation
@alice-i-cecile I think this should go to 0.13 as long as the sprite slices, the UI feature is probably even more useful than the sprite counterpart |
The generated |
2 similar comments
The generated |
The generated |
I agree: the UI equivalent is heavily awaited and I'd like to be able to land both at once. |
@@ -0,0 +1,177 @@ | |||
// This module is mostly copied and pasted from `bevy_sprite::texture_slice` | |||
// | |||
// A more centralized solution should be investigated in the future |
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.
Strongly agree. The API duplication between 2D and UI, and the inconsistencies and delays we get is something that's been on my mind lately.
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.
Tbh most of the code is not duplicated the main components and logic are reused, what is duplicated and adapted is the ComputedTextureSlices
code, so only the cache elements with the sprite/ui specific logic
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.
Anyway in the future we might want to implement slicing directly in the shader
@alice-i-cecile What about the new textures ? Do you think keeping them makes sense or should I only keep the one in use ? |
I like the new textures a lot: I think they clearly demonstrate the value in a more appropriate way. |
Great, but I added the whole pack in the |
Yeah, let's strip it down to only the ones that we use. We can always add more later if we find a use in other examples. |
c4c8176
to
d8b60e0
Compare
Working on giving this a review, I noticed some left over unused system set ordering which seems like it was changed here #5103 (comment) in the Texture Atlas rework. |
could you also add the assets you're adding to https://github.com/bevyengine/bevy/blob/main/CREDITS.md with the direct link to Kenney's pack containing them and their license? |
Sure, currently the license file is in the asset sub folder, so in addition to the credits where should the license file be? |
it's a CC0 license so the license file is not strictly needed, it could be removed. |
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.
I see there is a note to support flipping, but it seems like there is an issue with the default orientation.
It was tricky but I fixed the flipped issue and added flipping support for sliced textures |
@alice-i-cecile Do you know why the CI fails on |
you can't, and it's not blocking for merging (it doesn't have the "required" tag) |
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.
I'm unhappy about the need for a compute_slices_on_asset_event
system, and even worse that it was already added for sprites.
I think 9-slice enabled ui elements and sprites should not be part of the existing bundles but in new bundles, or a "add this component ImageScaleMode
to any entity with an image and it will be sliced/scaled/tiled, otherwise it will be just scaled and nothing fancy will happen"
This has already been added for sprites, so approving here for feature parity
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.
Nice, the flipping works as expected now and the default orientation is correct.
The ordering cleanup also looks 👍
LGTM
This is an optimization to avoid re computing the slices every frames, in a prepare or extract stage. It's not ideal but untile we are able to do slicing on the GPU I don't have a better solution
Since the sprite slicing was not released yet we can remove the scale mode from the sprite and UI bundles, note that in UI it was only added to bundles with a UI image |
Yup, what I'm unhappy about is that any change to an image asset will go through all image (2d or UI) entities, even when you're not using 9 slice at all
I would like that. Do you think we should duplicate all bundles with an added |
Honestly we can just remove those systems, the slices won't refresh if you change the image asset directly but users can be responsible to trigger change detection
I feel we might be adding too many bundles that are basically the same as others with one extra component. |
> Follow up to #11600 and #10588 @mockersf expressed some [valid concerns](#11600 (comment)) about the current system this PR attempts to fix: The `ComputedTextureSlices` reacts to asset change in both `bevy_sprite` and `bevy_ui`, meaning that if the `ImageScaleMode` is inserted by default in the bundles, we will iterate through most 2d items every time an asset is updated. # Solution - `ImageScaleMode` only has two variants: `Sliced` and `Tiled`. I removed the `Stretched` default - `ImageScaleMode` is no longer part of any bundle, but the relevant bundles explain that this additional component can be inserted This way, the *absence* of `ImageScaleMode` means the image will be stretched, and its *presence* will include the entity to the various slicing systems Optional components in bundles would make this more straigthfoward # Additional work Should I add new bundles with the `ImageScaleMode` component ?
# Objective Fixes bevyengine#11944 ## Solution bevyengine#11600 made an incorrect assumption on what `UiImageSize` does, removing its usage in slicing fixes the problem
# Objective Fixes bevyengine#11944 ## Solution bevyengine#11600 made an incorrect assumption on what `UiImageSize` does, removing its usage in slicing fixes the problem
# Objective Follow up to #11600 and #10588 #11944 made clear that some people want to use slicing with texture atlases ## Changelog * Added support for `TextureAtlas` slicing and tiling. `SpriteSheetBundle` and `AtlasImageBundle` can now use `ImageScaleMode` * Added new `ui_texture_atlas_slice` example using a texture sheet <img width="798" alt="Screenshot 2024-02-23 at 11 58 35" src="https://github.com/bevyengine/bevy/assets/26703856/47a8b764-127c-4a06-893f-181703777501"> --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Pablo Reinhardt <[email protected]>
# Objective Follow up to bevyengine#11600 and bevyengine#10588 bevyengine#11944 made clear that some people want to use slicing with texture atlases ## Changelog * Added support for `TextureAtlas` slicing and tiling. `SpriteSheetBundle` and `AtlasImageBundle` can now use `ImageScaleMode` * Added new `ui_texture_atlas_slice` example using a texture sheet <img width="798" alt="Screenshot 2024-02-23 at 11 58 35" src="https://github.com/bevyengine/bevy/assets/26703856/47a8b764-127c-4a06-893f-181703777501"> --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Pablo Reinhardt <[email protected]>
Follow up to bevyengine#11600 and bevyengine#10588 bevyengine#11944 made clear that some people want to use slicing with texture atlases * Added support for `TextureAtlas` slicing and tiling. `SpriteSheetBundle` and `AtlasImageBundle` can now use `ImageScaleMode` * Added new `ui_texture_atlas_slice` example using a texture sheet <img width="798" alt="Screenshot 2024-02-23 at 11 58 35" src="https://github.com/bevyengine/bevy/assets/26703856/47a8b764-127c-4a06-893f-181703777501"> --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Pablo Reinhardt <[email protected]>
Enable Texture slicing for the following UI nodes:
ImageBundle
ButtonBundle
I also added a collection of
fantazy-ui-borders
from Kenney's assets, with the appropriate license (CC).If it's a problem I can use the same textures as the
sprite_slice
exampleWork done
Added the
ImageScaleMode
component to the targetted bundles, most of the logic is directly reused frombevy_sprite
.The only additional internal component is the UI specific
ComputedSlices
, which does the same thing as its spritee equivalent but adapted to UI code.Again the slicing is not compatible with
TextureAtlas
, it's something I need to tackle more deeply in the futureFixes
TextureSlicer::compute_slices
could infinitely loop if the border was larger that the image half extents, now an error is triggered and the texture will fallback to being stretchedflip_x
orflip_y
would give incorrect results, correct flipping is now supported to both sprites and ui image nodes thanks to @odecay observationGPU Alternative
I create a separate branch attempting to implementing 9 slicing and tiling directly through the
ui.wgsl
fragment shader. It works but requires sending more data to the GPU:And more importantly, the actual quad scale which is hard to put in the shader with the current code, so that would be for a later iteration