Shader "URP/Effects/Particle/Fresnel_HAlpha"
{
	Properties
	{
		[Enum(Addtive,1,Alpha,10)]_BlendMode("BlendMode", Float) = 10
		_HRange("HRange", Vector) = (1,0,1,0)
		[HDR]_TexAColor("TexAColor", Color) = (1,1,1,1)
		[HDR]_MainColor("MainColor", Color) = (1,1,1,1)
		_UA("UA", Float) = 0
		_VA("VA", Float) = 0
		_MainTex("MainTex", 2D) = "white" {}
		_TexA("TexA", 2D) = "white" {}
		[Header(Fresnel)]
		_FresnelPower("FresnelPower", Float) = 1
		[HDR]_FresnelColor("FresnelColor", Color) = (1,1,1,1)

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

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

			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_instancing
			#include "UnityCG.cginc"
			#include "UnityShaderVariables.cginc"
			#define NEEDS_FRAG_WORLD_POSITION


			struct appdata
			{
				float4 vertex : POSITION;
				float4 color : COLOR;
				float4 texcoord : TEXCOORD0;
				half3 normal : NORMAL;
			};
			
			struct v2f
			{
				float4 vertex : SV_POSITION;
				float3 worldPos :  TEXCOORD0;
				float4 texcoord1 : TEXCOORD1;
				float4 texcoord2 : TEXCOORD2;
				float4 ScenePos : TEXCOORD3;
				float4 color : COLOR;
			};

			uniform half _BlendMode;
			uniform half4 _TexAColor;
			uniform half3 _MainColor;
			uniform sampler2D _MainTex;
			uniform half4 _MainTex_ST;
			uniform sampler2D _TexA;
			uniform half4 _TexA_ST;
			uniform half _UA;
			uniform half _VA;
			uniform half _FresnelPower;
			uniform half4 _FresnelColor;
			uniform half4 _HRange;

			
			v2f vert ( appdata v )
			{
				v2f o;
				half3 worldNormal = UnityObjectToWorldNormal(v.normal);
				o.texcoord2.xyz = worldNormal;
				float3 vertexValue = float3(0, 0, 0);
				v.vertex.xyz += vertexValue;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.ScenePos = ComputeScreenPos (o.vertex);
				o.texcoord1.xy = v.texcoord.xy;
				o.color = v.color;
				o.texcoord1.zw = 0;
				o.texcoord2.w = 0;
				o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				return o;
			}
			
			fixed4 frag (v2f i ) : SV_Target
			{
				fixed4 finalColor;
				half4 MainTex = tex2D(_MainTex, i.ScenePos.xy*_MainTex_ST.xy+_MainTex_ST.zw);
				float3 WorldPosition = i.worldPos;
				half2 uv0_TexA = i.texcoord1.xy * _TexA_ST.xy + _TexA_ST.zw;
				half2 appendResult24 = (half2(( uv0_TexA.x + ( _UA * _Time.y ) ) , ( uv0_TexA.y + ( _Time.y * _VA ) )));
				half3 worldNormal = i.texcoord2.xyz;
				float3 worldViewDir = UnityWorldSpaceViewDir(WorldPosition);
				worldViewDir = normalize(worldViewDir);
				half dotResult8 = dot( worldNormal , worldViewDir );
				half temp_output_13_0 = pow( ( 1.0 - dotResult8 ) , _FresnelPower );
				float3 center = unity_ObjectToWorld._14_24_34;
				finalColor = _TexAColor * tex2D( _TexA, appendResult24 )* temp_output_13_0 * i.color.a + temp_output_13_0 * _FresnelColor;
				finalColor.rgb += MainTex.rgb*_MainColor;
				half HAlpha = saturate((i.worldPos.y-center.y)/_HRange.x);
    			HAlpha = smoothstep(_HRange.y,_HRange.z,HAlpha);
				finalColor.a = HAlpha * i.color.a;
				return finalColor;
			}
			ENDCG
		}
	}	
}
