Shader "URP/SceneBase/PBR_Scene_DetailNormal"
{
	Properties
	{	
		_Color ("Color", Color) = (1,1,1,1)	
		// [Enum(Both,0,Front,1,Back,2)] _CullMode("Cull Mode", int) = 2 
		// [Enum(Opaque,1,Alpha,5)]_SrcBlend("SrcBlend", Float) = 1
        // [Enum(Opaque,0,Alpha,10)]_DstBlend("DstBlend", Float) = 0
        //[Enum(Off,0,On,1)]_ZWrite("ZWrite", Float) = 1
		[HideInInspector] _Surface("__surface", Float) = 0.0
        //[HideInInspector] _Blend("__blend", 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
		_Cutoff ("Alpha Clip", Range(0,1)) = 0.5
		_MainAlpha ("MainAlpha", Range(0,1)) = 1
		[Enum(uv,0,uv3,1)] _UVSec ("UV Set", Float) = 0
		//[Header(Light)]
		// [KeywordEnum(Off,On)]_Light1("Directional Light",Float) = 1
		// [KeywordEnum(Off,On)]_Light2("LightDir",Float) = 0
		// _LightDir("LightDir", vector) = (0.1, 0.44, -0.3, 0)
		//_HColor ("hLight Color", Color) = (1,1,1,0)
		//_LightIntensity("Light Intensity",Float) = 1
		_diffuse_intensity ("Diffuse_Intensity", Range(0, 10)) = 1
		//_LM_Strength ("LM Strength", Range(0, 1)) = 0
		//_SM_Strength("SM Strength", Range(0, 1)) = 0
		//[Header(Metallic)]
		[Toggle(Metal_ON)]_Metal_ON("Metal_On",Float)=0
		[Toggle(ALPHA_METAL)]_Alpha_Metal("Alpha Metal",Float)=0
        _Metallic ("Metallic", Range(0, 1)) = 0
        _Roughness ("Roughness", Range(0, 2)) = 0
        _SpecStrength ("SpecStrength", Range(0, 5)) = 1
        _MetalStrength ("MetalStrength", Range(0, 5)) = 1
		//[NoScaleOffset]_EvnTex ("Env", Cube) = "white" { }
		[NoScaleOffset]_Metal_Mask ("Metal Mask", 2D) = "white" { }
        _envir_brightness ("Envir brightness", Vector) = (0.5,1,0,0)
        //_max_brightness ("max brightness", Float) = 1
        _bloom_range ("Bloom_range", Range(0, 1)) = 0
        _BloomFactor ("BloomFactor", Range(0, 1)) = 1
		//[Header(Env)]
		//_Ambient ("Ambient Color", Color) = (0.5,0.5,0.5,0)
		//_EnvShadow("Env Shadow",Color) = (1,1,1,1)
		[ToggleOff]_Receive_Shadows("Receive Shadows", Float) = 1.0
		[ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 0
		//[Header(HSV)]
		[Toggle(COLOR_HSV)]_Color_HSV("Color HSV",Float)=0
		_HueShift("HueShift", Float ) = 0
		_Sat("Saturation", range(0,4)) = 1
		_Val("Brightness", range(0,1)) = 0.5

		[Toggle(_EMISSION)]_EMISSION("Emission",Float)=0
		[HDR]_EmissionColor("Emission Color", Color) = (0,0,0)
        _EmissionMap("Emission", 2D) = "white" {}

		//[Header(Ramp)]
		[Toggle(_Ramp_On)]_Ramp_On("Ramp_On",Float)=0
		_RampThreshold ("Ramp Threshold", Range(0,1)) = 0.5
		_RampSmooth ("Ramp Smoothing", Range(0.01,1)) = 0.1
		_SColor ("SColor", Color) = (0.5,0.5,0.5,1.0)
		
		//[Header(Grass)]
		[Toggle(USE_Blend)]_Use_Blend("Use Blend",Float)=0
		_Blend("Blend Level",Range(-1,1)) = 0            
      	_BlendDirection("Blend Direction",Vector) = (0,2,0)
		_BlendColor ("Blend Color", Color) = (1,1,1,1.0)
		//[Header(_Cloud_Shadow)]
		// [Toggle(SHADOW_SWITCH)]_SHADOW_SWITCH("SHADOW SWITCH",Float)=0
		// [Toggle]_IsRotate("IsRotate", Range(0,1)) = 0
		// _ShadowTex("Shadow (RGB) Trans (A)", 2D) = "white" {}
		// _DirX("DirX", Range(0,250)) = 0.5
		// _DirY("DirY", Range(0,250)) = 0.5
		// _Speed("Speed", Range(-1,1)) = 0.1
		// _ShadowAlphaRatio("ShadowAlphaRatio", Range(0,1.5)) = 1
		// [Header(VertexColor)]
		// [Toggle(_USE_VCOLOR)]_Use_VColor("Use VColor",Float)=0
		// _VColor_R ("VColor R", Color) = (1,1,1,1)	
		// _VColor_G ("VColor G", Color) = (1,1,1,1)
		// _VColor_B ("VColor B", Color) = (1,1,1,1)
		[Header(Height Fog)]
		[Toggle(_HeightFog)]_Use_HFog("Use HFog",Float)=0
		_HFogColor ("HFog Color", Color) = (1,1,1,1)	
		_HFogStart("Height Fog Start",float) = 0
		_HFogEnd("Height Fog End",float) = 0
		_StartPoint("Start Point",float) = 0
		[Header(Fog)]
		[Toggle(_CustomFog)]_CustomFog("Custom Fog",Float) = 0
		_FogStart("Fog Start",float) = 0
		_FogEnd("Fog End",float) = 50
		_FogColor ("Fog Color", Color) = (1,1,1,0)	
		//[Header(Tex)]
		_BaseMap ("Base (RGB)", 2D) = "white" {}
		[HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
		[NoScaleOffset]_BumpMap ("Normalmap", 2D) = "bump" {}
		_NormalScale1 ("NormalScale", Float) = 1
		[NoScaleOffset]_DetailNormal ("DetailNormal (RGB)", 2D) = "bump" {}
		_NormalScale0 ("DetailNormalScale", Float) = 1	
		_BlendTex ("BlendTex (RGB)", 2D) = "white" {}
		[NoScaleOffset]_BlendNormal ("BlendNormal (RGB)", 2D) = "bump" {}
		_NormalScale2 ("BlendNormalScale", Float) = 1	
		_UseHole("Hole",range(-0.6, 0.5)) = -0.5

		[Header(Inject Effect)]
    	_EffectUVScale ("EffectUVScale", Vector) = (40,1,0,0)
    	_EffectWeight("EffectWeight",Vector) = (0,1,0,1)
			
	}
	SubShader {
		Tags { "RenderType" = "Opaque" }
		LOD 200
		Pass {
		Tags{"LightMode" = "UniversalForward"}
		Blend[_SrcBlend][_DstBlend]
		ZWrite[_ZWrite]
		Cull[_Cull]
		HLSLPROGRAM
		#pragma vertex vert
		#pragma fragment frag_Pbr
		//#pragma multi_compile _NORMALMAP
		#pragma shader_feature COLOR_HSV
		#pragma shader_feature ALPHA_METAL
		#pragma shader_feature _EMISSION
		#pragma shader_feature _ALPHATEST_ON
		#pragma shader_feature USE_Blend
		#pragma multi_compile _ LIGHTMAP_ON
		#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
		#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
		#pragma multi_compile _ SHADOWS_SHADOWMASK
		#pragma shader_feature _RECEIVE_SHADOWS_OFF
		#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
		#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
		#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
		#pragma multi_compile _ _SHADOWS_SOFT
		#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
		#pragma multi_compile _ DIRLIGHTMAP_COMBINED
		#pragma shader_feature _ENVIRONMENTREFLECTIONS_OFF
		#pragma multi_compile _ INJECT_EFFECT_SNOW
		#pragma multi_compile _ INJECT_EFFECT_BURN
		#pragma multi_compile _ _UNIQUE_SHADOW

		//#pragma multi_compile_fog
		#pragma multi_compile_instancing

		#define _NORMALMAP 1
		//#define LIGHTMAP_ON 1

		#pragma prefer_hlslcc gles
		#pragma exclude_renderers d3d11_9x
		#pragma target 2.0
		#include "../../Common/Function/Scene_PBR.hlsl"
		half4 frag_Pbr (v2f i) : SV_Target
		{	
			half4 col = SampleAlbedoAlpha(i.uv*_BaseMap_ST.xx, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
			half4 outColor = frag_Common_Color(i,col);
			UNITY_SETUP_INSTANCE_ID(i);
			UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
			half4 holeColor = GetHoleColor(i.positionWS);
			clip(holeColor.r - (0.5f + _UseHole));
		#ifdef _ALPHATEST_ON
			outColor.a = col.a*_MainAlpha;
			clip(outColor.a-_Cutoff);
		#endif
		//fog
			// half density = i.FogAndDistanceAndvPos.x;
			// outColor.rgb = MixFog( outColor.rgb ,density);
			return outColor;
		}
		ENDHLSL
    }
	Pass
            {
                Name "a"
                Tags{ "LightMode" = "SRPDefaultUnlit" }
                Lighting Off
                ZWrite Off
                Blend SrcAlpha  OneMinusSrcAlpha
                ColorMask A
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                //#pragma multi_compile_fog
				#include "UnityCG.cginc"
				uniform half4 _MainLightColor;
                float _BloomFactor;
			uniform half _SceneBloomFactor;
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };
            sampler2D _BaseMap;
            v2f vert(appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            { 
            fixed4 col = tex2D(_BaseMap, i.uv);
			col.a = _BloomFactor*_SceneBloomFactor;
            return col;
        }
        ENDCG
    }
	Pass
		{
		Name "ShadowCaster"
			Tags
			{
				"LightMode" = "ShadowCaster"
			}
			Cull Off
			ZWrite On
            ZTest LEqual
			Cull[_Cull]
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#pragma multi_compile_shadowcaster
			#pragma multi_compile _ALPHATEST_ON
			#pragma multi_compile_instancing
			#pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma target 2.0
			#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"

			//TEXTURE2D(_BaseMap); 
			//SAMPLER(sampler_BaseMap);
			//float4 _BaseMap_ST;
			half4 _Color;
			Varyings vert(Attributes v)
			{
				Varyings o;
				UNITY_SETUP_INSTANCE_ID(v);
				o.positionCS = GetShadowPositionHClip(v);
				o.uv = TRANSFORM_TEX(v.texcoord, _BaseMap);
				return o;
			}

			float4 frag(Varyings i) : SV_Target
			{
				Alpha(SampleAlbedoAlpha(i.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _Color, _Cutoff);
				return 0;
			}

			ENDHLSL
		}

		Pass
		{
			Name"DepthOnly"
			Tags
			{
				"LightMode" = "DepthOnly"
			}

			Blend[_SrcBlend][_DstBlend]
			ZWrite[_ZWrite]
			Cull[_Cull]
			HLSLPROGRAM
			#pragma vertex vert
			#pragma fragment frag_Pbr
			//#pragma multi_compile _NORMALMAP
			#pragma shader_feature COLOR_HSV
			#pragma shader_feature Metal_ON
			#pragma shader_feature _EMISSION
			#pragma shader_feature _ALPHATEST_ON
			#pragma shader_feature USE_Blend
			#pragma multi_compile _ LIGHTMAP_ON
			#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
			#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
			#pragma multi_compile _ SHADOWS_SHADOWMASK
			#pragma shader_feature _RECEIVE_SHADOWS_OFF
			#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
			#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
			#pragma multi_compile _ _SHADOWS_SOFT
			#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
			#pragma multi_compile _ DIRLIGHTMAP_COMBINED
			#pragma shader_feature _ENVIRONMENTREFLECTIONS_OFF
			#pragma multi_compile _ INJECT_EFFECT_SNOW
			#pragma multi_compile _ INJECT_EFFECT_BURN

			//#pragma multi_compile_fog
			#pragma multi_compile_instancing

			#define _NORMALMAP 1
			//#define LIGHTMAP_ON 1

			#pragma prefer_hlslcc gles
			#pragma exclude_renderers d3d11_9x
			#pragma target 2.0
			#include "../../Common/Function/Scene_PBR.hlsl"
			half4 frag_Pbr (v2f i) : SV_Target
			{	
				half4 col = SampleAlbedoAlpha(i.uv*_BaseMap_ST.xx, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
				half4 outColor = frag_Common_Color(i,col);
				UNITY_SETUP_INSTANCE_ID(i);
				UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
				half4 holeColor = GetHoleColor(i.positionWS);
				clip(holeColor.r - (0.5f + _UseHole));
				#ifdef _ALPHATEST_ON
					outColor.a = col.a*_MainAlpha;
					clip(outColor.a-_Cutoff);
				#endif
				//fog
				// half density = i.FogAndDistanceAndvPos.x;
				// outColor.rgb = MixFog( outColor.rgb ,density);
				return outColor;
			}
		ENDHLSL
		}

				//UsePass "URP/DepthOnly/DepthOnlyCutoff"
		//UsePass "Universal Render Pipeline/Lit/DepthOnly"
		//UsePass "Universal Render Pipeline/Lit/ShadowCaster"
	}
	CustomEditor "DBT.SceneAdvancedShaderGUI"
} 