Advertisement
dnnkeeper

Unity Triplanar PBS Simple

Nov 6th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. Shader "Custom/TerrainShader" {
  2.     Properties {
  3.         _ColorLow ("_ColorLow", Color) = (0,1,0,1)
  4.         _ColorHigh ("_ColorHigh", Color) = (1,1,1,1)
  5.         _ColorSlope ("_ColorHigh", Color) = (1,0,0,1)
  6.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  7.        
  8.         _BumpMap ("BumpMapLow", 2D) = "white" {}
  9.         _BumpMapHigh ("BumpMapHigh", 2D) = "white" {}
  10.         _BumpMapSlope ("BumpMapSlope", 2D) = "white" {}
  11.        
  12.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
  13.         _HeightFactor ("HeightFactor", Float) = 0.05
  14.         _SlopeFactor ("SlopeFactor", Float) = 0.7
  15.         //_Metallic ("Metallic", Range(0,1)) = 0.0
  16.     }
  17.     SubShader {
  18.         Tags { "RenderType"="Opaque" }
  19.         LOD 200
  20.        
  21.         CGPROGRAM
  22.         // Physically based Standard lighting model, and enable shadows on all light types
  23.         #pragma surface surf Standard
  24.  
  25.         // Use shader model 3.0 target, to get nicer looking lighting
  26.         #pragma target 3.0
  27.  
  28.         fixed4 _ColorLow,_ColorHigh,_ColorSlope;
  29.         sampler2D _MainTex,_BumpMap,_BumpMapHigh,_BumpMapSlope;
  30.         float _HeightFactor,_SlopeFactor;
  31.  
  32.         struct Input {
  33.             float2 uv_MainTex;
  34.             float2 uv_BumpMap;
  35.             float3 worldPos;
  36.             float3 worldNormal; INTERNAL_DATA
  37.         };
  38.  
  39.         half _Glossiness;
  40.         half _Metallic;
  41.         fixed4 _Color;
  42.  
  43.         void surf (Input IN, inout SurfaceOutputStandard o) {
  44.             // Albedo comes from a texture tinted by color
  45.             fixed4 col = tex2D (_MainTex, IN.uv_MainTex);
  46.            
  47.             float h = saturate(IN.worldPos.y*_HeightFactor);
  48.            
  49.             o.Normal = UnpackNormal ( lerp( tex2D (_BumpMap, IN.uv_BumpMap), tex2D (_BumpMapHigh, IN.uv_BumpMap), h ) );
  50.            
  51.             float3 worldNorm = WorldNormalVector (IN, o.Normal);
  52.            
  53.             float slope = abs( dot(worldNorm, float3(0,1,0) ) );
  54.            
  55.             fixed4 c = lerp( _ColorLow, _ColorHigh, h*h ); 
  56.            
  57.             if (slope > _SlopeFactor)
  58.                 c.rgb = c;
  59.             else{
  60.                 c.rgb = lerp(col, c, slope*slope );
  61.                
  62.                 o.Normal = UnpackNormal ( tex2D (_BumpMapSlope, IN.uv_MainTex) );
  63.                
  64.             }
  65.  
  66.             //o.Normal = worldNorm;
  67.  
  68.             o.Albedo = c.rgb;
  69.             // Metallic and smoothness come from slider variables
  70.             o.Metallic = 0.0;
  71.             o.Smoothness = c.a*_Glossiness;
  72.             o.Alpha = 1.0;
  73.         }
  74.         ENDCG
  75.     }
  76.     FallBack "Diffuse"
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement