Search Unity

LWRP and masking shaders with AR Foundation

Discussion in 'AR' started by virtualHCIT, Feb 22, 2019.

  1. virtualHCIT

    virtualHCIT

    Joined:
    Aug 20, 2018
    Posts:
    13
    Hello,

    I was wondering if anyone knows of a masking shader that works with LWRP and AR Foundation (at least with ARKit)? With the standard Unity renderer, we were able to use Vuforia's DepthMask shader for masking (hiding objects behind invisible geometry). This doesn't work anymore:

    Code (CSharp):
    1. Shader "DepthMask" {
    2.  
    3.     SubShader {
    4.         // Render the mask after regular geometry, but before masked geometry and
    5.         // transparent things.
    6.      
    7.         Tags {"Queue" = "Geometry-10" }
    8.      
    9.         // Turn off lighting, because it's expensive and the thing is supposed to be
    10.         // invisible anyway.
    11.      
    12.         Lighting Off
    13.  
    14.         // Draw into the depth buffer in the usual way.  This is probably the default,
    15.         // but it doesn't hurt to be explicit.
    16.  
    17.         ZTest Always
    18.         ZWrite On
    19.  
    20.         // Don't draw anything into the RGBA channels. This is an undocumented
    21.         // argument to ColorMask which lets us avoid writing to anything except
    22.         // the depth buffer.
    23.  
    24.         ColorMask 0
    25.  
    26.         // Do nothing specific in the pass:
    27.  
    28.         Pass {}
    29.     }
    30. }
     
  2. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    904
  3. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    110
    Hi @steego could you please give some guidance how to remove the occlusion feature in your shader? In the case of a hole in the ground I don't want to occlude the part under the plane.

    Thanks a bunch !
     
  4. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    904
    It's a bit more complicated that, you can have a look at this page in the docs https://docs.unity3d.com/Manual/SL-CullAndDepth.html -- see the section named "Transparent shader with depth writes".

    Basically you would have two passes, one that only writes depth where you want culling, and one with a modified version of my shader that doesn't write depth. I think that should do it for you.
     
  5. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    110
    @steego Yay, not straight forward indeed for a newbie in shaders, defo will try :)

    Thanks a bunch !