How to make Outline Shader draw by Z-Order?

Hi, i use Quick Outline from asset store to draw my 3d gameobject outline, it work, but have some problem, when 2 gameobject collapse each other, collapse area don’t draw outline. I want outline draw by Z-order of gameoject, how can i achieve this?

Shader Code:

Shader "Custom/Outline Fill" {
  Properties {
    [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 0

    _OutlineColor("Outline Color", Color) = (1, 1, 1, 1)
    _OutlineWidth("Outline Width", Range(0, 10)) = 2
  }

  SubShader {
    Tags {
      "Queue" = "Transparent+110"
      "RenderType" = "Transparent"
      "DisableBatching" = "True"
    }

    Pass {
      Name "Fill"
      Cull Off
      ZTest [_ZTest]
      ZWrite Off
      Blend SrcAlpha OneMinusSrcAlpha
      ColorMask RGB

      Stencil {
        Ref 1
        Comp NotEqual
        Pass Replace
      }

      CGPROGRAM
      #include "UnityCG.cginc"

      #pragma vertex vert
      #pragma fragment frag

      struct appdata {
        float4 vertex : POSITION;
        float3 smoothNormal : TEXCOORD3;
        UNITY_VERTEX_INPUT_INSTANCE_ID
      };

      struct v2f {
        float4 position : SV_POSITION;
        fixed4 color : COLOR;
        UNITY_VERTEX_OUTPUT_STEREO
      };

      uniform float _OutlineWidth;
      uniform fixed4 _OutlineColor;

      v2f vert(appdata input) {
        v2f output;

        UNITY_SETUP_INSTANCE_ID(input);
        UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

        float3 viewPosition = UnityObjectToViewPos(input.vertex);
        float3 viewNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, input.smoothNormal));

        output.position = UnityViewToClipPos(viewPosition + viewNormal * -viewPosition.z * _OutlineWidth / 1000.0);
        output.color = _OutlineColor;

        return output;
      }

      fixed4 frag(v2f input) : SV_Target {
        return input.color;
      }
      ENDCG
    }
  }
}

3487810--277669--cube-2.PNG
Normal Outline

3487810--277668--cube-1.PNG
When 2 cube collapse

3487810--277670--cube-13.png
What i want to achieve, outline by Zorder

Remove the stencil bits, and make sure they’re in different Z layers

So i just remove this ?

Stencil {
        Ref 1
        Comp NotEqual
        Pass Replace
      }

I 'm beginner of shader learning so please forgive about stupid question. :smile:

Author support me by modify his code to achieve my goal, feel free to use this by download bellow package.
Support him on: Quick Outline | Particles/Effects | Unity Asset Store

3489226–277818–QuickOutline-PerObject.unitypackage (19.4 KB)

Is there a version of this with the precompute stuff and skinned meshes added? What exactly was changed to fix the zorder stuff?

Did you ever find out? Trying to know what he changed.

Hy, i need to acheive the same result do you have the new code please ?