Shader "URP/Effects/Particle/Fresnel"
{
	Properties
	{
		[Enum(Addtive,1,Alpha,10)]_BlendMode("BlendMode", Float) = 10
		[HDR]_TexAColor("TexAColor", Color) = (1,1,1,1)
		_UA("UA", Float) = 0
		_VA("VA", Float) = 0
		_TexA("TexA", 2D) = "white" {}
		[HDR]_TexBColor("TexBColor", Color) = (1,1,1,1)
		_UB("UB", Float) = 0
		_VB("VB", Float) = 0
		_TexB("TexB", 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;
			/*	UNITY_VERTEX_INPUT_INSTANCE_ID*/
				float4 texcoord : TEXCOORD0;
				half3 normal : NORMAL;
			};
			
			struct v2f
			{
				float4 vertex : SV_POSITION;
		/*		#ifdef NEEDS_FRAG_WORLD_POSITION
				float3 worldPos : TEXCOORD0;
				#endif
				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO*/
				float3 worldPos :  TEXCOORD0;
				float4 texcoord1 : TEXCOORD1;
				float4 texcoord2 : TEXCOORD2;
				float4 color : COLOR;
			};

			uniform half _BlendMode;
			uniform half4 _TexAColor;
			uniform sampler2D _TexA;
			uniform half4 _TexA_ST;
			uniform half _UA;
			uniform half _VA;
			uniform sampler2D _TexB;
			uniform half4 _TexB_ST;
			uniform half _UB;
			uniform half _VB;
			uniform half4 _TexBColor;
			uniform half _FresnelPower;
			uniform half4 _FresnelColor;

			
			v2f vert ( appdata v )
			{
				v2f o;
		/*		UNITY_SETUP_INSTANCE_ID(v);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				UNITY_TRANSFER_INSTANCE_ID(v, o);*/

				half3 worldNormal = UnityObjectToWorldNormal(v.normal);
				o.texcoord2.xyz = worldNormal;
				
				o.texcoord1.xy = v.texcoord.xy;
				o.color = v.color;
				o.texcoord1.zw = 0;
				o.texcoord2.w = 0;
				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*/
				v.vertex.xyz += vertexValue;
				o.vertex = UnityObjectToClipPos(v.vertex);

				/*#ifdef NEEDS_FRAG_WORLD_POSITION
				o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				#endif*/
				o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				return o;
			}
			
			fixed4 frag (v2f i ) : SV_Target
			{
				/*UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);*/
				fixed4 finalColor;
			/*	#ifdef NEEDS_FRAG_WORLD_POSITION
				float3 WorldPosition = i.worldPos;
				#endif*/
				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 ) )));
				half2 uv0_TexB = i.texcoord1.xy * _TexB_ST.xy + _TexB_ST.zw;
				half2 appendResult34 = (half2(( uv0_TexB.x + ( _UB * _Time.y ) ) , ( uv0_TexB.y + ( _Time.y * _VB ) )));
				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 );
				
				
				finalColor = ( ( ( ( _TexAColor * tex2D( _TexA, appendResult24 ) ) * ( tex2D( _TexB, appendResult34 ) * _TexBColor ) ) * temp_output_13_0 * i.color.a ) + ( temp_output_13_0 * _FresnelColor ) );
				return finalColor;
			}
			ENDCG
		}
	}	
}
