Shader "URP/Terrain/Terrain-BlendStone"
{
	Properties
	{
		_Color("Color", Color) = (1,1,1,1)
		//_HColor("Highlight Color", Color) = (0.785,0.785,0.785,1.0)
		//_LightIntensity("HighLight Intensity",Float) = 1
		_diffuse_intensity("Diffuse_Intensity", Range(0, 10)) = 1
		//[Header(Specular)]
		[Title(_,Specular)]
		[Sub(_)]_Roughness("Roughness", Range(0, 2)) = 0
		_SpecStrength ("SpecStrength", Range(0, 2)) = 1
		[Title(_,Shadow)]
		[ToggleOff]_Receive_Shadows("Receive Shadows", Float) = 1.0

		[Title(_,Env)]
		[Sub(_)]_envir_brightness ("反射x", Vector) = (0.2,0,0,0)
		[ToggleOff]_EnvironmentReflections("Environment Reflections", Float) = 0

		[Main(COLOR,_,2)]
		_COLOR("COLOR:基础远处-R通道内远处-G通道远处", float) = 0
		[Color(COLOR,_,_CMaskBottomFar,_CMaskBottomGFar)]
		_ColorBottomFar("远处颜色", Color) = (1, 1, 1, 1)
		[HideInInspector]_CMaskBottomFar("R通道内远处颜色", Color) = (1, 1, 1, 1)
		[HideInInspector]_CMaskBottomGFar("G通道远处颜色", Color) = (1, 1, 1, 1)
		//[HideInInspector]_Flip_CMaskBottomGFar("R通道内G通道远处颜色", Color) = (1, 1, 1, 1)
		[Title(COLOR,R)]
		[Sub(COLOR)]_HueShiftCM("R通道色相", Float) = 0
		[Sub(COLOR)]_SatCM("R通道饱和", range(0,10)) = 1
		[Sub(COLOR)]_ValCM("R通道明度", range(0,5)) = 0.5
		[Sub(COLOR)]_CMaskBottom("R通道颜色", Color) = (1, 1, 1, 1)
		[Title(COLOR,G)]
		[Sub(COLOR)]_HueShift("G通道色相", Float) = 0
		[Sub(COLOR)]_Sat("G通道饱和", range(0,10)) = 1
		[Sub(COLOR)]_Val("G通道明度", range(0,5)) = 0.5
		[Sub(COLOR)]_CMaskBottomG("G通道颜色", Color) = (1, 1, 1, 1)
		[Title(COLOR,ColorMask)]
		[Sub(COLOR)]_ColorStart("ColorStart", Float) = 0
		[Sub(COLOR)]_ColorEnd("ColorEnd", Float) = 50
		[Sub(COLOR)]_ColorMask("Color Mask:TillingX红通道TillingY绿通道", 2D) = "white" {}
		
		// [HideInInspector][KeywordEnum(Off,On)]_CustomFog("Custom Fog",Float) = 0
		// _FogColor("Fog Color", Color) = (1,1,1,0)
		//[Header(Base)]
		[Main(Tex,_,2)]
		_Tex("贴图", float) = 0
		[Sub(Tex)]_UvSize("UvSize:xy为地表尺寸zw为中心坐标", vector) = (200, 200, 0, 0)
		[KWEnum(Tex,Uv,_,Uv3,_)]
		_UVSec ("细节法线uv切换", Float) = 0
		[KWEnum(Tex,Uv,_,Uv3,_,Wrold_UV,_)]
		_BlendUV ("混合贴图uv切换", Float) = 0
		[KWEnum(Tex,Uv,_,Uv3,_,Wrold_UV,_)]
		_ControlUV ("控制图uv切换", Float) = 0
		//_Weight("Blend Weight" , Range(0.001,1)) = 0.2
		//_CMRange("CMRange",Vector) = (1, 1, 1, 1)
		//_BTiling("Tiling",Vector) = (1, 1, 1, 1)
		//_NormalScale("NormalScale",Vector) = (1, 1, 1, 1)
		[Sub(Tex)]_BaseMap ("Base (RGB)", 2D) = "white" {}
        [Tex(Tex,_NormalScale0)]_BumpMap ("Normal(Bump)", 2D) = "Bump" {}
		[HideInInspector]_NormalScale0 ("NormalScale", Float) = 1
		[Sub(Tex)]_DetailNormal ("DetailNormal (RGB)", 2D) = "bump" {}
		[Sub(Tex)]_NormalScale2 ("DetailNormalScale", Float) = 1
		//[Title(Tex,Blend)]
		//[Enum(Uv,0,Uv3,1,Wrold_UV,2)] _UVSec ("BlendTex UV Set", Float) = 0
		[Sub(Tex)]_Splat0 ("Blend Tex(RGBA)", 2D) = "white" {}
       	[Tex(Tex,_NormalScale1)]_BumpSplat1 ("Blend Normal(Bump)", 2D) = "Bump" {}
		[HideInInspector]_NormalScale1 ("Blend NormalScale", Float) = 1
		//[Title(Tex,Control)]
    	[Tex(Tex,_)]_Control ("Control (RGBA)", 2D) = "white" {}

		[HideInInspector]_Splat1 ("Layer 1(RGBA)", 2D) = "white" {}
    	[HideInInspector]_Splat2 ("Layer 3(RGBA)", 2D) = "white" {}
        [HideInInspector]_Splat3 ("Layer 4(RGBA)", 2D) = "white" {}
		
		//_BlockParams("Block Params",Vector) = (41007, 242262, 0.1, 0)
		//_UseHole("Hole",range(-0.6, 0.5)) = -0.5
	}
		SubShader{
				 Tags {
					 "SplatCount" = "4"
				   "RenderType" = "Opaque"
				}
			Pass {
				Tags{"LightMode" = "UniversalForward"}

				HLSLPROGRAM
				#pragma vertex vert
				#pragma fragment frag_Pbr

				#pragma shader_feature _RECEIVE_SHADOWS_OFF
				#pragma shader_feature _ENVIRONMENTREFLECTIONS_OFF
				#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
				#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
				#pragma multi_compile _ SHADOWS_SHADOWMASK
				#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 prefer_hlslcc gles
				#pragma exclude_renderers d3d11_9x
				#pragma target 2.0
				#define _NORMALMAP 1
				#define LIGHTMAP_ON 1
				#define USE_FAST_HSV_COMPUTED 1
				#define _Terrain_Moblie 1
				#include "../../Common/Function/Scene_PBR.hlsl"
				float4 _Splat0_ST;
				TEXTURE2D(_DetailNormal); SAMPLER(sampler_DetailNormal);
				float2 _DetailNormal_ST;
				half _NormalScale2; 
				half4 frag_Pbr(v2f i) : SV_Target
				{
					half4 col = SampleAlbedoAlpha(i.uv*_BaseMap_ST.xx, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
					half4 lay1 = SampleAlbedoAlpha(i.BlendUv*_Splat0_ST.xx, TEXTURE2D_ARGS(_Splat0, sampler_Splat0));
					half4 splat_control = SAMPLE_TEXTURE2D(_Control,sampler_Control, i.ControlUv);
					col = lerp(lay1,col,splat_control.a*i.color.a);
					half4 BaseNormal = SampleNormalAlpha(i.uv*_BaseMap_ST.xx, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap),_NormalScale0);
					half4 DetailNormal = SampleNormalAlpha(i.uv_Detail*_DetailNormal_ST.xx, TEXTURE2D_ARGS(_DetailNormal, sampler_DetailNormal),_NormalScale2); 
					half4 BlendNormal = SampleNormalAlpha(i.BlendUv*_Splat0_ST.xx, TEXTURE2D_ARGS(_BumpSplat1, sampler_BumpSplat1),_NormalScale1);
					BaseNormal.rgb = normalize(half3(BaseNormal.xy+DetailNormal.xy,BaseNormal.z));
					half4 Normal = lerp(BlendNormal,BaseNormal,splat_control.a*i.color.a);
					half4 outColor = frag_Blend_Common(i,col,Normal,(1-splat_control.a)*i.color.a);
					return outColor;
				}
				ENDHLSL
			}
			UsePass "URP/Terrain/Mobile_PBR_Blend_4Tex/DepthOnly"
			UsePass "URP/Terrain/Mobile_PBR_Blend_4Tex/ShadowCaster"
		}
		CustomEditor "FZDL.ShaderDrawer.LWGUI"
}