Scaled SpriteAtlas variants bleed into adjacent sprites.

,

When I add sprites to a SpriteAtlas you can add padding of 2/4/8 to avoid bleed between sprites, which works fine. The problem is that my scaled down SpriteAtlas variants pick up on the edge of the adjacent sprite in the packed atlas, because there is no way to add “margin” between the sprites.

Here is an example of two of my packed sprites in my atlas:

6374772--709686--upload_2020-10-2_13-9-21.png

Sprite set on a UI Image from a Sprite Atlas variant of 0.25 scale.

From variant of 1 scale it will look ok, and even a 0.5 scale will not get the edge bleed.
6374772--709695--upload_2020-10-2_13-18-55.png

What we need is an option to define “margins” between the sprites packed in the Atlas, so we don’t get adjacent sprites bleeding into each other when the variant scale is low.

Or if possible the best fix for this issue would be to not scale the packed master spriteatlas, but the actual included sprites itself before repacking them together. This way you would avoid sprites bleeding into adjacent sprites.

Bonus from solving it this way if possible is that you will be able to avoid generating NPOT textures like described here: Sprite Atlas Variant - force POT texture

This is a QoL improvement that would save us many hours of work. Currently we have to add transparent “margin” around our exported images manually, most software for artists/designers do not provide an automatic way to do this - so you end up having to do it manually.

Hey there @tealm ,

Im getting the same thing on Unity 2022.1.5f1.
Did you ever got a solution or created a bug report that I can follow? Thank you!

It’s a while ago, as I mention I just added “margins” in my slices (I use Affinity Designer) before exporting my sprites to PNG. Haven’t heard anything from Unity, but maybe one day they will improve on the sprite-packing of Sprite Atlas variants fixing these kind of errors.

Thank you very much for the answer, and sorry for the bump after two years.

Yeah, I presumed nothing had changed and did the same. Unfortunately that also requires to change the size of the Images RTs to the new assets size in order to conserve the originally intended dimensions, but that is what I did as well.

Cheers!

Hello,
Have you tried disabling Tight Packing as well as increasing the Padding?
More details can be found in the Sprite Atlas documentation if needed

Hello @DanielTanBK thank you for commenting. Yes, we’ve tried that, padding is at 8 and Tight Packing is disabled. Im not entirely convinced that is a classic texture bleeding issue, as the artifacts are produced only when scaling the atlased assets (in our case was downscaling same as op).

The case should be simple to replicate btw.

Hello, after talking with the devs this does not appear to be a bug and is expected.
A common workflow for artists is to have margins in their sprites if they expect some downscaling of their assets, thus our padding is only set to 8 at max for some small corrections.
As the variant atlas’ scale decreases to 0.5 and 0.25, this padding will decrease relatively to 4 and 2 respectively.

Should you really want to have even more padding, you can use the SpriteAtlasPackingSettings.padding API to set a custom value. But this is not recommended as it defeats the purpose of atlas packing if its set to high values

You can refer to this similar post for more info: Sprites have hairline artifacts when using SpriteAtlas and mipmapping - how to fix?

1 Like

Thanks for the replies @DanielTanBK , what you explain is also what I assumed was happening. From my use cases so far it would definitely make more sense to keep the same padding even in scaled variants. That would mean I could set a padding of 2 for my original master atlas, and the variant atlases of 0.5 and 0.25 would still keep the padding of 2. Do you see any use case where you’d want to also scale the padding between sprites?

Another QOL problem I faced is that there is no setting for defining Unity - Scripting API: TextureImporterNPOTScale for sprite atlases. I think a regular sprite atlas is always compressed in POT (power-of-two). But if I remember correctly sprite atlas variants could end up being packed into NPOT textures.

Perhaps it would be possible to force power-of-two sprite atlases being generated through a custom Sprite Packer Policy? Unity - Manual: Sprite Packer

Hello again @DanielTanBK thank you very much for elaborating on the matter. Much appreciated.

Hello, apologies for the late reply but just wanted to let you know that we will take this feedback into consideration for future improvements and changes to Sprite Atlas. Should you also know of other users or areas where such functionality is desired, do let us know so we can accumulate feedback. Thanks!

2 Likes