|
|
- Shader "SuYou/CustomTerrain"
- {
- Properties
- {
- _Splat0 ("Layer 1", 2D) = "white" {}
- _Splat1 ("Layer 2", 2D) = "white" {}
- _Splat2 ("Layer 3", 2D) = "white" {}
- _Splat3 ("Layer 4", 2D) = "white" {}
- _Control ("Control (RGBA)", 2D) = "white" {}
- }
-
- CGINCLUDE
- sampler2D _Splat0, _Splat1, _Splat2, _Splat3, _Control;
- ENDCG
-
- SubShader {
- Tags { "SplatCount" = "4" "RenderType" = "Opaque" }
-
- Pass {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_fog
- #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
- #include "UnityCG.cginc"
-
- struct appdata_t
- {
- float4 vertex : POSITION;
- float2 texcoord : TEXCOORD0;
- float2 texcoord1 : TEXCOORD1;
- };
-
- struct v2f
- {
- half4 pos : SV_POSITION;
- half2 uv_Control : TEXCOORD0;
- half4 uv_Splat0 : TEXCOORD1;
- half4 uv_Splat1 : TEXCOORD2;
- #ifdef LIGHTMAP_ON
- half2 lmuv : TEXCOORD3;
- #endif
- UNITY_FOG_COORDS(4)
- };
-
-
- half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
- v2f vert (appdata_t v)
- {
- v2f o;
- o.pos = UnityObjectToClipPos (v.vertex);
- o.uv_Control = v.texcoord;
-
- o.uv_Splat0.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
- o.uv_Splat0.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
- o.uv_Splat1.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
- o.uv_Splat1.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
-
- #ifdef LIGHTMAP_ON
- o.lmuv = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
- #endif
- UNITY_TRANSFER_FOG(o,o.pos);
- return o;
- }
-
- fixed4 frag (v2f i) : COLOR0
- {
- fixed4 splat_control = tex2D (_Control, i.uv_Control).rgba;
-
- fixed3 lay1 = tex2D (_Splat0, i.uv_Splat0.xy);
- fixed3 lay2 = tex2D (_Splat1, i.uv_Splat0.zw);
- fixed3 lay3 = tex2D (_Splat2, i.uv_Splat1.xy);
- fixed3 lay4 = tex2D (_Splat3, i.uv_Splat1.zw);
- fixed4 resultColor;
- resultColor.rgb = (lay1 * splat_control.r + lay2 * splat_control.g + lay3 * splat_control.b + lay4 * splat_control.a);
-
- #ifdef LIGHTMAP_ON
- fixed3 lm = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap,i.lmuv));
- resultColor.rgb *= lm;
- #endif
-
- UNITY_APPLY_FOG(i.fogCoord, resultColor);
- return resultColor;
- }
-
- ENDCG
- }
- }
-
- Fallback Off
- }
|