Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.25 KB | None | 0 0
  1. Shader "Custom/TerrainMapper" {
  2.     Properties {
  3.         _LowlandTex ("Grass", 2D)     = "white" {}
  4.       _HighlandTex("HighGrass", 2D) = "white" {}
  5.       _LowwallTex ("Stone", 2D)     = "white" {}
  6.       _HighwallTex("HighStone", 2D) = "white" {}
  7.      
  8.       _LowlandNorm ("GrassBump", 2D)     = "bump" {}
  9.       _HighlandNorm("HighGrassBump", 2D) = "bump" {}
  10.       _LowwallNorm ("StoneBump", 2D)     = "bump" {}
  11.       _HighwallNorm("HighStoneBump", 2D) = "bump" {}
  12.      
  13.       _HeightDiff("Height", Float)       = 100
  14.       _HeightMix ("MixingOffset", Float) = 3
  15.     }
  16.     SubShader {
  17.         Tags { "RenderType"="Opaque" }
  18.         LOD 200
  19.              
  20.         CGPROGRAM
  21.         #pragma surface surf Lambert
  22.       #pragma target 3.0
  23.  
  24.       #define PI 22/7
  25.      
  26.         sampler2D _LowlandTex, _HighlandTex, _LowwallTex, _HighwallTex, _LowlandNorm, _HighlandNorm, _LowwallNorm, _HighwallNorm;
  27.      
  28.       float _HeightDiff, _HeightMix;
  29.      
  30.         struct Input {
  31.             float2 uv_LowlandTex;        
  32.          float3 worldPos;
  33.          float3 worldNormal;
  34.         };
  35.  
  36.         void surf (Input IN, inout SurfaceOutput o) {;
  37.          
  38.          float deg = (1 - IN.worldNormal.y);
  39.          deg = (deg * 1.5);
  40.          if (deg > 1) deg = 1;
  41.          deg = (sin(deg * PI - PI * 0.5) + 1) * 0.5;
  42.                  
  43.          float height = IN.worldPos.y;
  44.          half4 c;
  45.          half4 b;
  46.          if (height > _HeightDiff + _HeightMix) {
  47.             c =  tex2D (_HighwallTex, IN.uv_LowlandTex) * deg;
  48.             c += tex2D (_HighlandTex, IN.uv_LowlandTex) * (1 - deg);
  49.              
  50.             b =  tex2D (_HighwallNorm, IN.uv_LowlandTex) * deg;
  51.             b += tex2D (_HighlandNorm, IN.uv_LowlandTex) * (1 - deg);
  52.                              
  53.          } else if (height > _HeightDiff - _HeightMix){
  54.             float k = (_HeightDiff + _HeightMix - height) / (_HeightMix * 2.0);
  55.             half4 c1, b1;
  56.            
  57.             c =  tex2D (_HighwallTex, IN.uv_LowlandTex) * deg;
  58.             c += tex2D (_HighlandTex, IN.uv_LowlandTex) * (1 - deg);  
  59.            
  60.             b =  tex2D (_HighwallNorm, IN.uv_LowlandTex) * deg;
  61.             b += tex2D (_HighlandNorm, IN.uv_LowlandTex) * (1 - deg);
  62.            
  63.             c *= (1 - k);
  64.             b *= (1 - k);
  65.            
  66.             c1 =  tex2D (_LowwallTex, IN.uv_LowlandTex) * deg;
  67.             c1 += tex2D (_LowlandTex, IN.uv_LowlandTex) * (1 - deg);
  68.            
  69.             b1 =  tex2D (_LowwallNorm, IN.uv_LowlandTex) * deg;
  70.             b1 += tex2D (_LowlandNorm, IN.uv_LowlandTex) * (1 - deg);
  71.            
  72.             c += c1 * k;
  73.             b += c1 * k;                                                          
  74.          } else {
  75.             c =  tex2D (_LowwallTex, IN.uv_LowlandTex) * deg;
  76.             c += tex2D (_LowlandTex, IN.uv_LowlandTex) * (1 - deg);
  77.            
  78.             b =  tex2D (_LowwallNorm, IN.uv_LowlandTex) * deg;
  79.             b += tex2D (_LowlandNorm, IN.uv_LowlandTex) * (1 - deg);
  80.          }                          
  81.             o.Albedo = c.rgb;
  82.             o.Alpha = c.a;  
  83.          
  84.          //o.Normal = UnpackNormal(tex2D (_LowlandNorm, IN.uv_LowlandTex));        
  85.          o.Normal = half3(0, 0, 0);//tex2D(_LowlandNorm, IN.uv_LowlandTex).xyz * 2 - 1;                
  86.          
  87.         }
  88.         ENDCG
  89.     }
  90.     FallBack "Diffuse"
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement