Search Unity

Transparent/Specular material problem

Discussion in 'Shaders' started by kleinfb, Aug 21, 2013.

  1. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Transparent/Specular material problem
    Posted: 02:17 AM 35 Minutes Ago
    Hello guys.

    I am having a hard time figuring out something.. hopefully someone can give me some tips.

    The problem is that I need a GameObject with a specular material to gradually turn invisible.
    For that, I am trying to use Transparent/Specular standard shader. However, I can never make it into a completely opaque object. It does get transparent, even though I set colour to full opacity. On the other hand, if I use the regular Specular material, I get the looks that I want. But I am not able to gradually make it invisible.

    $Screen Shot 2013-08-20 at 11.08.17 PM.png $Screen Shot 2013-08-20 at 11.07.56 PM.png

    So as you can see, one is opaque, the other is transparent, even though Main Color alpha is set to 255.

    I do not intend to write shader code, unless it is strictly necessary.

    Can anyone suggest me a workaround for that?

    Best regards
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use a standard non-transparent shader when it should be opaque, then switch to a transparent shader when you need to fade it out.

    --Eric
     
  3. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Eric.

    As much as this idea looks good, what will happen is that once I do this switching, the object will "pop" into this transparent, giving a rough material switching. I really want to avoid this kind of ugly impressions.
     
  4. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    So my post has been moved?
    Even though it is not directly related to writing shaders?
     
  5. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    You need to move the insides to a separate mesh. For transparent materials, the triangles need to be sorted from back to front to render correctly, but since this is a lot of unnecessary work in most cases (not to mention its not a trivial thing to do), only the meshes are sorted this way.
     
  6. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Dolkar. Thanks for the advice.
    They are all different meshes, actually. The object can assemble/disassemble.

    I am thinking about placing an alpha slide through code on the material shader for the "regular" specular. Anyone think that might be a solution?
     
  7. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Hmm.. anyways, the problem is with the fact that the meshes cant be properly sorted... Oh, I see! They share the same position, so the meshes don't get sorted either! Can't think of a solution on the spot though...
     
  8. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
  9. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Ah, that is great to know, guys! I really appreciate it.

    I will take this opportunity to make another question:
    Is there a way I can get the standard specular shader code, and add an alpha slider to it, via coding? Or would I just get another version of transparent specular shader?
     
  10. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    You can add a slider and name it "Alpha", sure... but it won't to anything. To get it to control transparency, you'd get what is already the transparent specular shader.
     
  11. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Guys... still haven't come across to anything that could actually solve my problem?

    Is it the case that I am trying to achieve something that is not possible with unity (that is, using a specular material and make it turn gradually into invisible, without having z-buffer problems?)
     
  12. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    You should be getting the same problems with any other transparent shader, specular or not. If everything works fine with others, there's something really fishy going on.