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

Standard Shader - Emissive Texture: Alpha Textures Working Sometimes? (Bug?)

Discussion in 'Shaders' started by Xander-Davis, Jul 8, 2017.

  1. Xander-Davis

    Xander-Davis

    Joined:
    Apr 23, 2011
    Posts:
    441
    tldr; Emission Textures, how do?

    I'm having issues with adding an Emissive layer to the Standard Shader. I believe before I used to add a layer with transparency and save as a PNG (of course checking the Alpha is Transparency checkbox on import into Unity which shows up correctly in the preview), so that the non-transparent pixels would be emissive. That didn't work-- the emissive layer renders the alpha pixels in a glitchy way as emission (usually white).

    I tried adding my emissive graphics onto a black background as a flat image, thinking maybe it's on a grayscale setting (black being non-emissive and white being fully emissive). That didn't work either. The emissive layer renders the black as emissive too.

    And yet, I've created materials where PNG transparency does work. Just not all the time. I even tried a TGA with an alpha channel. No help.

    So how can you add an Emissive Texture to the Standard Shader that is ONLY the emissive elements and doesn't cover up the Albedo?
     
    Last edited: Jul 8, 2017
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Sounds like you need to mask part of the albedo with the emissive channel first THEN output that result to emissive. (ie something like emissive.rgb = maintex.a * maintex.rgb)
     
    jojue likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Emission textures should not have an alpha channel. For the standard shader they are just a color texture and an HDR color value multiplied together.

    This likely had more to do with the program you're using to author the PNG than anything in Unity or even anything you drew. The expectation most graphics programs have is that PNG files are going to be used for the web, and as such keeping the file size as small as possible is of utmost importance.

    The way PNG image compression works big blocks of solid colors compress the best, and just because an area of the image is fully transparent doesn't mean there isn't any color data being saved (in fact, there always is). Since for web purposes that color doesn't matter most graphics programs will make it a solid color, or patches of solid colors depending on the colors that remain in the visible parts, whatever it thinks will compress best. So that means sometimes it'll be a solid black, and sometimes a solid white, and sometimes even seemingly random streaks of color.

    Since the Standard shader ignores the alpha, that "unseen" solid color gets used, and when it gets saved as black it "works", when it saves as white it doesn't.

    The "Alpha is Transparency" setting actually exists to work around this for the specific case of alpha blending. If the PNG is saved with black in the completely transparent areas you'll get a black fringe on the edges due to bilinear texture sampling blending from the visible color to that black as it fades out. So it takes the visible color and bleeds it out into the transparent areas. The result is choosing this option is actually possibly making it worse for you as textures that were black in the transparent will no longer be!
     
    Adam_Benko likes this.