Backface is not getting DOF correctly. (GIF and Shader attached)

Hello,

I have this problem where the backface render of the mesh is not getting DOF properly.
The backface is almost getting faded away like a transparent object with a low value of alpha.
7515209--926912--ezgif-1-de86ae8f82ee.gif

I am using Cull Off on a custom surface shader like below.

Shader "Custom/NewSurfaceCullOff"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        Cull Off
        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0
        sampler2D _MainTex;
        struct Input
        {
            float2 uv_MainTex;
        };
        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

I am using PostProcessing Stack v2 with Built-In RP.
Unity 2019.4.29f1.
In order to get DOF properly for the backface, what should I do?

Depth of field uses the camera depth texture, which is a screen space texture that has the depth of the closest opaque object at each pixel. When using forward rendering, this is created by rendering all the visible opaque objects using their shadow caster pass. In the example you have above, the shadow caster pass is coming from the fallback, and the diffuse shader’s shadow caster is one sided.

The solution is to use a custom shadow caster pass rather than one from a fallback. For a Surface Shader you can accomplish this by adding addshadow to the #pragma surface line.

2 Likes

@bgolus Thank you. You saved my life.