Shader "URP/Effects/Particle/ScreenSpaceDetail"
{
	Properties
	{
		[HDR]_Color("Color", Color) = (0.5,0.5,0.5,0.5)
		_MainTex("MainTex", 2D) = "white" {}
		_Tiling("Tiling", Vector) = (1,1,0,0)
		_MainTexUSpeed("MainTex U Speed", Float) = 0
		_MainTexVSpeed("MainTex V Speed", Float) = 0
		[HDR]_FresnelColor("Fresnel Color", Color) = (0.5,0.5,0.5,0.5)
		_FresnelScale("Fresnel Scale", Float) = 1
		_FresnelPower("Fresnel Power", Float) = 1
		_FlashTime("FlashTime", Float) = 1
		_FlashStrength("FlashStrength", Range(0,1)) = 0
	}

	SubShader
	{
		Tags{ "RenderType" = "Transparent"  "Queue" = "Transparent" "IsEmissive" = "true"  }
		Cull Back
		Blend SrcAlpha OneMinusSrcAlpha , SrcAlpha OneMinusSrcAlpha
		
		Pass
		{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		#pragma target 3.0
		#include "UnityCG.cginc"
		float4 _Color;
		sampler2D _MainTex;
		float2 _Tiling;
		float _MainTexUSpeed;
		float _MainTexVSpeed;
		float4 _FresnelColor;
		float _FresnelScale;
		float _FresnelPower;
		float _FlashTime,_FlashStrength;
		struct appdata
		{
			float4 vertex : POSITION;
			float4 color : COLOR;
			half3 normal : NORMAL;
		};
		struct v2f
		{
			float4 vertex : SV_POSITION;
			float3 worldPos : TEXCOORD0;
			float4 screenPos : TEXCOORD1;
			float3 worldNormal : TEXCOORD2;
			float4 vertexColor : COLOR;
		};
		v2f vert ( appdata v )
		{
			v2f o;
			o.vertex = UnityObjectToClipPos(v.vertex);
			o.screenPos = ComputeScreenPos (o.vertex);
			o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
			o.worldNormal = UnityObjectToWorldNormal(v.normal);
			o.vertexColor = v.color;
			return o;
		}
		fixed4 frag (v2f i ) : SV_Target
		{
			half4 c = 0;
			float2 appendResult = (float2(_MainTexUSpeed , _MainTexVSpeed));
			float4 screenPos = float4( i.screenPos.xyz , i.screenPos.w);
			float4 screenPosNor = screenPos / screenPos.w;
			screenPosNor.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? screenPosNor.z : screenPosNor.z * 0.5 + 0.5;
			float4 tex2DNode1 = tex2D( _MainTex, ( ( _Time.y * appendResult ) + ( (screenPosNor).xy * _Tiling ) ) );
			float3 worldPos = i.worldPos;
			float3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
			float3 worldNormal = i.worldNormal;
			float fresnelNdotV11 = dot( worldNormal, worldViewDir );
			float fresnelNode11 = ( 0.0 + _FresnelScale * pow( 1.0 - fresnelNdotV11, _FresnelPower ) );
			c.rgb = ( ( i.vertexColor * _Color * tex2DNode1 ) + ( _FresnelColor * fresnelNode11 ) ).rgb;
			half Flash = abs(( (sin((_Time.y*_FlashTime)) + 1.0) / 2.0))* _FlashStrength;
			c.a = ( i.vertexColor.a * _Color.a * tex2DNode1.a )*fresnelNode11;
			c.a = lerp(c.a,0,Flash);
			return c;
		}
		ENDCG
		}
	}
}