Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

PackTextures() padding bug?

Discussion in 'Editor & General Support' started by Bugfoot, Sep 8, 2010.

  1. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Im working on a 2D game and made a simple batching system to render my sprites efficiently. I create a texture atlas containing all the sprites that are going to be used in the level being loaded.

    Today I noticed that there was some artifact around the borders of my sprite quads caused by the bilinear filtering on my shadow blobs. I looked at the atlas, and added a 10 pixels padding just to make sure. If you look at the attached screenshot, you'll see that the brown 64x64 square under the red circle is touching the splash sprite above it, while there should be 10 pixels padding (at least that's what I was expecting).

    What is the reason for this? Is the padding just a hint and is not enforced 100%?

    Thanks in advance for any help/hint!
     

    Attached Files:

  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    A project that reproduces the problem plz!
     
  3. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Here you go, fine sir!
    Run the project and select the TextureAtlas object in the scene, and look at the generate Atlas texture.
     

    Attached Files:

  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    It always a problem with the upper-right two textures, for me. Using a padding greater than one pixel, and forcing a resize of the texture by using a smaller maximumAtlasSize than is actually necessary to contain all the graphics, seems to break things apart. That's likely not very helpful to fix the problem for you, but may help squash the bug?
     
  5. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Well the thing kind of fixed itself when I added another sprite, and it made the atlas size increase. Ive also played with resizing some of my sprite graphics, and this no longer happens either with the original texture atlas size. Weird :)
     
  6. codebeans

    codebeans

    Joined:
    Apr 7, 2014
    Posts:
    79
    What you are looking for is probably texture bleeding. Unity uses black to fill out the blank area on the sprite sheet.
    When using filtering you will see these black pixels around the edges.

    The easiest way to fix this is using this technique.
    https://github.com/AlexSTV/uPaddingBleed