bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.17k stars 3.47k forks source link

TextureAtlasBuilder does not pad the textures #8150

Closed GlennFolker closed 1 year ago

GlennFolker commented 1 year ago

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

Additional information

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

thetrav commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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).