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

Adding transparency to a shader?

Discussion in 'Shaders' started by Juice-Tin, Feb 27, 2015.

  1. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Here's what my material looks like with Unlit/Transparent (They are eyelids)


    However, this obviously does not look right when the fact, which is lighted and rimmed.

    When I apply a different face shader, the eyelids dissapear:


    Any idea what needs to be changed in shaders to allow transparency to work properly? Thanks!

    P.S. It seems even Transparent/Diffuse, and other transparent shaders don't display the eyelids either.
     
  2. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Without any shader code from the eyelids or head it's difficult to ascertain what it is. Your magenta head means you have a shader with errors when compiling.
     
  3. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Hey again kebrus! (you've helped me in the past)

    So here's exactly what i've tried to achieve using 4 texture layers (head, pupil, eyelid, mouth). However these only seem to work with Unlit/Transparent.


    Any other lit transparent shader I try to use results in this. (head texture working fine, but none of the transparent textures are displayed, erroring as you said)


    The actual shader I'm trying to use is here:
    http://pastebin.com/9SijERr1

    Also if you don't mind...
    Here's a transparent cape that DOES work with Transparent/Diffuse (oddly the head textures did not).


    However when I use the alpha shader linked above, the cape this time is displayed, but loses all transparency. (the above textures disappeared completely)


    Sorry for the long post, I'm just super confused as to why some textures work differently with some shaders.

    Thanks!
     
  4. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Hello!

    People create shaders for their own needs, there's no point in doing extra calculation inside a shader if you are never going to use the result of that calculation. What i mean is, unity's shaders generally work for most situations because they were create to fit general purposes. That custom shader you have does not and currently it's only outputting any transparency through the _Color parameter.

    One way to fix it would be to change this line
    Code (csharp):
    1. o.Alpha *= _Color.a;
    into this:
    Code (csharp):
    1. o.Alpha *= c.a * _Color.a;
    This will make the alpha from the texture to affect the final alpha besides the _Color parameter. So if you have _Color alpha at zero it's all transparent, but if you have it at max value the transparency is determined by the main texture.

    Unity's Transparent/Diffuse shader should work for you, are you sure you _Color parameter is fully opaque white? Because if color is transparent the final result is transparent too.
     
  5. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    242
    Whoops! Looks like the _Color param was indeed at alpha 0 for some reason.

    Thanks for the info! I'm starting to understand shaders a lot better. Multiplying the texture alpha did in fact fix the material not alpha-ing properly. I found that the texture still wasn't accepting light properly however, but removing UsePass "Transparent/Diffuse/FORWARD" seemed to do the trick.

    Thanks kebrus!
     
    kebrus likes this.