Advertisement
tonynogo

Demo 55 - Worldspace texture

Jul 6th, 2017
7,963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/WorldSpaceTexture" {
  2.     Properties {
  3.         _MainTex ("Texture", 2D) = "white" {}
  4.     }
  5.  
  6.     SubShader {
  7.         Tags { "RenderType"="Opaque" }
  8.  
  9.         CGPROGRAM
  10.         #pragma surface surf Standard
  11.  
  12.         sampler2D _MainTex;
  13.  
  14.         struct Input {
  15.             float3 worldNormal;
  16.             float3 worldPos;
  17.         };
  18.  
  19.         void surf (Input IN, inout SurfaceOutputStandard o) {
  20.  
  21.             if(abs(IN.worldNormal.y) > 0.5)
  22.             {
  23.                 o.Albedo = tex2D(_MainTex, IN.worldPos.xz);
  24.             }
  25.             else if(abs(IN.worldNormal.x) > 0.5)
  26.             {
  27.                 o.Albedo = tex2D(_MainTex, IN.worldPos.yz);
  28.             }
  29.             else
  30.             {
  31.                 o.Albedo = tex2D(_MainTex, IN.worldPos.xy);
  32.             }
  33.  
  34.             o.Emission = o.Albedo;
  35.         }
  36.  
  37.         ENDCG
  38.     }
  39.     FallBack "Diffuse"
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement