Search Unity

Object always on top shader

Discussion in 'Shaders' started by ratamorph, Apr 7, 2008.

  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Is there a shader out there that would make a 3D object appear in front of all other 3D objects? I'm not very familiar with writing shaders, but I did tried adding this statements to the default diffuse shader...

    Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off}

    I copied these from the builtin text shader which has this property that I need.

    The object is indeed in front of other objects but you can see trough it. I'm sure I need to do more to the shader but I'm no good at shader programming just yet.

    Any help would be very appreciated.

    Edit: I got rid of all but ZTest Always and now I can only see through my object if there are other objects on front of it.
     
  2. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I'd like to answer my own question now that I figured it out, for something like this it's better to just use an extra camera set it to clear to depth only and set the mask so it only renders the desired objects, then set the camera's depth higher than the your other camera.
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Correct. Well, you answered your own question now :)
     
  4. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Extra points if you tell me now how to render on top of some elements of the GUI but not all.

    }:- )
     
  5. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    To my experience this isn't possible, seems the GUI system always renders on top of everything, I was trying to make a GUI on a cube kinda like the gamecube menu with it, but failed to get the GUI to render to a texture and not the main cam.
     
  6. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    well, Eric5h5 proposed a method using the old GUITexture. I also proposed one using RenderToTexture. We discuss them in this thread:

    http://forum.unity3d.com/viewtopic.php?t=10752

    But neither of them seems too elegant to me. Anyway, I need to give a try to the GUITexture method.

    Un saludo!