Shader "URP/Effects/Transparent-Simple-Shadow" {
	Properties {
		_Color ("Color", Color) = (1, 1, 1, 1)
		_Intensity("Intensity", Float) = 1
		_BaseMap ("Base (RGB)", 2D) = "white" {}
		[Enum(Off,0,On,1)]_ZWrite("ZWrite", Float) = 1
		[Enum(Both,0,Back,2)] _Cull("Cull Mode", int) = 2 
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
		_env_shadow_color ("Shadow Color", Color) = (0.5, 0.5, 0.5, 1)
		[Header(Wind)]
		[Toggle(_USE_Wind)]_UseWind("Wind",Float) = 0
		_echoRNormal("R Wind Bending Direction", Vector) = (1, 0, 1, 0)
		_echoRSpeed("R Tumbling Speed", Range(0.0, 50.0)) = 20.0
		_echoRHeight("R Tumbling Height", Range(0.0, 0.7)) = 0.35
		_echoRAmount("R Tumbling Amount", Range(1.0, 10)) = 5.0
		[ToggleOff]_Receive_Shadows("Receive Shadows", Float) = 1.0
		[Toggle]_SHADOW_SWITCH("云影", Float) = 1.0
		//_LM_Strength("LM Strength", Range(0,1)) = 0
		//_SM_Strength("SM Strength", Range(0, 1)) = 0
		[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
		//[ToggleOff]_VColor("VColor",Float) = 0
		//[Toggle(_Fog)]_Fog("Fog",Float) = 1
	}

	SubShader {
		Tags { "RenderType"="TransparentCutout" "Queue"="AlphaTest" "RenderPipeline" = "UniversalPipeline"}
		LOD 200

		HLSLINCLUDE
		#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
		#include "../Common/Template Shader/Define.hlsl"
		#include "../Common/Function/Scene_Common.hlsl"
		#include "../Common/Function/BlackHole.hlsl"
		#include "../Environment/Sky&Fog/VolumetricFogForObject.hlsl"

		ENDHLSL
		Pass
		{
			Tags{"LightMode" = "UniversalForward"}
			//Blend SrcAlpha OneMinusSrcAlpha
			ZWrite[_ZWrite]
			Cull[_Cull]
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			//#pragma shader_feature _Fog
			//#pragma multi_compile_fog
			#pragma shader_feature _USE_Wind
			#pragma multi_compile _ LIGHTMAP_ON
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
			#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
			#pragma multi_compile _ SHADOWS_SHADOWMASK
			#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
			#pragma multi_compile _ DIRLIGHTMAP_COMBINED
			#pragma multi_compile _ _SHADOWS_SOFT
			#pragma shader_feature _RECEIVE_SHADOWS_OFF
			#pragma multi_compile_instancing

			uniform half4 _env_shadow_color;
			uniform half3 _Color;
			uniform half _VColor;
			uniform half _Intensity;
			#ifdef _USE_Wind
			uniform half4 _echoRNormal;		
			uniform half _echoRSpeed;
			uniform half _echoRHeight;
			uniform half _echoRAmount;
			uniform half _echoRCenterX;
			uniform half _echoRCenterY;
			#endif

			//uniform half _SceneBloomFactor;

			struct v2f 
			{
				float4 pos : SV_POSITION;
				float2 texcoord : TEXCOORD0;
				float4 fogCoord : TEXCOORD1;
				float3 positionWS :TEXCOORD2;
				half3 normalWS   : TEXCOORD3;
				float4 color : COLOR;
				DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 4);

				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO
			};
			#include "../Common/Function/Lightmap_Output.hlsl"
			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
				half2 lightmapUV   : TEXCOORD1;
				half3 normal : NORMAL;
				float4 color : COLOR;
				UNITY_VERTEX_INPUT_INSTANCE_ID
			};

			v2f vert(appdata v)
			{
				v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_TRANSFER_INSTANCE_ID(v, o);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				#ifdef _USE_Wind
				half ripple;
				ripple 			= EchoRipple ( v.uv, _echoRAmount, _echoRSpeed * (1.1 - (v.color.rgb/2)), _echoRHeight * v.color.rgb, 0, 0 );
				v.vertex.xyz 	=  v.vertex.xyz + ( half3(ripple,ripple,ripple) * _echoRNormal.xyz );
				#endif
				VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
				o.pos = vertexInput.positionCS;
				//o.fogCoord = vertexInput.positionCS.z;
				o.fogCoord = VolumetricFog_GetFogCoord(vertexInput.positionNDC, vertexInput.positionVS.z);
				o.texcoord = TRANSFORM_TEX(v.uv, _BaseMap);
				o.positionWS = vertexInput.positionWS;
				o.normalWS = normalize(v.normal);
				OUTPUT_LIGHTMAP_UV(v.lightmapUV, unity_LightmapST, o.lightmapUV);
				OUTPUT_SH(v.normal.xyz, o.vertexSH);
				o.color = v.color;
				return o;
			}

			half4 frag(v2f i) : SV_Target
			{
				UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
				half4 col = SampleAlbedoAlpha(i.texcoord, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
				clip(col.a- _Cutoff);
				Light light = MainLight(i.positionWS);
				//half3 ENV = UNITY_LIGHTMODEL_AMBIENT.rgb;
				// half3 bakedGI = SAMPLE_GI(i.lightmapUV, i.vertexSH, i.normal);;
				// #ifdef LIGHTMAP_ON
				// LightmapResult(light,bakedGI,i.positionWS,i.lightmapUV,i.normal);
				// #endif
				half3 bakedGI;
				LightmapResult(light,i,bakedGI,i.normalWS,i.positionWS.xyz);
				half4 posW = VertCalaShadow(half4(i.positionWS,0), _DirX, _DirY);
				light.shadowAttenuation =FragCalaShadowAtten(light.shadowAttenuation, posW, _Time.x, _Speed, _ShadowAlphaRatio, _ShadowTex);
				half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
				half3 diffuseColor = bakedGI + LightingLambert(attenuatedLightColor, light.direction, i.normalWS);
				col.rgb *= diffuseColor*_Color*_Intensity;
				//col.rgb *= _MainLightColor.w;
				col.rgb *= BalckHole_GetLightIntensity(i.positionWS.xyz);
				//#ifdef _Fog
				//half density = ComputeFogFactor(i.fogCoord);
				//col.rgb = MixFog(col.rgb, density);
				//col.rgb = VolumetricFog_GetFog(col.rgb, i.fogCoord);
				//#endif
				//col.a = _SceneBloomFactor;

				return col;
			}

			ENDHLSL
		}

	Pass{
			// use for pc
			Name"DepthOnly"
			Tags{"LightMode" = "DepthOnly"}
		
			ZWrite[_ZWrite]
			Cull[_Cull]
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma shader_feature _Fog
			#pragma multi_compile_fog
			#pragma shader_feature _USE_Wind
			#pragma multi_compile _ LIGHTMAP_ON
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
			#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
			#pragma multi_compile _ SHADOWS_SHADOWMASK
			#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
			#pragma multi_compile _ DIRLIGHTMAP_COMBINED
			#pragma multi_compile _ _SHADOWS_SOFT
			#pragma shader_feature _RECEIVE_SHADOWS_OFF
			#pragma multi_compile_instancing

			uniform half4 _env_shadow_color;
			uniform half3 _Color;
			uniform half _VColor;
			uniform half _Intensity;
			#ifdef _USE_Wind
						uniform half4 _echoRNormal;		
						uniform half _echoRSpeed;
						uniform half _echoRHeight;
						uniform half _echoRAmount;
						uniform half _echoRCenterX;
						uniform half _echoRCenterY;
			#endif

			uniform half _SceneBloomFactor;

			struct v2f
			{
				float4 pos : SV_POSITION;
				float2 texcoord : TEXCOORD0;
				float3 positionWS : TEXCOORD2;
				DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 4);

				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO
			};
			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
				float4 color : COLOR;
				UNITY_VERTEX_INPUT_INSTANCE_ID
			};

			v2f vert(appdata v)
			{
				v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_TRANSFER_INSTANCE_ID(v, o);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				#ifdef _USE_Wind
					half ripple;
					ripple 			= EchoRipple ( v.uv, _echoRAmount, _echoRSpeed * (1.1 - (v.color.rgb/2)), _echoRHeight * v.color.rgb, 0, 0 );
					v.vertex.xyz 	=  v.vertex.xyz + ( half3(ripple,ripple,ripple) * _echoRNormal.xyz );
				#endif
				VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
				o.pos = vertexInput.positionCS;
				o.texcoord = TRANSFORM_TEX(v.uv, _BaseMap);
				return o;
			}

			half4 frag(v2f i) : SV_Target
			{
				UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
				half4 col = SampleAlbedoAlpha(i.texcoord, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
				clip(col.a - _Cutoff);

				return col;
			}

		ENDHLSL
		}
	}
}
