// Used only by the exporter (TextureWriter) to turn Unity's packed normal maps (DXT5nm / BC5, where the
// normal is stored in the A and G channels) into plain RGB tangent-space normals for glTF.
// UnpackNormal handles both packed and unpacked layouts, so the output is always n * 0.5 + 0.5.
Shader "Hidden/VCam/DecodeNormal"
{
    Properties
    {
        _MainTex ("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
        Cull Off ZWrite Off ZTest Always
        Pass
        {
            CGPROGRAM
            #pragma vertex vert_img
            #pragma fragment frag
            #include "UnityCG.cginc"

            sampler2D _MainTex;

            float4 frag (v2f_img i) : SV_Target
            {
                float3 n = UnpackNormal(tex2D(_MainTex, i.uv));
                return float4(n * 0.5 + 0.5, 1.0);
            }
            ENDCG
        }
    }
}
