// Made by Howe
Shader "URP/Effects/Particle/UVmove_2"
{
	Properties
	{
		[Enum(Addtive,1,Alpha,10)] _BlendMode("BlendMode", Float) = 10
		[Enum(Auto,0,Custom,1)]_AutoSwitch("AutoSwitch", Float) = 1
		[Enum(Auto,0,Custom,1)]_AutoMSwitch("AutoMSwitch", Float) = 1
		_U("U", Float) = 0
		_V("V", Float) = 0
		_UMask("UMask", Float) = 0
		_VMask("VMask", Float) = 0
		[HDR]_MainColor("MainColor", Color) = (1,1,1,1)
		_MainTex("MainTex", 2D) = "white" {}
		_Mask("Mask", 2D) = "white" {}
		_Depth ("Depth", Float ) = 0

	}
	
	SubShader
	{
		
		
		Tags { "RenderType"="Transparent" "Queue"="Transparent" "PreviewType"="Plane" }


		CGINCLUDE
		#pragma target 3.0
		ENDCG
		Blend SrcAlpha [_BlendMode]
		Cull Off
		ColorMask RGBA
		ZWrite Off
		ZTest LEqual
		
		
		
		Pass
		{
			Name "Unlit"
			Tags { "LightMode"="LightweightForward" }
			CGPROGRAM

			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_instancing
			#include "UnityCG.cginc"
			#include "UnityShaderVariables.cginc"
			#ifndef FX_DEPTH_INCLUDED
			#define FX_DEPTH_INCLUDED
			uniform sampler2D _CameraDepthTexture;
			uniform float _Depth;
			half Depth(half4 projPos)
			{
				half sceneZ = max(0,LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(projPos)))) - _ProjectionParams.g);
				half partZ = max(0,projPos.z - _ProjectionParams.g);
				return saturate((sceneZ - partZ) / _Depth);
			}
			#endif


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

			struct v2f
			{
				float4 vertex : SV_POSITION;
				float4 texcoord : TEXCOORD0;	
				float4 texcoord1 : TEXCOORD2;
				float4 color : COLOR;
				float4 projPos : TEXCOORD1;
			};

			uniform sampler2D _MainTex;
			uniform half4 _MainTex_ST;
			uniform half _U;
			uniform half _V;
			uniform half _UMask;
			uniform half _VMask;
			uniform half _AutoSwitch;
			uniform half _AutoMSwitch;
			uniform half4 _MainColor;
			uniform sampler2D _Mask;
			uniform half4 _Mask_ST;

		
			v2f vert(appdata v)
			{
				v2f o;
			
				o.texcoord.xy = v.texcoord.xy;
				o.texcoord1.xy = v.texcoord1.xy;
				o.texcoord1.zw = v.texcoord1.zw;

				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);
				o.projPos = ComputeScreenPos (o.vertex);
                COMPUTE_EYEDEPTH(o.projPos.z);
				return o;
			}


			fixed4 frag(v2f i) : SV_Target
			{
				fixed4 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.texcoord1.xy * float2(1,1) + float2(0,0);
				float2 uv145 = i.texcoord1.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;
				float2 appendResult38 = (float2((_Time.y * _UMask), (_Time.y * _VMask)));
				float2 appendResult53 = (float2((uv_Mask.x + uv145.x), (uv_Mask.y + uv145.y)));
				float2 lerpResult48 = lerp((uv_Mask + appendResult38), appendResult53, _AutoMSwitch);

				finalColor = (tex2D(_MainTex, lerpResult49) * _MainColor * i.color * tex2D(_Mask,lerpResult48).a) *Depth(i.projPos);
				return finalColor;
			}
			ENDCG
		}
	}		
}
