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 does not pad the textures #8150

Closed
GlennFolker opened this issue Mar 21, 2023 · 4 comments · Fixed by #9494
Closed

TextureAtlasBuilder does not pad the textures #8150

GlennFolker opened this issue Mar 21, 2023 · 4 comments · Fixed by #9494
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@GlennFolker
Copy link

GlennFolker commented Mar 21, 2023

Bevy version

0.10.0

Relevant system information

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy
$ uname -r
5.19.0-35-generic
AdapterInfo { name: "Intel(R) HD Graphics 520 (SKL GT2)", vendor: 32902, device: 6422, device_type: IntegratedGpu, driver: "Intel open-source Mesa driver", driver_info: "Mesa 22.2.5", backend: Vulkan }

What I did

  • Enable linear filtering by adding ImagePlugin::default_linear().
  • Pack several textures (that have no "free" borders of clear textures) into an atlas with TextureAtlasBuilder.
  • Draw some stuff with it.
  • There are some stray pixels in the edge of some sprite rectangles.
    image
  • Increase the sprite canvas size allocating a border of transparent pixels to simulate padding, now the stray pixels are gone.
    image

Additional information

This is most likely caused by lack of padding in the atlas texture, causing linear filtering to accidentally sample from other sprites.

@GlennFolker GlennFolker added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 21, 2023
@james7132 james7132 added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 22, 2023
@thetrav
Copy link

thetrav commented Aug 2, 2023

On the flip side of this I've noticed that when using a texture atlas with spacing (which I do for 2d tile map games) and default_nearest, at some zoom levels it picks the border pixels leaving my game with many vertical and horizontal lines.

I read about some artifacts coming out of MSAA however turning it on and off seems to have no impact, pretty sure it's in the texture atlas somewhere.

I'm using bevy 0.11.0 and seeing the same issue in both windows vulcan and wasm

@GlennFolker
Copy link
Author

GlennFolker commented Aug 14, 2023

it picks the border pixels leaving my game with many vertical and horizontal lines.

That's why some people also "bleed" the sprites one or two pixel into the padding. So for example, 4 pixels for padding and 1 pixel for bleeding.

@thetrav
Copy link

thetrav commented Aug 14, 2023

Yes, I guess I could solve it that way. It's probably even possible to write a bit of code that takes the input tile-map (I'm not an artist I'm just using CC free stuff) spaces it out more and just duplicates the pixels on the borders.

Still probably won't look 100% pixel perfect, which makes me a little sad, but will be a lot better than the mesh of flat window background colour. Thanks for the tip.

@ickshonpe
Copy link
Contributor

ickshonpe commented Aug 18, 2023

I have a crate that implements an alternative TextureAtlasBuilder that adds padding:
https://crates.io/crates/bevy_texture_atlas_tools

It hasn't been updated for a while because some changes in 0.10 broke my TextureAtlas crates, 0.11 reversed those changes though. It's really simple and you can probably fork it and update it yourself, or you can wait; I plan to put aside an afternoon next week to update my third-party crates (at least the useful ones).

github-merge-queue bot pushed a commit that referenced this issue Sep 8, 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:
<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>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue 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>
This issue was closed.
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-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants