Shader "URP/Effects/Transparent-Simple" {
	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
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
		[Toggle]_Light_On("Light On",Float) = 1
		//[ToggleOff]_SHADOW_SWITCH("云影", Float) = 0.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 "../Common/Function/BlackHole.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
		#include "../Common/Function/Scene_Common.hlsl"
		#include "../Environment/Sky&Fog/VolumetricFogForObject.hlsl"

		struct unlit_v2f 
		{
			float4 pos : SV_POSITION;
			float2 texcoord : TEXCOORD0;
			float4 fogCoord : TEXCOORD1;
			float3 positionWS :TEXCOORD2;
			float3 normalWS : TEXCOORD3;

			UNITY_VERTEX_INPUT_INSTANCE_ID
			UNITY_VERTEX_OUTPUT_STEREO
		};

		struct appdata
		{
			float4 vertex : POSITION;
			float2 uv : TEXCOORD0;
			float3 normalOS :NORMAL;
			float4 tangentOS :TANGENT;
			UNITY_VERTEX_INPUT_INSTANCE_ID
		};
		ENDHLSL
		Pass{
			Tags{"LightMode" = "UniversalForward"}
			//Blend SrcAlpha OneMinusSrcAlpha
			ZWrite[_ZWrite]
			Cull Back
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_instancing
			//#pragma shader_feature _Fog
			//#pragma multi_compile_fog
			half _Light_On;
			half _Intensity;
			half3 _Color;
			unlit_v2f vert(appdata v)
			{
				unlit_v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_TRANSFER_INSTANCE_ID(v, o);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
				o.pos = vertexInput.positionCS;
				
				o.texcoord = TRANSFORM_TEX(v.uv, _BaseMap);
				o.positionWS = vertexInput.positionWS;
				VertexNormalInputs normalInput = GetVertexNormalInputs(v.normalOS, v.tangentOS);
				o.normalWS = normalInput.normalWS;
				o.fogCoord = VolumetricFog_GetFogCoord(vertexInput.positionNDC, vertexInput.positionVS.z);
				return o;
			}

			half4 frag(unlit_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);

				//half4 posW = VertCalaShadow(half4(i.positionWS,0), _DirX, _DirY);
				//light.shadowAttenuation =FragCalaShadowAtten(light.shadowAttenuation, posW, _Time.x, _Speed, _ShadowAlphaRatio, _ShadowTex);

				half3 bakedGI = SampleSHPixel(SampleSHVertex(i.normalWS), i.normalWS);
				half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
				half3 diffuseColor = bakedGI + LightingLambert(attenuatedLightColor, light.direction, i.normalWS);
				col.rgb *= _Color*_Intensity;
				col.rgb *= lerp(1,diffuseColor,_Light_On);

				col.rgb *= BalckHole_GetLightIntensity(i.positionWS.xyz);
				// #ifdef _Fog
				//col.rgb = VolumetricFog_GetFog(col.rgb, i.fogCoord);
				// #endif
				return col;
			}
		ENDHLSL
		}
		Pass
		{
			Name "DepthOnly"
			Tags
			{
				"LightMode" = "DepthOnly"
			}

			Cull Back
			ColorMask RGBA
			ZWrite[_ZWrite]
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_instancing
			//#pragma multi_compile_shadowcaster

			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
			#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
			#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
			unlit_v2f vert(appdata v)
			{
				unlit_v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_TRANSFER_INSTANCE_ID(v, o);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
				o.pos = vertexInput.positionCS;
				o.texcoord = TRANSFORM_TEX(v.uv, _BaseMap);
				return o;
			}
			half4 frag(unlit_v2f i) : SV_TARGET
			{
				UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
				clip(SampleAlbedoAlpha(i.texcoord, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a - _Cutoff);
				return 0;
			}

			ENDHLSL
		}
	}
}
