Advertisement
Guest User

Terrain Shader

a guest
Dec 8th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. Shader "Custom/4-Part Texture" {  
  2.     Properties {  
  3.         _MainTex0 ("Base (RGB)", 2D) = "white" {}  
  4.         //Added three more textures slots, one for each image  
  5.         _MainTex1 ("Base (RGB)", 2D) = "white" {}  
  6.         _MainTex2 ("Base (RGB)", 2D) = "white" {}  
  7.         _MainTex3 ("Base (RGB)", 2D) = "white" {}  
  8.     }  
  9.     SubShader {  
  10.         Tags { "RenderType"="Opaque" }  
  11.         LOD 200  
  12.  
  13.         CGPROGRAM  
  14.         #pragma surface surf Lambert  
  15.  
  16.         sampler2D _MainTex0;  
  17.         //Added three more 2D samplers, one for each additional texture  
  18.         sampler2D _MainTex1;  
  19.         sampler2D _MainTex2;  
  20.         sampler2D _MainTex3;  
  21.  
  22.         struct Input {  
  23.             float2 uv_MainTex0;  
  24.         };  
  25.  
  26.         //this variable stores the current texture coordinates multiplied by 2  
  27.         float2 dbl_uv_MainTex0;  
  28.  
  29.         void surf (Input IN, inout SurfaceOutput o) {  
  30.  
  31.             //multiply the current vertex texture coordinate by two  
  32.             dbl_uv_MainTex0 = IN.uv_MainTex0*2;  
  33.  
  34.             //add an offset to the texture coordinates for each of the input textures  
  35.             half4 c0 = tex2D (_MainTex0, dbl_uv_MainTex0 - float2(0.0, 1.0));  
  36.             half4 c1 = tex2D (_MainTex1, dbl_uv_MainTex0 - float2(1.0, 1.0));  
  37.             half4 c2 = tex2D (_MainTex2, dbl_uv_MainTex0);  
  38.             half4 c3 = tex2D (_MainTex3, dbl_uv_MainTex0 - float2(1.0, 0.0));  
  39.  
  40.             //this if statement assures that the input textures won't overlap  
  41.             if(IN.uv_MainTex0.x >= 0.5)  
  42.             {  
  43.                 if(IN.uv_MainTex0.y <= 0.5)  
  44.                 {  
  45.                     c0.rgb = c1.rgb = c2.rgb = 0;  
  46.                 }  
  47.                 else  
  48.                 {  
  49.                     c0.rgb = c2.rgb = c3.rgb = 0;  
  50.                 }  
  51.             }  
  52.             else  
  53.             {  
  54.                 if(IN.uv_MainTex0.y <= 0.5)  
  55.                 {  
  56.                     c0.rgb = c1.rgb = c3.rgb = 0;  
  57.                 }  
  58.                 else  
  59.                 {  
  60.                     c1.rgb = c2.rgb = c3.rgb = 0;  
  61.                 }  
  62.             }  
  63.  
  64.             //sum the colors and the alpha, passing them to the Output Surface 'o'  
  65.             o.Albedo = c0.rgb + c1.rgb + c2.rgb + c3.rgb;  
  66.             o.Alpha = c0.a + c1.a + c2.a + c3.a ;  
  67.         }  
  68.         ENDCG  
  69.     }  
  70.     FallBack "Diffuse"  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement