Shader "Universal Render Pipeline/2D/Spine/Skeleton LitTest"
{
    Properties
    {
        [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
        [NoScaleOffset] _MainColor ("Main Color", Color) = (1,1,1,1)
        [NoScaleOffset] _MaskTex("Mask", 2D) = "white" {}
        _LiuGuang("LiuGuang", 2D) = "white" {}
        _LiuGuangColor ("LiuGuangColor", Color) = (1,1,1,1)
        [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
        [MaterialToggle(_LIGHT_AFFECTS_ADDITIVE)] _LightAffectsAdditive("Light Affects Additive", Float) = 0
        [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
        [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
        _LiuGuangTime("LiuGuangTime", Float) = 0

    }

    HLSLINCLUDE
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    ENDHLSL

    SubShader
    {
        // UniversalPipeline tag is required. If Universal render pipeline is not set in the graphics settings
        // this Subshader will fail.
        Tags
        {
            "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"
        }
        Cull Off
        ZWrite Off

        Stencil
        {
            Ref[_StencilRef]
            Comp[_StencilComp]
            Pass Keep
        }

        Pass
        {
            Tags
            {
                "LightMode" = "Universal2D"
            }

            ZWrite Off
            Cull Off
            Blend One OneMinusSrcAlpha

            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library
            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __
            #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __
            #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __
            #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __
            #pragma multi_compile _ _LIGHT_AFFECTS_ADDITIVE
            #include <HLSLSupport.cginc>

            struct Attributes
            {
                float3 positionOS : POSITION;
                half4 color : COLOR;
                float2 uv : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                half4 color : COLOR0;
                float2 uv : TEXCOORD0;
                float2 lightingUV : TEXCOORD1;
                float2 scenUV : TEXCOORD2;
            };

            // Spine related keywords
            #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
            #pragma vertex CombinedShapeLightVertex
            #pragma fragment CombinedShapeLightFragment

            #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
            #define USE_URP
            #include "../Include/SpineCoreShaders/Spine-Common.cginc"

            TEXTURE2D (_MainTex);
            SAMPLER (sampler_MainTex);
            TEXTURE2D (_MaskTex);
            SAMPLER (sampler_MaskTex);


            float4 _TextrueRect[3];
     

            fixed _GrayFloat;
            float4 _MainColor;
            sampler2D _LiuGuang;
            float4 _LiuGuang_ST;
            float4 _LiuGuangColor;
            float4 _vertextPos;
            float _LiuGuangTime;
            #if USE_SHAPE_LIGHT_TYPE_0
            SHAPE_LIGHT (


            
            0
            )
            #endif

            #if USE_SHAPE_LIGHT_TYPE_1
            SHAPE_LIGHT (


            
            1
            )
            #endif

            #if USE_SHAPE_LIGHT_TYPE_2
            SHAPE_LIGHT (


            
            2
            )
            #endif

            #if USE_SHAPE_LIGHT_TYPE_3
            SHAPE_LIGHT (


            
            3
            )
            #endif


            Varyings CombinedShapeLightVertex(Attributes v)
            {
                Varyings o = (Varyings)0;
                o.positionCS = TransformObjectToHClip(v.positionOS);
                o.uv = v.uv;
                float4 clipVertex = o.positionCS / o.positionCS.w;
                float4 pos = ComputeScreenPos(clipVertex);
                o.scenUV = mul(unity_ObjectToWorld, v.positionOS);
                o.lightingUV = ComputeScreenPos(clipVertex).xy;
                o.color = PMAGammaToTargetSpace(v.color);
                return o;
            }

            #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"

            half4 CombinedShapeLightFragment(Varyings i) : SV_Target
            {
                half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv) * _MainColor;
                #if defined(_STRAIGHT_ALPHA_INPUT)
				tex.rgb *= tex.a;
                #endif

                half4 main = tex * i.color;
                #if !defined(_LIGHT_AFFECTS_ADDITIVE)
                if (i.color.a == 0)
                    return main;
                #endif
                half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);


                SurfaceData2D surfaceData;
                InputData2D inputData;
                surfaceData.albedo = main.rgb;
                surfaceData.alpha = 1;
                surfaceData.mask = mask;
                inputData.uv = i.uv;
                inputData.lightingUV = i.lightingUV;
                half4 color = half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
                float gray = dot(color.rgb, float3(0.299, 0.587, 0.114));
                float3 grayColor = fixed3(gray, gray, gray);
                color.rgb = lerp(color.rgb, grayColor, _GrayFloat);


                float2 pointUV = _TextrueRect[0].xy;
                float2 maxUV = _TextrueRect[0].zw;
                if (i.uv.x > pointUV.x && i.uv.x < maxUV.x && i.uv.y > pointUV.y && i.uv.y < maxUV.y)
                {
                    float2 blUV = (i.scenUV - _vertextPos.xy) / (_vertextPos.zw - _vertextPos.xy);
                    float2 liuGuangUV = blUV - _LiuGuangTime * _LiuGuang_ST.xy + _LiuGuang_ST.zw;
                    liuGuangUV = float2(liuGuangUV.x, liuGuangUV.y);
                    color.rgb += tex2D(_LiuGuang, liuGuangUV).rgb * _LiuGuangColor;
                }

                pointUV = _TextrueRect[1].xy;
                maxUV = _TextrueRect[1].zw;
                if (i.uv.x > pointUV.x && i.uv.x < maxUV.x && i.uv.y > pointUV.y && i.uv.y < maxUV.y)
                {
                    float2 blUV = (i.scenUV - _vertextPos.xy) / (_vertextPos.zw - _vertextPos.xy);
                    float2 liuGuangUV = blUV - _LiuGuangTime * _LiuGuang_ST.xy + _LiuGuang_ST.zw;
                    liuGuangUV = float2(liuGuangUV.x, liuGuangUV.y);
                    color.rgb += tex2D(_LiuGuang, liuGuangUV).rgb * _LiuGuangColor;
                }

                return color;
            }
            ENDHLSL
        }
    }
    FallBack "Universal Render Pipeline/2D/Sprite-Lit-Default"
}