Shader "Zhanyou/Mobile/Transparent/DiffuseAlphaTest" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Cutoff("Alpha Cutoff", Range(0, 1)) = 0.5
		_Emission ("Emission", Range(0, 1)) = 0
	}

	SubShader {
		Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }

		// Forward Base
		Pass
		{
			Name "FORWARD"
			Tags { "LightMode" = "ForwardBase" }

			CGPROGRAM
			#define UNITY_PASS_FORWARDBASE
			#include "UnityGiBase.cginc"
			#pragma multi_compile_fwdbase
			#pragma multi_compile_fog
			#pragma vertex vert_Base
			#pragma fragment frag
			#pragma multi_compile __ PLAYER_HALO_ON

			uniform sampler2D _MainTex;
			uniform float4 _MainTex_ST;
			uniform half _Emission;
			uniform half _Cutoff;

			fixed4 frag(v2f_Base i) : SV_TARGET
			{
				fixed4 c = tex2D(_MainTex, TRANSFORM_TEX(i.uv, _MainTex));
				clip(c.a - _Cutoff);
				// ÊÀ½ç·¨Ïß
				fixed3 worldNormal = fixed3(i.tSpace0.z, i.tSpace1.z, i.tSpace2.z);

				// ±ê×¼UnityGiÁ÷³Ì
				GET_UNITY_GI_COLOR;

				// ×Ô·¢¹â¹¦ÄÜ
				c.rgb = giColor + c.rgb * _Emission;
#if PLAYER_HALO_ON
				c.rgb += _DirectionalLightColor * LightColorFromWorld(worldPos);
#endif
				UNITY_APPLY_FOG(i.fogCoord, c);
				UNITY_OPAQUE_ALPHA(c.a);
				return c;
			}
			ENDCG
		}
		// Forward Add
		// ×¢£ºÊµ¼Ê¹âÕÕÌùͼֻͨ¹ýmetaͨµÀʵÏÖ£¬Forward Add½öÓÃÓڱ༭Æ÷ÎÞ¹âÕÕÌùͼʱԤÀÀ
		// ¼òµ¥´¦Àí£¬Forward AddҲʹÓö¥µã¼ÆËã¹âÕÕºÍÊÓÒ°·½Ïò£¬ÕæÊµ¹âÕÕ²ÎÊý
		// ¸ÃͨµÀ¿ÉÒÔʡȥ¾µÃæ¸ß¹âµÈËùÐè²ÎÊý£¬Òò´Ë°´³£¹æËã·¨×ö
		Pass
		{
			Name "FORWARD_ADD"
			Tags { "LightMode" = "ForwardAdd" }
			ZWrite Off
			Blend One One
			CGPROGRAM
			#define UNITY_PASS_FORWARDADD
			#include "UnityGiBase.cginc"
			#pragma multi_compile_fwdadd
			#pragma multi_compile_fog
			#pragma skip_variants INSTANCING_ON
			#pragma vertex vert_Add
			#pragma fragment frag
			uniform sampler2D _MainTex;
			uniform float4 _MainTex_ST;
			uniform half _Cutoff;

			fixed4 frag(v2f_Add i) : SV_TARGET
			{
#ifdef LIGHTMAP_ON
					fixed4 c = fixed4(0.0, 0.0, 0.0, 0.0);
#else
					fixed4 c = tex2D(_MainTex, TRANSFORM_TEX(i.uv, _MainTex));
					half NtoL = max(0.0, i.lightDir.z);
					UNITY_LIGHT_ATTENUATION(atten, i, i.worldPos);
					c.rgb = c.rgb * atten * _LightColor0.rgb * NtoL;
#endif
				clip(c.a - _Cutoff);
				UNITY_APPLY_FOG(i.fogCoord, c);
				UNITY_OPAQUE_ALPHA(c.a);
				return c;
			}
			ENDCG
		}
		// Shadow Caster
		// ---- shadow caster pass:
		Pass {
			Name "ShadowCaster"
			Tags { "LightMode" = "ShadowCaster" }
			ZWrite On ZTest LEqual

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_shadowcaster
			#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
			#include "HLSLSupport.cginc"
			#include "UnityShaderVariables.cginc"
			#define UNITY_PASS_SHADOWCASTER
			#include "UnityCG.cginc"
			#include "Lighting.cginc"
			half _Cutoff;

			sampler2D _MainTex;
			float4 _MainTex_ST;
			struct v2f {
				V2F_SHADOW_CASTER;
				float2 uv : TEXCOORD1; // _MainTex
				float3 worldPos : TEXCOORD2;
			};
			v2f vert (appdata_full v) {
				v2f o;
				UNITY_TRANSFER_INSTANCE_ID(v,o);
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
				o.worldPos = worldPos;
				TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
				return o;
			}
			fixed4 frag (v2f i) : SV_Target {
				fixed4 c = tex2D(_MainTex, i.uv);
				clip (c.a - _Cutoff);
				SHADOW_CASTER_FRAGMENT(i)
			}
			ENDCG
		}
		// Meta
		Pass
		{
			Name "Meta"
			Tags { "LightMode" = "Meta" }
			Cull Off

			CGPROGRAM
			#define UNITY_PASS_META
			#include "UnityCG.cginc"
			#include "UnityMetaPass.cginc"
			#pragma vertex vert
			#pragma fragment frag
			#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
			#pragma skip_variants INSTANCING_ON
			
			uniform half _Cutoff;
			uniform sampler2D _MainTex;
			uniform float4 _MainTex_ST;
			uniform half _Emission;

			struct v2f {
				float4 pos : SV_POSITION;
				float2 uv : TEXCOORD0;
			};

			v2f vert(appdata_full v) {
				v2f o;
				UNITY_INITIALIZE_OUTPUT(v2f, o);
				o.pos = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				return o;
			}

			fixed4 frag(v2f i) : SV_TARGET
			{
				fixed4 c = tex2D(_MainTex, i.uv);
				clip(c.a - _Cutoff);
				UnityMetaInput metaIN;
				UNITY_INITIALIZE_OUTPUT(UnityMetaInput, metaIN);
				metaIN.Albedo = c.rgb;
				metaIN.Emission = c.rgb * _Emission;
				return UnityMetaFragment(metaIN);
			}
			ENDCG
		}
	}
	Fallback "Zhanyou/Mobile/DiffuseEmit"
}