Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/TerrainMapper" {
- Properties {
- _LowlandTex ("Grass", 2D) = "white" {}
- _HighlandTex("HighGrass", 2D) = "white" {}
- _LowwallTex ("Stone", 2D) = "white" {}
- _HighwallTex("HighStone", 2D) = "white" {}
- _LowlandNorm ("GrassBump", 2D) = "bump" {}
- _HighlandNorm("HighGrassBump", 2D) = "bump" {}
- _LowwallNorm ("StoneBump", 2D) = "bump" {}
- _HighwallNorm("HighStoneBump", 2D) = "bump" {}
- _HeightDiff("Height", Float) = 100
- _HeightMix ("MixingOffset", Float) = 3
- }
- SubShader {
- Tags { "RenderType"="Opaque" }
- LOD 200
- CGPROGRAM
- #pragma surface surf Lambert
- #pragma target 3.0
- #define PI 22/7
- sampler2D _LowlandTex, _HighlandTex, _LowwallTex, _HighwallTex, _LowlandNorm, _HighlandNorm, _LowwallNorm, _HighwallNorm;
- float _HeightDiff, _HeightMix;
- struct Input {
- float2 uv_LowlandTex;
- float3 worldPos;
- float3 worldNormal;
- };
- void surf (Input IN, inout SurfaceOutput o) {;
- float deg = (1 - IN.worldNormal.y);
- deg = (deg * 1.5);
- if (deg > 1) deg = 1;
- deg = (sin(deg * PI - PI * 0.5) + 1) * 0.5;
- float height = IN.worldPos.y;
- half4 c;
- half4 b;
- if (height > _HeightDiff + _HeightMix) {
- c = tex2D (_HighwallTex, IN.uv_LowlandTex) * deg;
- c += tex2D (_HighlandTex, IN.uv_LowlandTex) * (1 - deg);
- b = tex2D (_HighwallNorm, IN.uv_LowlandTex) * deg;
- b += tex2D (_HighlandNorm, IN.uv_LowlandTex) * (1 - deg);
- } else if (height > _HeightDiff - _HeightMix){
- float k = (_HeightDiff + _HeightMix - height) / (_HeightMix * 2.0);
- half4 c1, b1;
- c = tex2D (_HighwallTex, IN.uv_LowlandTex) * deg;
- c += tex2D (_HighlandTex, IN.uv_LowlandTex) * (1 - deg);
- b = tex2D (_HighwallNorm, IN.uv_LowlandTex) * deg;
- b += tex2D (_HighlandNorm, IN.uv_LowlandTex) * (1 - deg);
- c *= (1 - k);
- b *= (1 - k);
- c1 = tex2D (_LowwallTex, IN.uv_LowlandTex) * deg;
- c1 += tex2D (_LowlandTex, IN.uv_LowlandTex) * (1 - deg);
- b1 = tex2D (_LowwallNorm, IN.uv_LowlandTex) * deg;
- b1 += tex2D (_LowlandNorm, IN.uv_LowlandTex) * (1 - deg);
- c += c1 * k;
- b += c1 * k;
- } else {
- c = tex2D (_LowwallTex, IN.uv_LowlandTex) * deg;
- c += tex2D (_LowlandTex, IN.uv_LowlandTex) * (1 - deg);
- b = tex2D (_LowwallNorm, IN.uv_LowlandTex) * deg;
- b += tex2D (_LowlandNorm, IN.uv_LowlandTex) * (1 - deg);
- }
- o.Albedo = c.rgb;
- o.Alpha = c.a;
- //o.Normal = UnpackNormal(tex2D (_LowlandNorm, IN.uv_LowlandTex));
- o.Normal = half3(0, 0, 0);//tex2D(_LowlandNorm, IN.uv_LowlandTex).xyz * 2 - 1;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement