Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Depth Mask Shader in URP

Discussion in 'Shader Graph' started by charles_xl, Mar 27, 2020.

  1. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    Hey all,

    I’m trying to recreate the depth effect shown in the video
    - and essentially cut fake holes into geometry without modifying the mesh. I’m trying to do this in URP without luck, has this been achieved before? Is this something that isn’t possible with Shader Graph yet?

    Anything to steer me in the right direction would be extremely helpful!
     
  2. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    need to make sure URP is generating depth textures, otherwise I dont see any reason that it wouldnt work
    upload_2020-3-27_13-36-25.png
     
  3. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    I will try that, thanks for the quick response!
     
    Elizabeth_LeGros likes this.
  4. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    Hey @Elizabeth_LeGros - I'm a bit new to Shader Graph (and shaders in general). The idea is that anything where the depth mask is should basically just render transparent. In my attached screenshot - the hope is the center of the torus is transparent. Any idea how to achieve this effect or available resources to do so? Thank you!
     

    Attached Files:

  5. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    I mean you can set the alpha of the center to 0 or modify the mesh to just have no center but I am a bit confused what you are trying to accomplish here; could you explain what the desired effect is? If you want to create a similar effect to quill's then making the center transparent wont achieve that
     
  6. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    The desired effect is I want to be able to have geometries pass through the center of the torus (or any shape that the depth mask creates). Think Hole in the Wall. The idea being that the actual mesh has to be created with the holes, but rather prefabs for different shapes can be placed at runtime on a surface. Hope that’s helpful, appreciate your help!
     
  7. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    Are you saying that wherever the torus defines a "hole" you should be able to see through the attached mesh as though it were transparent?
     
  8. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    Yes exactly!
     
  9. Elizabeth_LeGros

    Elizabeth_LeGros

    Unity Technologies

    Joined:
    Jan 7, 2020
    Posts:
    50
    Cool idea that is very much not possible in shadergraph. There might be other ways to achieve this effect but would likely take both c# code and some clever shadergraphs with maybe some hlsl thrown on top.
    It may be easier to achieve this effect by having the attached mesh have a shadergraph marked as transparent, and modify the alpha based on distance to a point in worldspace, and then use c# to attach the position of your torus to the material worldspace point
     
    florianhanke likes this.
  10. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    74
    Oh that’s an interesting idea! I guess depending on the shape of the transparent parts it would require different shaders. ie one for a circle, one for a rectangle etc. I think I would also need different material instances, basically one per each transparent section I wanted on the surface. Will give it a shot this weekend, thanks a bunch for the tips
     
    Elizabeth_LeGros likes this.
  11. paul_meynckens

    paul_meynckens

    Joined:
    Nov 30, 2019
    Posts:
    4
    @Elizabeth_LeGros. I used the same method described in the video above to make holes in walls. It worked very well with the built-in render pipeline. But now, I a using URP, the depth mask is hiding the skybox even if the skybox is drawn before the depth mask in the render queue. Skybox queue is 1000(background) and the depth mask is at 1999(geometry-1.)

    depth mask.jpg

    In both cases, the depth mask uses the same shader as described here : https://wiki.unity3d.com/index.php/DepthMask exepted that my mask queue is at geometry-1.

    How can I fix this issue?
     
    Last edited: May 28, 2020
    juan-jo likes this.
  12. Strodio

    Strodio

    Joined:
    Oct 20, 2018
    Posts:
    4
    I have the same problem, wait for a solution
     
  13. andyasj

    andyasj

    Joined:
    Nov 23, 2016
    Posts:
    14
    I simply used this shader (which I believe is the one you linked to) and set the 'Priority' of the object to be masked as 20.
    Code (csharp):
    1. Shader "Custom/DepthMask"
    2. {
    3.     SubShader{
    4.         // Render the mask after regular geometry, but before masked geometry and
    5.         // transparent things.
    6.         Tags {"Queue" = "Geometry+10" }
    7.  
    8.         // Don't draw in the RGBA channels; just the depth buffer
    9.         ColorMask 0
    10.         ZWrite On
    11.  
    12.         // Do nothing specific in the pass:
    13.         Pass {}
    14.     }
    15. }
    16.  
    It seems to work fine.
     
  14. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    97
    Anybody have any idea how I make this work for HDRP?
     
unityunity