VR, Post-processing, vertex/frag shader, single pass stereo, instancing, not writing to depth.

Well, it’s just like the title says.

What do you mean it doesn’t make sense?

OK here’s what I’m doing. I’ve got a post-processing effect that draws fog. We’re rendering in forward path, using single-pass stereo. This shader is for drawing instanced meshes, and I recently converted it from a surface shader to a vert/frag shader.

Trouble is, now the instanced meshes don’t seem to be writing to the depth buffer, even though ZWrite is on. Objects that are near to the camera are visible but only if they are in front of some nearby geometry. If they’re in front of something far away, they disappear into the fog. Says to me that they’re not writing to depth.

Surface shaders with the exact same vertex program still work fine in the same situation. I note that the manual says that depth is written in the shadowcaster pass, but my vert/frag shader falls back to diffuse so that should be ok?

Anyone experienced anything like this?

Have you attempted to write a Pass to handle the ShadowCaster pass explicitly?

        Pass
        {
            Name "ShadowCaster"
            Tags{ "LightMode" = "ShadowCaster" }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0
            #pragma multi_compile_shadowcaster
            #include "UnityCG.cginc"

            struct a2v_shadow
            {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };
            struct v2f_shadow
            {
                V2F_SHADOW_CASTER;
            };

            v2f_shadow vert(a2v_shadow v)
            {
                v2f_shadow o;
                TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
                return o;
            }

            float4 frag(v2f_shadow i) : SV_Target
            {
                SHADOW_CASTER_FRAGMENT(i)
            }
            ENDCG
        }