// Made by Howe
Shader "URP/Effects/UI/UVmove"
{
	Properties
	{
		[Enum(Addtive,1,Alpha,10)] _BlendMode("BlendMode", Float) = 10
		[Enum(Auto,0,Custom,1)]_AutoSwitch("AutoSwitch", Float) = 1

		_ColorMask ("Color Mask", Float) = 15
		_U("U", Float) = 0
		_V("V", Float) = 0
		[HDR]_MainColor("MainColor", Color) = (1,1,1,1)
		_MainTex("MainTex", 2D) = "white" {}
		_Mask("Mask", 2D) = "white" {}
		_StencilComp ("Stencil Comparison", Float) = 8
		_Stencil ("Stencil ID", Float) = 0
		_StencilOp ("Stencil Operation", Float) = 0
		_StencilWriteMask ("Stencil Write Mask", Float) = 255
		_StencilReadMask ("Stencil Read Mask", Float) = 255
		[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
	}
	
	SubShader
	{

		Tags { "RenderType"="Transparent" "Queue"="Transparent" "PreviewType"="Plane" "IgnoreProjector"="True" "CanUseSpriteAtlas"="True" }		
		CGINCLUDE
		#pragma target 3.0
		ENDCG
		Stencil
		{
			Ref [_Stencil]
			Comp [_StencilComp]
			Pass [_StencilOp] 
			ReadMask [_StencilReadMask]
			WriteMask [_StencilWriteMask]
		}
		Blend SrcAlpha [_BlendMode]
		Cull Off
		ColorMask RGBA
		ZWrite Off
		ZTest [unity_GUIZTestMode]

		Pass
		{
			Name "Unlit"
			Tags { "LightMode"="LightweightForward" }				
			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile __ UNITY_UI_ALPHACLIP
			#pragma multi_compile_instancing
			#include "UnityCG.cginc"
			#include "UnityShaderVariables.cginc"


			struct appdata
			{
				float4 vertex : POSITION;
				float4 color : COLOR;
				float4 texcoord : TEXCOORD0;
				float4 texcoord1 : TEXCOORD1;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
				float4 texcoord : TEXCOORD0;
				float4 color : COLOR;
			};

			uniform sampler2D _MainTex;
			uniform float4 _MainTex_ST;
			uniform float _U;
			uniform float _V;
			uniform float _AutoSwitch;
			uniform float4 _MainColor;
			uniform sampler2D _Mask;
			uniform float4 _Mask_ST;


			v2f vert(appdata v)
			{
				v2f o;
			
				o.texcoord.xy = v.texcoord.xy;
				o.texcoord.zw = v.texcoord1.xy;
				o.color = v.color;
				float3 vertexValue = float3(0, 0, 0);
				#if ABSOLUTE_VERTEX_POS
				vertexValue = v.vertex.xyz;
				#endif
				vertexValue = vertexValue;
				#if ABSOLUTE_VERTEX_POS
				v.vertex.xyz = vertexValue;
				#else
				v.vertex.xyz += vertexValue;
				#endif
				o.vertex = UnityObjectToClipPos(v.vertex);
				#ifdef UNITY_HALF_TEXEL_OFFSET
				o.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1) * o.vertex.w;
				#endif
				return o;
			}

			float4 frag(v2f i) : SV_Target
			{
				float4 finalColor;
				float2 uv0_MainTex = i.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;

				float2 appendResult39 = (float2((_Time.y * _U) , (_Time.y * _V)));
				float2 uv146 = i.texcoord.zw * float2(1,1) + float2(0,0);
				float2 appendResult54 = (float2((uv0_MainTex.x + uv146.x) , (uv0_MainTex.y + uv146.y)));
				float2 lerpResult49 = lerp((uv0_MainTex + appendResult39) , appendResult54 , _AutoSwitch);
				float2 uv_Mask = i.texcoord.xy * _Mask_ST.xy + _Mask_ST.zw;

				finalColor = (tex2D(_MainTex, lerpResult49) * _MainColor * i.color * tex2D(_Mask, uv_Mask).a);
				#ifdef UNITY_UI_ALPHACLIP
				clip (finalColor.a - 0.001);
				#endif
				return finalColor;
			}
			ENDCG
		}
	}		
}
