Writing to Depth Texture in URP with custom shader

Hi, I’m facing an issue, where I need to read from the depth texture in custom Image effect (with custom Renderer Feature for Blit), but only default Lit opaque material which is renderer with the default Forward Renderer (and not with the Renderer Features) seems to be writing into the depth texture. I even tried to use the custom shader below with no success. Has anyone worked this out? Thanks, Adam

Shader "MaskDepth" {
    Properties { }
    SubShader
    {
        Tags {"RenderType" = "TransparentCutout" "IgnoreProjector" = "True" "Queue" = "Transparent" "RenderPipeline" = "UniversalPipeline"}
        Pass
        {
            Name "DepthOnly"
            Tags{"LightMode" = "DepthOnly"}
            ZWrite On
            ColorMask 0

            HLSLPROGRAM

            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma target 2.0

            #pragma vertex DepthOnlyVertex
            #pragma fragment DepthOnlyFragment

            #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"

            ENDHLSL
        }
    }
    FallBack "Hidden/InternalErrorShader"
}

Edit: I’m using Unity 2019.3.0b4 with URP 7.1.2

Edit 2: “RenderType” = “Opaque” in the custom shader solved my issue

1 Like

I have a similar problem.

My mesh, with Lit material (a modified version of Lit shader), gets processed by my custom depth shader only when the Opaque surface type on the Lit material is selected, but I need to get it processed with transparent option.
Setting the ZWrite option on doesn’t help.

So I got to render it twice, once using colormask 0 opaque shader - thus it now gets into my texture, and then using Render Objects using the transparent shader.