Search Unity

Alpha is not transparent

Discussion in 'General Graphics' started by Ben_Iyan, Oct 10, 2018.

  1. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    I have a strange problem that hopefully someone else has seen before. I imported a texture with an alpha channel into Unity (2017.4.12f). When I set Alpha is Transparent to true, the transparent areas become multicolored. The texture looks fine in paint.net, but not in Unity. Any ideas or suggestions? Thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The alpha of an image is just another data channel, like red, green, and blue. By default the alpha has no direct effect on the other color values. Also, any shader not set to be transparent is likely going to ignore the value in the alpha channel of the texture and just show the RGB values. When you check the "Alpha is Transparency" option on the texture, it doesn't change the behavior of the shaders, it's just telling the importer that any RGB value that is fully transparent won't be visible, so the importer modifies the texture to prevent possible fringing from mip mapping and bilinear filtering.

    Short version, if you want the alpha of your texture to be used to make something transparent, you'll need to use a shader that supports transparency.
     
    Solihin100, mmmshuddup and Ben_Iyan like this.
  3. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    Thanks for such a clear explanation. :)
     
  4. VCC_Geek

    VCC_Geek

    Joined:
    Apr 30, 2013
    Posts:
    29
    If you're using the Standard shader, make sure to set the Rendering Mode (the drop list at the very top of the shader panel) to either Fade or Transparent. It's set to Opaque by default. In my experience, Fade tends to work better than Transparent; your mileage may vary.
     
  5. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    Thanks, I'll give that a shot :)
     
  6. unitylearn3d

    unitylearn3d

    Joined:
    Feb 5, 2019
    Posts:
    4
    Hello, sorry to necropost.
    Where is the alpha map supposed to be added for objects that use transparency to fake holes, etc?
    This chair is a single sided poly with holes using alpha. Is it possible? upload_2020-6-20_13-17-33.png
    I also see that the back side is not well rendered even when set to render both.
     
  7. unitylearn3d

    unitylearn3d

    Joined:
    Feb 5, 2019
    Posts:
    4
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    For real time rendering, the alpha isn't a separate map. It's usually stored in the alpha channel of the albedo / base map.
     
  9. unitylearn3d

    unitylearn3d

    Joined:
    Feb 5, 2019
    Posts:
    4
    Thanks. In that chair I used a png for the albedo map. But Unity doesn't seem to be reading the transparency? The holes are not transparent in the chair. :(
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Can you show a screen shot of your texture import settings (including the preview image at the bottom of the inspector where it shows the format), and the entire material settings. The top that you have cutoff in the above example is the most important part.
     
  11. unitylearn3d

    unitylearn3d

    Joined:
    Feb 5, 2019
    Posts:
    4
    I sent a pm. :D
     
  12. ardy_asteria_sp

    ardy_asteria_sp

    Joined:
    Aug 9, 2020
    Posts:
    2
    Thanks to bgolus's reply I was able to understand and fix a similar issue. Sharing in case somebody else does too.

    I was working on my first custom shader that blended two textures: one texture is fully opaque and the other I wanted to use the alpha chanel to get transparency. But the latter wasn't working and the parts of the texture that should've been transparent were opaque.

    I assumed it was a problem with my texture export settings (from image software) or import settings (in unity), and playing with the alpha settings while importing into unity gave me the same issue as the original poster. In the end, it wasn't my export or import settings on the texture that was the problem - it was my shader.

    Originally, I had the respective RGBA outputs from both of the Sample Texture 2D nodes going into the base and blend inputs on the Blend node. But all I needed to do was connect the alpha channel on the texture sample 2D node from the texture I wanted transparency on to the opacity input on the blend node. And it worked. Obvious in hindsight.
     
    Nightkin99 likes this.