Search Unity

something odd in my silhouette overlay shader

Discussion in 'Shaders' started by glowingboy, Apr 29, 2016.

  1. glowingboy

    glowingboy

    Joined:
    Apr 29, 2016
    Posts:
    2
    here is my code below:
    ----------------------------------------------
    Pass
    {
    Stencil
    {
    Ref[_MaterialID]
    Comp Always
    Pass Replace
    }
    Cull Back
    ZWrite On
    ZTest LEqual
    CGPROGRAM
    #include "UnityCG.cginc"
    #pragma vertex vert
    #pragma fragment frag
    sampler2D _MainTex;
    float4 _Color;
    struct vertexInput
    {
    float4 vertex:pOSITION;
    };
    struct vertexOutput
    {
    float4 pos:SV_POSITION;
    };
    vertexOutput vert(vertexInput input)
    {
    vertexOutput output;

    output.pos = mul(UNITY_MATRIX_MVP, input.vertex);

    return output;
    }
    float4 frag(vertexOutput input):COLOR
    {
    return _Color;
    }
    ENDCG
    }
    Pass
    {
    Stencil
    {
    Ref[_MaterialID]
    Comp NotEqual
    }
    ZWrite On
    ZTest Greater

    CGPROGRAM
    #include "UnityCG.cginc"
    #pragma vertex vert
    #pragma fragment frag
    float4 _OverlayColor;
    struct vertexInput
    {
    float4 vertex:pOSITION;
    };
    float4 vert(vertexInput input):SV_POSITION
    {
    return mul(UNITY_MATRIX_MVP, input.vertex);
    }
    struct fragOutput
    {
    float4 col:COLOR;
    };
    fragOutput frag(void)
    {
    fragOutput o;
    o.col = _OverlayColor;
    return o;
    }
    ENDCG
    }
    ----------------------------------------------
    n.png
    here everything works fine to me
    but, when i add another Empty Pass at the Top, odd things happened.
    the farther object's overlay sillhouette just be replaced by the nearer object
    an.png
    i guss the neaer's 2nd Pass(have added another Empty Pass, so it's 2nd now) happened after the farther's 3rd Pass, as for ZTest Pass, the color replaced
     
  2. glowingboy

    glowingboy

    Joined:
    Apr 29, 2016
    Posts:
    2
    any help would be nice