// Test-only harness around the real CardStencilFade.cginc.
//
// Same vert + GetCardSurface as the shipping card shaders, but with neutral render
// state (no stencil, no ZTest Equal, no AlphaToMask) so a test can blit it into a
// RenderTexture and count how many pixels survive the dither clip. Every surviving
// fragment writes alpha 1; the test clears to alpha 0 and counts.
//
// Lives under Editor/ so it never ships in a build.

Shader "Hidden/Tests/CardStencilFadeCoverage"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo", 2D) = "white" {}

        _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0

        _MaskFade ("Mask Fade", Range(0,1)) = 1
        _DitherSeed ("Dither Seed", Float) = 201
    }

    SubShader
    {
        Tags { "RenderType" = "Opaque" }

        Cull Off
        Blend Off
        ZWrite Off
        ZTest Always

        // Pass 0: outside every mask volume - pure _Color.a fade
        Pass
        {
            Name "COVERAGE_0"
            Tags { "LightMode" = "ForwardBase" }

            CGPROGRAM

            #define CARD_MASK_LEVEL 0

            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment fragCoverage
            #pragma multi_compile_fwdbase

            #include "../../../Shaders/CardStencilFade.cginc"

            fixed4 fragCoverage(v2f i) : SV_Target
            {
                // The clip under test lives in here
                CardSurface s = GetCardSurface(i);
                return fixed4(1, 1, 1, 1);
            }

            ENDCG
        }

        // Pass 1: first mask shell - _Color.a combined with the volume fade
        Pass
        {
            Name "COVERAGE_1"
            Tags { "LightMode" = "ForwardBase" }

            CGPROGRAM

            #define CARD_MASK_LEVEL 1

            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment fragCoverage
            #pragma multi_compile_fwdbase

            #include "../../../Shaders/CardStencilFade.cginc"

            fixed4 fragCoverage(v2f i) : SV_Target
            {
                CardSurface s = GetCardSurface(i);
                return fixed4(1, 1, 1, 1);
            }

            ENDCG
        }

        // Pass 2: second mask shell
        Pass
        {
            Name "COVERAGE_2"
            Tags { "LightMode" = "ForwardBase" }

            CGPROGRAM

            #define CARD_MASK_LEVEL 2

            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment fragCoverage
            #pragma multi_compile_fwdbase

            #include "../../../Shaders/CardStencilFade.cginc"

            fixed4 fragCoverage(v2f i) : SV_Target
            {
                CardSurface s = GetCardSurface(i);
                return fixed4(1, 1, 1, 1);
            }

            ENDCG
        }
    }

    FallBack Off
}
