Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Resolved Depth masking in deffered problem

Discussion in 'Shaders' started by PROE_, May 24, 2020.

  1. PROE_


    Feb 20, 2016
    Solved, edit below.

    Hi, I'm creating a building system for my game and I started thinking about placing windows and doors on the walls. And here is the issue, I tried depth masking but it doesn't work for 2500< render queues in Deferred so I lose the shadows and I can't let that happen.

    I get this with render queues above 2500:
    If the render queue is below or equal to 2500, everything renders normally as before applying any shaders.

    And the shader code is:
    Code (CSharp):
    1. SubShader{
    2.         // Render the mask after regular geometry, but before masked geometry and
    3.         // transparent things.
    5.         Tags {"Queue" = "Geometry+1" }
    7.         // Don't draw in the RGBA channels; just the depth buffer
    9.         ColorMask 0
    10.         ZWrite On
    12.         // Do nothing specific in the pass:
    14.         Pass {}
    15.     }
    What are the alternatives to this, possibly in shaders? The last option I have is CSG subtract but this would screw my UV and vertices caching etc.
    Thanks in advance!

    Well, now I learned a few things about shading and now I know why this approach wouldn't work. If anyone ever had the same problem - in built-in pipeline probably the easiest solution to this is to use clip() in the surface shader and add #pragma addshadow :)
    Last edited: Dec 31, 2020