HDRP - Custom Pass - Unlit Shader

Hi,

I am using HDRP and made a custom pass which render individual Meshs with a really simple unlit shader. The problem is: I am trying to sample the Depth Buffer, but without success. I am using the follow code:

Shader "Hidden/OutlineObjColor"
{
   
    HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl"
    ENDHLSL
   
    SubShader
    {
        Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue" = "Transparent" }
        Blend SrcAlpha OneMinusSrcAlpha

        Pass
        {

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 4.5
            #include "UnityCG.cginc"
           
            struct interpolators
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float4 projPos : TEXCOORD1;
            };

            float _GlobalOutlineObjColor; //Float to Color the rendered Meshs

            TEXTURE2D_ARRAY(_CameraDepthTexture);
            SAMPLER(sampler_CameraDepthTexture);
           
            v2f vert (interpolators v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.projPos = ComputeScreenPos(o.vertex);
                COMPUTE_EYEDEPTH(o.projPos.z);

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {

                //float objDepth = i.projPos.z;
                float depth = LOAD_TEXTURE2D_ARRAY_LOD(_CameraDepthTexture,i.projPos.xy/i.projPos.w, 0,0);
                //fixed4 col = float4(_GlobalOutlineObjColor,0,0,1);

                return float4(depth,0,0,1); //Test returning just the sampled depthbuffer
            }
            ENDHLSL
        }
    }
}

But what I get in return is just gray, meaning that I am not sampling the DepthBuffer. Tryed for days to solve this by myself. What I am doing wrong?

Hello,

Using functions in “UnityCG.cginc” is not supported in HDRP, because we’re using different variables in shaders than the builtin render pipeline.

Can you try to do the same with the Unlit custom pass renderer shader? You can create a new one with the menu “Assets > Create > Shaders > HDRP Custom Renderers Pass”.
There is also a “positionSS” (position screen space) field that you can use in the PositionInputs struct to do the texture Load operation

1 Like