What is the easiest eqvivalent of 1bit size stencil, which works in deferred rendering path?

Hello, I hit the common issue… Stencil and deferred rendering path. I wrote shader it worked, but switching scene to the main with deferred threw my work on that shader into garbage.

What is the most weird thing, is that 5th bit in stencil is unused by unity, so it could somehow be usable with my shaderrs. sadly it seems like, it just ignore the pass at all in deferred rendering path. even if I use comp Always… so if there is a way with stencil. What I am doing wrong?

Shader "StandardBoostedXray"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _MainTex("Albedo", 2D) = "white" {}
    _ColorXray("Color Xray", Color) = (1,0.792,0,1)
    [NoScaleOffset]_MetallicGlossMap("MetallicMap", 2D) = "white" {}
    _Glossiness("Smoothness", float) = 0.5
        _Metallic("Metallic", float) = 0.0
        [NoScaleOffset]_BumpMap("Normal Map", 2D) = "bump" {}
    _BumpScale("Scale NormalMap", Float) = 1.0
        [NoScaleOffset]_OcclusionMap("Occlusion", 2D) = "white" {}
    _OcclusionStrength("Occlusion Strength",float) = 1.0
    }

        SubShader{
        Tags{ "RenderType" = "Opaque"  }//
        LOD 200
        Stencil
    {
        Ref 32
        //IncrSat 32
        Comp always
        Pass replace// IncrSat//
        ZFail keep
    }
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
    #pragma target 3.0

        sampler2D _MainTex,_MetallicGlossMap,_BumpMap,_OcclusionMap;//,_EmissionMap;
    half _Glossiness, _Metallic, _OcclusionStrength, _BumpScale;//,_EmissionColor
    fixed4 _Color, _ColorXray;
    struct Input {
        float2 uv_MainTex;
    };



    void surf(Input IN, inout SurfaceOutputStandard o) {
        fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
        fixed4 m = tex2D(_MetallicGlossMap, IN.uv_MainTex);
        o.Albedo = c.rgb;
        o.Occlusion = tex2D(_OcclusionMap, IN.uv_MainTex)*_OcclusionStrength;
        o.Normal = UnpackScaleNormal(tex2D(_BumpMap, IN.uv_MainTex),_BumpScale);
        o.Metallic = m.a*_Metallic;
        o.Smoothness = _Glossiness*m.rgb;
      
    }
    ENDCG
//    }
  
        Pass
    {
        Tags
    {
        "Queue" = "AlphaTest"//AlphaTest +1
    }
        // Won't draw where it sees ref value 32
        Cull Back // draw front faces
        ZWrite OFF
        ZTest Always
        Stencil
    {
        Ref 32
        Comp NotEqual
        Pass keep
    }
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
        // Properties
        uniform float4 _ColorXray;
//    sampler2D _BumpMap;
    struct vertexInput
    {
        float4 vertex : POSITION;
        float3 normal : NORMAL;
    };

    struct vertexOutput
    {
        float4 pos : SV_POSITION;
        float3 normal : TEXCOORD0;
        float3 viewDirection : POSITION2;

    };

    vertexOutput vert(vertexInput input)
    {
        vertexOutput output;
        output.pos = UnityObjectToClipPos(input.vertex);
        output.normal = normalize(mul(float4(input.normal,0), unity_WorldToObject).xyz);
        output.viewDirection = normalize(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, input.vertex).xyz);
        return output;
    }

    float4 frag(vertexOutput input) : COLOR
    {
    //    float3 norm = UnpackScaleNormal(tex2D(_BumpMap, IN.uv_MainTex),_BumpScale);
        float newOpacity =1.25 -abs(dot(input.viewDirection,  input.normal));
    newOpacity = newOpacity*(newOpacity+0.3)*_ColorXray.a+0.1;
    float4 output = float4(_ColorXray.rgb, newOpacity);
        return output;
    }

        ENDCG
    }
    }
        FallBack "Diffuse"
}

And if there is no way to use stencil in deferred at all (regardless it says there: Unity - Manual: ShaderLab command: Stencil about that 5th bit is unused) What would be the easiest way to throw one bit into GBuffer? I know that RT0.a should not be used… but how I pass that alpha to 0 from surface program, or how I read it in pass I am not aware of… I just need to make some X-ray shader, for not-visible units. Any adwice welcome. Thanks

Oh, wait a second I made it!!! I just had to make unity think that this object is forward, then made second material which remains deferred and it works :open_mouth: Don’t ask… pure magic…