//角色卡通渲染 高级（半透明）
Shader "URP/Character/ToonCharacter_Base" 
{
	Properties
	{
		[Enum(OFF, 0, FRONT, 1, BACK, 2)] _Cull ("Cull Mode：裁剪", int) = 2
		[Tex(_, _Color)]_MainTex("Texture", 2D) = "white" {}
		[HideInInspector]_Color("Main Color", Color) = (1,1,1,1)
		[Tex(_, _NORMALMAP)]_BumpMap("Normalmap", 2D) = "white" {}
		[HideInInspector][Toggle(_NORMALMAP)]_NORMALMAP("Normal",Float) = 0
        [HideInInspector] _Surface("__surface", Float) = 0.0
        [HideInInspector] _AlphaClip("__clip", Float) = 0.0
        [HideInInspector] _SrcBlend("__src", Float) = 1.0
        [HideInInspector] _DstBlend("__dst", Float) = 0.0
        //[HideInInspector] _ZWrite("__zw", Float) = 1.0
        [HideInInspector] _Cull("__cull", Float) = 2.0
		[HideInInspector]_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
		[HideInInspector]_MainAlpha("MainAlpha", Range(0.0, 1.0)) = 1
		//_shadowFalloff("shadow Falloff", Range(0,1)) = 1
		
		[ToggleOff]_Receive_Shadows("Shadows:接收阴影", Float) = 1.0

		[Title(_,Ramp)]
		[Tex(_,_RampColor)]_RampTex("Ramp", 2D) = "white"{}
		[HideInInspector]_RampColor("Ramp Color", Color) = (1,1,1,1)
		_RampNum("RampNum", Range(1,20)) = 10

		[Title(_,LightMask)]
		[Tex(_,_LightMask_Off)]_LightMaskTex("LightMask:R:闭塞A:RampID(G:金属B:高亮)", 2D) = "black" {}
		[HideInInspector][ToggleOff]_LightMask_Off ("LightMask", float) = 0
		_LightMaskParam("LightMask:范围", Range(-1.0,1.0)) = 0.7
		_LightMaskBackParam("LightMask:暗部闭塞增强", Range(0.0,1.0)) = 0.7

		[Title(_,Outline)]
		[KWEnum(_, Uv3, _, Tangent, _TANGENT)]
		_OutlineMode("Outline Mode",Float) = 0
		[Sub(_)]_OutlineColor("Outline Color", Color) = (0.3,0.3,0.3,1)
		_Outline("Outline Width", range(0,20)) = 0.24
		_OutlineStrength("Outline Strength", range(0,5)) = 0.6
		//[Toggle(_Tangent)]_Tangent("Use Tangent",Float) = 0
		
		[Main(HighLight, _, 2)]
		_HL("HighLight", float) = 0
		[Title(HighLight,HighLight)]
		[Sub(HighLight)]_HighLight("HighLightStrength",range(0,2)) = 0.9		// 高光范围
		[Sub(HighLight)]_HighLightColor("HighLight Color", Color) = (1,1,1,1)
		[Title(HighLight,Specular)]
		[KWEnum(HighLight, NPR, _, PBR, _HL_PBR)]
        _Specular_Mode ("Specular Mode", float) = 0
		[Sub(HighLight)]_Shininess("Shininess", Range(0.01,1)) = 0.1
		[Sub(HighLight)]_SpecSmooth("Smoothness", Range(0,1)) = 0.05
		[Sub(HighLight)]_SpecStrength("SpecStrength", Range(0,2)) = 1
		[Sub(HighLight_HL_PBR)]_MetalStrength("MetalStrength", Range(0,2)) = 1
        [Sub(HighLight_HL_PBR)]_envir_brightness ("Envir brightness", Range(0,2)) = 1
		[SubToggle(HighLight_HL_PBR, _EnvironmentReflections)] _EnvironmentReflections("Environment Reflections", Float) = 0
		
		[Main(Rim)]
		_Rim("Rim", float) = 0
		[HideInInspector][HDR]_RimColor("Rim Color", color) = (0,0,0,1)
		[HideInInspector]_RimWidth("Rim Width", Range(0,1)) = 0
		[Sub(Rim)][HDR]_BackRimColor("Back Rim Color", color) = (0,0,0,1)
		[Sub(Rim)]_BackRimMax("Back Rim Max", Range(0,1)) = 1
		[Sub(Rim)]_BackRimMin ("Back Rim Min", Range(0,1)) = 1

		[Main(Emission)]
		_Illumin_On ("Emission", float) = 0
		[Sub(Emission)]_TimeScale ("Time Scale", Float ) = 1
		[Sub(Emission)]_IlluminStrength("Emission Strength" , Range(0,30)) = 0
		[Sub(Emission)][HDR]_IlluminColor("Emission Color", Color) = (1,1,1,1)

		[HideInInspector][Toggle(FLASH_SWITCH)]_FLASH_SWITCH("FLASH SWITCH", Float) = 0
		[HideInInspector]_FlashTex("FlashTex", 2D) = "white" {}
		[HideInInspector]_FlashFactor("FlashFactor", Vector) = (0, -2, 1, 1)
		[HideInInspector]_FlashStrength("FlashStrength", Range(0, 5)) = 1
		[HideInInspector]_DissolveTex("DissolveTex", 2D) = "white" {}
		[HideInInspector]_DissolveFactor("DissolveFactor",Range(0, 1)) = 0
		//_QueueOffset("Queue offset", Float) = 0.0
			
	}
	SubShader
	{
		Tags
		{
			"IgnoreProjector" = "true"
			"RenderType"="Opaque"
			"Queue"="Geometry"
		}

		pass
		{
			Tags{ "LightMode" = "UniversalForward" }
			//Blend[_SrcBlend][_DstBlend]
            //ZWrite[_ZWrite]
            Cull[_Cull]
			HLSLPROGRAM
			#pragma vertex BasicVert
			#pragma fragment BasicFrag
			#include "CharacterPassForward.hlsl"

			#pragma target 3.0 
			#pragma shader_feature _NORMALMAP
			//#pragma shader_feature USE_FACE_LIGHT
			//#pragma shader_feature _ALPHATEST_ON
			#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
			#pragma shader_feature _RECEIVE_SHADOWS_OFF
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
			#pragma multi_compile _ _SHADOWS_SOFT
			#pragma shader_feature FLASH_SWITCH
			#pragma multi_compile DISSOLVE
			ENDHLSL
		}
		pass
		{
			Name "CHAR_OUTLINE"
			Tags{ "LightMode" = "SRPDefaultUnlit" }
			Lighting Off
			Cull Front
			ZTest Less
			ColorMask RGBA
			//Blend SrcAlpha OneMinusSrcAlpha

			HLSLPROGRAM
			#pragma vertex OutlineVert
			#pragma fragment OutlineFrag
			#pragma shader_feature _TANGENT
			//#pragma shader_feature _Change
			//#pragma shader_feature _USE_Ramp_Num4
			#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
			#pragma shader_feature _RECEIVE_SHADOWS_OFF
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
			#pragma multi_compile _ _SHADOWS_SOFT
			#pragma shader_feature FLASH_SWITCH
			#pragma multi_compile DISSOLVE
			#include "CharacterPassForward.hlsl"
			#include "HLSLOutlineInc.hlsl"
			#pragma target 3.0

			ENDHLSL
		} 

		 Pass
		{
			Name "DepthOnly"
			Tags{"LightMode" = "DepthOnly"}
			ColorMask 0
			Cull[_Cull]

			HLSLPROGRAM
		// Required to compile gles 2.0 with standard srp library
		#pragma prefer_hlslcc gles
		#pragma exclude_renderers d3d11_9x
		#pragma target 2.0

		#pragma vertex DepthOnlyVertex
		#pragma fragment DepthOnlyFragment

		// -------------------------------------
		// Material Keywords
		//#pragma shader_feature _ALPHATEST_ON
		//#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

		//--------------------------------------
		// GPU Instancing
		#pragma multi_compile_instancing

		#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
		ENDHLSL
	
	
	}

		Pass
		{
			Name "ShadowCaster"
			Tags{"LightMode" = "ShadowCaster"}
			ZTest LEqual
			Cull[_Cull]

			HLSLPROGRAM
		// Required to compile gles 2.0 with standard srp library
		#pragma prefer_hlslcc gles
		#pragma exclude_renderers d3d11_9x
		#pragma target 2.0

		// -------------------------------------
		// Material Keywords
		//#pragma shader_feature _ALPHATEST_ON

		//--------------------------------------
		// GPU Instancing
		#pragma multi_compile_instancing
		//#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

		#pragma vertex ShadowPassVertex
		#pragma fragment ShadowPassFragment

		#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
		#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
		ENDHLSL
		}	
	}
	CustomEditor "FZDL.ShaderDrawer.LWGUI"
	//CustomEditor "Valkyrie.PBRToonShaderGUI"
}