-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Texture Atlas rework #5103
Texture Atlas rework #5103
Conversation
I'm satisfied with the state of this. @alice-i-cecile I know you like the enum approach but I think this is way more modular and more ecs friendly as there is one single additional component defining one behaviour. I think this MR is better than #5072 |
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 is nice! I think that this is an uncontroversial improvement to the UX of working with texture atlases.
Given that I expect it to be very rare to swap between ordinary sprites and sprite atlases at run time, I think this approach makes more sense that the enum design you showed before.
I’m probably not going to have any time to review this until later in the week as it seems like I probably also need to look at two other PRs that are proposals? I may have some thoughts about this as I’d like to use a shadow atlas at some point, which is quite dynamic in some senses (updating subregions) but it’s unclear whether that should use the same implementation or a special one, as it is more using a large tiled texture, possibly with various tile sizes, to manage a cache of shadow maps. I dunno. I’ll take a look when I can. |
@superdump this is an alternative to the |
850f6e2
to
a5f0a11
Compare
This breaks the 1-1 relation between the texture atlas and the image, right? We lose the encoding that a texture atlas belongs to a specific image. Makes me a little nervous that people would change the image handle and forget to change the atlas handle, which would be confusing. On the other hand this probably makes it easier to have a large texture atlas that might have different grids on it. Hmm... Ideally we'd encode the dependency of the texture atlas on the image somewhere. But we probably don't want that in the component. Maybe just something to consider when dependent assets gets figured out. I do like that this blurs the line between texture atlas sprites and normal sprites in a very ecs way. i.e. you just need to add a mapping and an index to a normal sprite. |
@hymm I don't think the relationship break is an issue. Overall I think this allows more "ECS friendly" modularity, and more use cases for texture sheets. |
I wouldn't say this problem is necessarily blocking, but this PR introduces a new class of errors that users can make. They can now use the wrong atlas with an image, where before they couldn't do this. In some cases this could lead to significant confusion. Consider a situation where the section of the old texture atlas points at a section of the new image that only has transparent pixels. To the user their sprite will have disappeared and they won't know why. The decreased conceptual difference between sprites and texture atlas sprites and increased flexibility is likely to be worth introducing this new type of error. But I haven't fully formed my opinion on this yet. |
c3b6f29
to
5756075
Compare
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've merged in the relevant new stress test now; would be curious to see the before and after.
@alice-i-cecile rebased on main, I adapted the stress test |
On this branch I get:
And on the main branch I have:
So I don't see much difference, as expected. Maybe I should use stuff described in profiling.md ? |
Looks very close. I'd test out the more advanced traces; if nothing else it's good to get comfortable with those tools. |
Topologically an atlas consists of a set of charts, so maybe TextureChart |
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.
LGTM
I'm fine with the current name, there might be something better but we can rename that later.
I didn't do a super deep review of everything but I tried running everything and overall the approach seems nice.
Co-authored-by: IceSentry <[email protected]>
Merging! |
TextureSlice matches up with 9-slice, which also refers to a piece of a texture. One more alternative is "patch". |
Merge conflicts aren't trivial, but once they're resolved ping me and I'll merge this in for you :) |
@alice-i-cecile done ! The camera driven UI PR had a few conflcits with this |
Pulled locally and the relevant examples work for me :) Merging! |
# Objective #5103 caused a bug where `Sprite::rect` was ignored by the engine. (Did nothing) ## Solution My solution changes the way how Bevy calculates the rect, based on this table: | `atlas_rect` | `Sprite::rect` | Result | |--------------|----------------|------------------------------------------------------| | `None` | `None` | `None` | | `None` | `Some` | `Sprite::rect` | | `Some` | `None` | `atlas_rect` | | `Some` | `Some` | `Sprite::rect` is used, relative to `atlas_rect.min` |
# Objective bevyengine#5103 caused a bug where `Sprite::rect` was ignored by the engine. (Did nothing) ## Solution My solution changes the way how Bevy calculates the rect, based on this table: | `atlas_rect` | `Sprite::rect` | Result | |--------------|----------------|------------------------------------------------------| | `None` | `None` | `None` | | `None` | `Some` | `Sprite::rect` | | `Some` | `None` | `atlas_rect` | | `Some` | `Some` | `Sprite::rect` is used, relative to `atlas_rect.min` |
extract_atlas_uinodes | ||
.in_set(RenderUiSystem::ExtractAtlasNode) | ||
.after(RenderUiSystem::ExtractNode), |
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.
It seems like removing extract_atlas_uinodes
here also means that the ordering constraints referencing RenderUiSystem::ExtractAtlasNode
aren't doing anything since nothing is in that set now. If its no longer needed we should remove it.
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.
Could you make an issue for this?
Objective
Unify sprite management
Solution
Handle<Image>
field inTextureAtlas
which is the main cause for all the boilerplateTextureAtlasSprite
componentTextureAtlas
asset toTextureAtlasLayout
(suggestion)TextureAtlas
component, containing the atlas layout handle and the section indexThe difference between this solution and #5072 is that instead of the
enum
approach is that we can more easily manipulate texture sheets without any breaking changes for classicSpriteBundle
s (@mockersf comment)Also, this approach is more data oriented extracting the
Handle<Image>
and avoiding complex texture atlas manipulations to retrieve the texture in both applicative and engine code.With this method, the only difference between a
SpriteBundle
and aSpriteSheetBundle
is an additional component storing the atlas handle and the index.This solution can be applied tobevy_ui
as well (see #5070).EDIT: I also applied this solution to Bevy UI
Changelog
TextureAtlasSprite
TextureAtlas
toTextureAtlasLayout
SpriteSheetBundle
:Sprite
instead of aTextureAtlasSprite
componenttexture
field containing aHandle<Image>
like theSpriteBundle
TextureAtlas
component instead of aHandle<TextureAtlasLayout>
DynamicTextureAtlasBuilder::add_texture
takes an additional&Handle<Image>
parameterTextureAtlasLayout::from_grid
no longer takes aHandle<Image>
parameterTextureAtlasBuilder::finish
now returns aResult<(TextureAtlasLayout, Handle<Image>), _>
bevy_text
:GlyphAtlasInfo
stores the textureHandle<Image>
FontAtlas
stores the textureHandle<Image>
bevy_ui
:UiAtlasImage
, the atlas bundle is now identical to theImageBundle
with an additionalTextureAtlas
Migration Guide