Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Invisible Depth Mask

Discussion in 'Shaders' started by briand3d, Feb 10, 2012.

  1. briand3d

    briand3d

    Joined:
    Mar 10, 2011
    Posts:
    14
    I'm working in unity, and trying to get a similar hole, "depth mask," effect to the one posted here.

    http://vimeo.com/25654703

    The ground recedes into the surface of the table. I will basically need to embed an object's surface, like in the video, while hiding any embedded geometry, other than that which is visible from the hole at the top. There is a the wiki depth-mask script

    http://www.unifycommunity.com/wiki/i...itle=DepthMask

    but I cant seem to get the same effect as receding ground. For instance, trying to hide the water in that tutorial, either by removing the mesh-renderer, or by applying an see-though texture, doesn't seem to work.

    How did you go about doing this? Or is there a tutorial I can reference? Any information you could give me would be very much appreciated.

    Thanks,
     
  2. BIG-BUG

    BIG-BUG

    Joined:
    Mar 29, 2009
    Posts:
    457
    Just use a ring of polygons around your geometry you want to hide (red mesh):


    Then apply this simple material to this (red) mesh:

    Code (csharp):
    1. Shader "DepthMask"
    2. {
    3.     SubShader
    4.     {
    5.         Tags {"Queue" = "Geometry-1" }
    6.         Lighting Off
    7.         Pass
    8.         {
    9.             ZWrite On
    10.             ZTest LEqual
    11.             ColorMask 0    
    12.         }
    13.     }
    14. }
    That's it :cool:
     
  3. Jamoke

    Jamoke

    Joined:
    Feb 16, 2012
    Posts:
    2
    I have been trying to find a shader that would mask another item, and I'd been looking for a while. This isn't at all the intended use I had in mind, but it works great for having polygons mask out objects behind them. Thank you!
     
  4. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I'm trying to use this by creating a place, and masking the terrain (creating the appearance of a hole). Is this not usable for that?
    All I get is an invisible plane.

    [Edit]
    But, it works great. Here's a screenshot of a cave a manually put together with planes, under the terrain:




    ok. This only appears to work with Forward rendering. Any idea how to make it happen with Deferred?
     
    Last edited: Mar 21, 2012
  5. BIG-BUG

    BIG-BUG

    Joined:
    Mar 29, 2009
    Posts:
    457
    Modifiying the render queue in Deferred rendering doesn't work like in Forward. I don't know if this is a bug or just a technical limitation with deferred rendering.
    You could try to use a 2nd camera, but I guess this is slower in deferred...
     
  6. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I actually am using a 2nd camera, I wasn't sure how to get it working with just one :) One renders just the cave layer containing the cave, the "Main" camera renders the invisible plane, everything else.

    And it is -significantly- slower...going by the stats window, at least.