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

TextureAtlasBuilder padding #9494

Merged

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Aug 19, 2023

Objective

TextureAtlas supports pregenerated texture atlases with padding, but TextureAtlasBuilder can't add padding when it creates a new atlas.

fixes #8150

Solution

Add a method padding to TextureAtlasBuilder that sets the amount of padding to add around each texture.

When queueing the textures to be copied, add the padding value to the size of each source texture. Then when copying the source textures to the output atlas texture subtract the same padding value from the sizes of the target rects.

unpadded:
texture_atlas_example

padded:
texture_atlas_example_with_padding


Changelog

TextureAtlasBuilder

  • Added support for building texture atlases with padding.
  • Adds a padding method to TextureAtlasBuilder that can be used to set an amount of padding to add between the sprites of the generated texture atlas.

Adds a `padding` method to `TextureAtlasBuilder` that can be used to set an amount of padding to add between the sprites of the generated texture atlas.
@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Aug 19, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once we clarify the docs: the field docs are great, but aren't publicly exposed so it's helpful to repeat them.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Aug 21, 2023

It might also be good to expand the texture atlas builder example in another PR.
We could generate atlases with and without padding and render the textures with and without anti-aliasing to demonstrate how different approaches can deal with bleeding issues etc.

@hymm hymm 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 Sep 8, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 8, 2023
Merged via the queue into bevyengine:main with commit e663d45 Sep 8, 2023
21 checks passed
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

`TextureAtlas` supports pregenerated texture atlases with padding, but
`TextureAtlasBuilder` can't add padding when it creates a new atlas.

fixes bevyengine#8150

## Solution

Add a method `padding` to `TextureAtlasBuilder` that sets the amount of
padding to add around each texture.

When queueing the textures to be copied, add the padding value to the
size of each source texture. Then when copying the source textures to
the output atlas texture subtract the same padding value from the sizes
of the target rects.

unpadded:
<img width="961" alt="texture_atlas_example"
src="https://github.com/bevyengine/bevy/assets/27962798/8cf02442-dc3e-4429-90f1-543bc9270d8b">

padded:
<img width="961" alt="texture_atlas_example_with_padding"
src="https://github.com/bevyengine/bevy/assets/27962798/da347bcc-b083-4650-ba0c-86883853764f">


---

## Changelog
`TextureAtlasBuilder`
* Added support for building texture atlases with padding.
* Adds a `padding` method to `TextureAtlasBuilder` that can be used to
set an amount of padding to add between the sprites of the generated
texture atlas.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
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 C-Usability A targeted 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.

TextureAtlasBuilder does not pad the textures
4 participants