Search code examples
unity-game-enginespritetransparencyblending

Unity sprite with white transparent area shows white line at border in scene


I have this sprite here which is part of a character. As you probably can see, it has a white area in the lower middle, which is semi-transparent.

Original

But when placed into a sprite renderer in the scene it suddenly shows this white line where the black contour and the white area meet:

Scene

In the import settings, "Alpha is transparent" is checked. I tried messing with the texture MaxSize, and it made the line thinner but didn't get rid of it. The sprite renderer has material Sprite-Unlit-Default, I also tried Sprite-Default.

How do I get rid of this?

I am using Unity 2019.4.35f1 LTS and URP. The image was created with ClipStudio and exported as PNG to import in Unity. This is the only image with that issue. We have tried re-exporting but no dice.

I have found this related issue: Incorrect white matte behind antialiasing on imported sprites but the solution seems not applicable to my problem.

Thank you!


Solution

  • I took a look at the texture in Unity:

    • The original texture is very big i.e. 3000x5000 with almost being transparent. But actual mouth textures is only about 210x145 pixels small. To avoid scaling issue, the max size would need to be at least 8192 pixel.
    • You should crop the transparency out of the texture, so the texture will only be about 210x145 pixels.

    The actual issue with white pixels can be fixed by using "Point" as "Filter mode" instead of "Bilinear".

    If you want to use "Bilinear" filter mode, you can also scale up the image by 200% to 420x290 pixels in Photoshop (or similar).

    You are having this problem, because with bilinear filtering, the GPU is mixing the between the pixels A (black and opaque) with B (white and almost transparent) to new unwanted color (light gray - half-transparent).

    3 tests with the mouth smile asset

    UPDATE 1:

    You can also configure the Sprite to have the MeshType "Tight" and place the sprite into an SpriteAtlas, then SpriteAtlas Texture size will be 256x256 pixels and Unity will keep the relative position.