daily pastebin goal
24%
SHARE
TWEET

Demo 56 - Triplanar mapping

tonynogo Jul 6th, 2017 929 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Triplanar" {
  2.     Properties {
  3.         _Texture1 ("Texture 1", 2D) = "white" {}
  4.         _Texture2 ("Texture 2", 2D) = "white" {}
  5.         _Texture3 ("Texture 3", 2D) = "white" {}
  6.         _Scale ("Scale", Range(0.001, 0.2)) = 0.1
  7.     }
  8.     SubShader {
  9.         Tags { "RenderType"="Opaque" }
  10.        
  11.         CGPROGRAM
  12.         #pragma surface surf Standard
  13.  
  14.         sampler2D _Texture1;
  15.         sampler2D _Texture2;
  16.         sampler2D _Texture3;
  17.         float _Scale;
  18.  
  19.         struct Input {
  20.             float2 uv_MainTex;
  21.             float3 worldNormal;
  22.             float3 worldPos;
  23.         };
  24.  
  25.         void surf (Input IN, inout SurfaceOutputStandard o) {
  26.            
  27.             fixed4 col1 = tex2D(_Texture2, IN.worldPos.yz * _Scale);
  28.             fixed4 col2 = tex2D(_Texture1, IN.worldPos.xz * _Scale);
  29.             fixed4 col3 = tex2D(_Texture3, IN.worldPos.xy * _Scale);
  30.  
  31.             float3 vec = abs(IN.worldNormal);
  32.             vec /= vec.x + vec.y + vec.z + 0.001f;
  33.             fixed4 col = vec.x * col1 + vec.y * col2 + vec.z * col3;
  34.  
  35.             o.Albedo = col;
  36.             o.Emission = col;
  37.         }
  38.  
  39.         ENDCG
  40.     }
  41.     FallBack "Diffuse"
  42. }
RAW Paste Data
Top