How do you make weapons not clip through geometry with deferred rendering path?

Hello! I’m used to stacking cameras to make weapons not clip through geometry.

im using deferred rendering on 2021 0b14 and when trying to stack cameras… it says overlay camera cannot be used with deferred rendering

So my question is: How do i make certain objects render ontop of everything else without camera stacking? (easily) Thank you.!

I did in a kind of a non optimal way, but it seems to be working (I’m using BuiltIn RP). The idea is to draw all hand-related meshes first using depth clear shader, which looks like this:

Pass
{
            Name "DEPTH CLEAR"
            Tags { "LightMode" = "DepthClear"}
            ZWrite On
            ZTest Always
            //ColorMask 0

            // This allows to work nicely with skyboxes
            Stencil
            {
                Ref 192
                WriteMask 207
                Comp Always
                Pass Replace
                Fail Keep
                ZFail Keep
            }
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0
            #include "UnityCG.cginc"
    
            float4 vert (float4 vertex : POSITION) : SV_POSITION
            {
                return UnityObjectToClipPos(vertex);
            }
    
            float frag (float4 clipPos : SV_POSITION) : SV_Depth
            {
                #if defined(UNITY_REVERSED_Z)
                    return 0;
                #else
                    return 1;
                #endif
            }
            ENDCG
}

Then make a CommandBuffer, set it to CameraEvent.AfterGBuffer. Draw all of your hand geometry with Graphics.DrawRenderer using this depth-clear shader. Then render all geometry again using their default materials, like so:

foreach (var renderer in renderers)
{
       buffer.DrawRenderer(renderer, m_ClearMaterial, 0, depthClearPassID);
}

 foreach (var renderer in renderers)
 {
     var deferredPassID = renderer.sharedMaterial.FindPass("DEFERRED");
      buffer.DrawRenderer(renderer, renderer.sharedMaterial, 0, deferredPassID);
 }

Except you also shouldn’t turn off original mesh renderers. Otherwise unity won’t update animations on them, so you will techically draw these hands 3 times. But since there are not many meshes, it shouldn’t be a problem.

@thiskidcalledtom you can overlay a forward rendering camera on top of deferred base camera.
I’m interested to hear some thoughts about stacking deferred on top of deferred, we could discuss supporting it.