Shader "URP/Terrain/PBR_Scene_Blend_4Tex"
{
	Properties
	{
		_Color ("Color", Color) = (1,1,1,1)
		//_LightDir("LightDir", vector) = (0.1, 0.44, -0.3, 0)
		//_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
		[Title(_,Specular)]
		[Sub(_)]_Roughness("Roughness", Range(0, 2)) = 0
		_SpecStrength ("SpecStrength", Range(0, 2)) = 1
		[Title(_,Shadow)]
		//[Sub(_)]_EnvShadow("Env Shadow",Color) = (0.5,0.5,0.5,1)
		[ToggleOff]_Receive_Shadows("Receive Shadows", Float) = 1.0

		[Title(_,Env)]
		//[Sub(Env)]_LM_Strength("lightmap强度", Range(0, 1)) = 0
		//[Sub(Env)]_SM_Strength("shadowmask强度", Range(0, 1)) = 0
		[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" {}
		// [Title(HSV,R_G)]
		// [Sub(HSV)]_HueShiftFlipG("R通道内G通道色相", Float) = 0
		// [Sub(HSV)]_SatFlipG("R通道内G通道饱和", range(0,10)) = 1
		// [Sub(HSV)]_ValFlipG("R通道内G通道明度", range(0,5)) = 0.5
		// [Sub(HSV)]_Flip_CMaskBottomG("R通道内G通道颜色", Color) = (1, 1, 1, 1)

		// [Main(ColorMask,_,2)]
		// _CM("ColorMask", float) = 0
		// [Sub(ColorMask)]_ColorStart("ColorStart", Float) = 0
		// [Sub(ColorMask)]_ColorEnd("ColorEnd", Float) = 50
		// [Sub(ColorMask)]_ColorMask("Color Mask", 2D) = "white" {}
		//[Header(Base)]

		[Main(Tex,_,2)]
		_Tex("贴图", float) = 0
		[Sub(Tex)]_UvSize("UvSize:xy为地表尺寸zw为中心坐标", vector) = (200, 200, 0, 0)
		[Sub(Tex)]_Weight("Blend Weight" , Range(0.001,1)) = 0.2 
		[KWEnum(Tex,Uv,_,Uv3,_,Wrold_UV,_)]
		_BlendUV ("贴图uv切换", Float) = 0
		[KWEnum(Tex,Uv,_,Uv3,_,Wrold_UV,_)]
		_ControlUV ("Control控制图uv切换", Float) = 0
		[Sub(Tex)]_ColorR ("ColorR", Color) = (1,1,1,1)
    	[Sub(Tex)]_Splat0 ("Layer 1(RGBA)", 2D) = "white" {}
        [Tex(Tex,_NormalScale0)]_BumpMap ("Layer 1 Normal(Bump)", 2D) = "Bump" {}	
		[HideInInspector]_NormalScale0 ("Layer 1 NormalScale", Float) = 1
		[Sub(Tex)]_ColorG ("ColorG", Color) = (1,1,1,1)
    	[Sub(Tex)]_Splat1 ("Layer 2(RGBA)", 2D) = "white" {}
        [Tex(Tex,_NormalScale1)]_BumpSplat1 ("Layer 2 Normal(Bump)", 2D) = "Bump" {}
		[HideInInspector]_NormalScale1 ("Layer 2 NormalScale", Float) = 1
		[Sub(Tex)]_ColorB ("ColorB", Color) = (1,1,1,1)
    	[Sub(Tex)]_Splat2 ("Layer 3(RGBA)", 2D) = "white" {}
        [Tex(Tex,_NormalScale2)]_BumpSplat2 ("Layer 3 Normal(Bump)", 2D) = "Bump" {}
		[HideInInspector]_NormalScale2 ("Layer 3 NormalScale", Float) = 1
		[Sub(Tex)]_ColorA ("ColorA", Color) = (1,1,1,1)
        [Sub(Tex)]_Splat3 ("Layer 4(RGBA)", 2D) = "white" {}
        [Tex(Tex,_NormalScale3)]_BumpSplat3 ("Layer 4 Normal(Bump)", 2D) = "Bump" {}
		[HideInInspector]_NormalScale3 ("Layer 4 NormalScale", Float) = 1
		[Tex(Tex,_)]_Control ("Control (RGBA)", 2D) = "white" {}
		//_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 multi_compile _ _UNIQUE_SHADOW

		#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
		float4 _Splat0_ST,_Splat1_ST,_Splat2_ST,_Splat3_ST;
		half4 _ColorR,_ColorG,_ColorB,_ColorA;  
		half _NormalScale2,_NormalScale3;
		#include "../../Common/Function/Scene_PBR.hlsl"
		half4 frag_Pbr(v2f i) : SV_Target
		{
			half4 lay1 = SampleAlbedoAlpha(i.BlendUv*_Splat0_ST, TEXTURE2D_ARGS(_Splat0, sampler_Splat0));
			half4 lay2 = SampleAlbedoAlpha(i.BlendUv*_Splat1_ST, TEXTURE2D_ARGS(_Splat1, sampler_Splat1));
			half4 lay3 = SampleAlbedoAlpha(i.BlendUv*_Splat2_ST, TEXTURE2D_ARGS(_Splat2, sampler_Splat2));
			half4 lay4 = SampleAlbedoAlpha(i.BlendUv*_Splat3_ST, TEXTURE2D_ARGS(_Splat3, sampler_Splat3));
			lay1.rgb *= _ColorR.rgb;lay2.rgb *= _ColorG.rgb;lay3.rgb *= _ColorB.rgb;lay4.rgb *= _ColorA.rgb;
			half4 splat_control = SampleAlbedoAlpha(i.ControlUv, TEXTURE2D_ARGS(_Control, sampler_Control));
			half4 blend = Blend(lay1.a,lay2.a,lay3.a,lay4.a,splat_control);
			half4 col = lay1 * blend.r + lay2 * blend.g + lay3 * blend.b + lay4 * blend.a;
			//half4 nor1 = half4(0,0,1,0);
			half4 nor1 = SampleNormalAlpha(i.BlendUv*_Splat0_ST, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap),_NormalScale0);
			half4 nor2 = SampleNormalAlpha(i.BlendUv*_Splat1_ST, TEXTURE2D_ARGS(_BumpSplat1, sampler_BumpSplat1),_NormalScale1);
			half4 nor3 = SampleNormalAlpha(i.BlendUv*_Splat2_ST, TEXTURE2D_ARGS(_BumpSplat2, sampler_BumpSplat2),_NormalScale2);
			half4 nor4 = SampleNormalAlpha(i.BlendUv*_Splat3_ST, TEXTURE2D_ARGS(_BumpSplat3, sampler_BumpSplat3),_NormalScale3);
			half4 Normal = nor1*blend.r + nor2*blend.g + nor3*blend.b + nor4*blend.a;

			half CM = 1-blend.r*_ColorR.a-blend.g*_ColorG.a-blend.b*_ColorB.a-blend.a*_ColorA.a;
			half4 outColor = frag_Blend_Common(i,col,Normal,CM);
			return outColor;
		}
		ENDHLSL
	}
	UsePass "URP/Terrain/Mobile_PBR_Blend_4Tex/DepthOnly"
	UsePass "URP/Terrain/Mobile_PBR_Blend_4Tex/ShadowCaster"
}
CustomEditor "FZDL.ShaderDrawer.LWGUI"
} 