Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Texture formats and alpha

Discussion in 'iOS and tvOS' started by Eyeofgod, Mar 5, 2011.

  1. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Hi there!,

    [Update]: I have made some more tests and seems that the problem is a bit more strange than it looks. The "non power of two" doesn't have anything to do here. The problem is that if you have and image of a size A with alpha channel, and you resize it to B, being B smaller than A, the alpha channel is lost when importing it in Unity (remember, ONLY on PSDs files). The things get weirder: This only happens if you only resizes the image and saves it without doing any other modifications. So, if you change the image size from A to B (being A>B) and save it, the alpha channel is lost. BUT, if you change the size from A to B (being A>B) and make some modifications on the image (whatever change; pain on top, fill a layer, brush, blur...) and then save, the alpha channel is imported into Unity right.


    I have been making some test with the texture formats and I think it will be useful to share the results with the community.
    I started with this because of the grey borders that appear on transparent alpha textures (Im currently working in a 2D game with pixel perfect graphics without the help of sprite manager). The textures import settings are:
    • Filter mode: trilinear
    • Texture type: Advanced
    • Non power of 2: None
    • Generate mip maps: off
    • Texure format: RGBA 32
    Im working with photoshop cs5 and unity 3.2 on Mac.

    So, here are the results:

    PSD
    ------------------
    Power of two without proper alpha channel (only the checkers on photoshop): Grey border.
    Power of two with alpha channel: No grey border.
    Non power of two with alpha channel: No transparency at all (the alpha channel is not imported). It seems to be a bug with this.

    PNG
    ----------------
    Power of two without proper alpha channel (only the checkers on photoshop): Grey border.
    Power of two with alpha channel: No transparency at all (the alpha channel is not imported/exported).
    Non power of two with alpha channel: No transparency at all (the alpha channel is not imported/exported).

    TGA
    ---------------
    Power of two without proper alpha channel (only the checkers on photoshop): Grey border.
    Power of two with alpha channel: No grey border.
    Non power of two with alpha channel: No grey border.

    Note: To get rid of the grey border you have to fill the background with a color similar to your texture outline (in my case they have a cartoonish black border, so the background is black)

    I wish to point again that there is a bug with the non power of two textures and alpha channels when importing PSDs.

    I hope this is useful for somebody.

    Cesar
     
    Last edited: Mar 5, 2011
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I'm also using CS5 on OS X, and have never experienced that bug (using Unity since version 1.6 or so, with Photoshop and Illustrator CS - CS5). I just checked again.

    You can do better:
    http://www.youtube.com/watch?v=sMR_R72bWzw
    http://vimeo.com/8444889
     
  3. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Great tuto Jessy (like the others you have published)!

    I have rebooted the mac, create a new project, new texture, and the bug appears always. I will try to find out why...
     
  4. moctezumagames

    moctezumagames

    Joined:
    Jun 9, 2009
    Posts:
    395

    My experience with Unity just confirms your words. To get best transparency borders always, use TGA with alpha channel, and fill the RGB with perimeter color.
     
  5. kenwong

    kenwong

    Joined:
    Jan 22, 2012
    Posts:
    24
    I just encountered this problem and found this thread - as soon as I saw you mention the 'grey border' I knew what was happening.

    Unity will first try to use the transparency from your Photoshop layers to create the Alpha. Only if the layers are fully opaque (ie the bottom layer has no transparency) will Unity use the Alpha channel. When you resize down the image, if the bottom layer isn't 'flattened', it will picks up a tiny bit of transparency from the trilinear filtering (the pixels outside the image bounds are treated as transparent). Unity uses this tiny border as the alpha, and also fills in the matte color with white. If the edge of your image is dark, then this will come out as grey.

    Solution: just make sure the bottom layer has no transparency after resizing. Then Unity will correctly read the alpha channel.
     
  6. Lukas H

    Lukas H

    Joined:
    Jan 16, 2009
    Posts:
    394
  7. Sibte

    Sibte

    Joined:
    Aug 30, 2012
    Posts:
    1
    I've encountered this same issue just now. I re-sized a PSD file from 1024 to 512 (in Photoshop, not in Unity), and lost the alpha channel. I had a fill layer on the bottom, and an alpha channel with the selections I wanted. However, the materials lost their transparency unless I turned off the fill layer in Photoshopshop and saved again. This was very annoying because that means Unity looked for transparencies in the PSD file and assumed that to be the Alpha Channel, used its default white color as its automatic fill layer, and thus we get those horrible gray outlines.

    I've figured out why the alpha channel was lost (I think). After re-sizing from 1024 to 512, the fill layer at the bottom no longer filled the entirety of the image. it must have been off by only a pixel or so, but that is enough for Unity to assume that there is no fill layer. As a result it will not reference the Alpha Channel, and use its default white background. However, since most of the image was solid from the old fill layer (the one I put in), the image appeared to have no transparency at all.

    I just added a new fill layer, (crt A to select all, then filled that selection with black) and lo and behold, the alpha channel is back! hooray!