Advertisement
Guest User

Two Textures one plane

a guest
Mar 4th, 2014
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. Shader "Custom/TwoSided" {
  2.     Properties {
  3.         _FirstTex ("First (RGB)", 2D) = "white" {}
  4.         _SecondTex ("Second (RGB)", 2D) = "white"{}
  5.     }
  6.    
  7.     SubShader {
  8.        
  9.     Pass {
  10.       Cull Off
  11.       CGPROGRAM
  12.       #pragma vertex vert
  13.       #pragma fragment frag
  14.       #include "UnityCG.cginc"
  15.  
  16.  
  17.         sampler2D _FirstTex;
  18.         sampler2D _SecondTex;
  19.    
  20.       struct v2f {
  21.           float4 pos : SV_POSITION;
  22.           fixed4 color : COLOR;
  23.           float4 tex : TEXCOORD0;
  24.       };
  25.  
  26.       v2f vert (appdata_base v)
  27.       {
  28.           v2f o;
  29.          
  30.           o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
  31.          
  32.           float3 viewVector = normalize(_WorldSpaceCameraPos);
  33.          
  34.           //Converting the normal to world space as we have view vector in world space. We need to transfer both to same space for any operations.
  35.           float3 worldSpaceNormal = normalize(mul((float3x3)_World2Object,v.normal));
  36.          
  37.           //Dot product to know which side we are facing
  38.           float NdotL = dot(viewVector,v.normal);
  39.  
  40.           o.color.w = NdotL;
  41.          
  42.           o.tex = v.texcoord;
  43.          
  44.           return o;
  45.       }
  46.  
  47.       fixed4 frag (v2f i) : COLOR0 {
  48.           if(i.color.w > 0.0f)
  49.           {
  50.             i.color.xyz = tex2D(_FirstTex, float2(i.tex)).xyz;
  51.           }
  52.           else
  53.           {
  54.             i.color.xyz = tex2D(_SecondTex, float2(i.tex)).xyz;
  55.           }
  56.          
  57.           return i.color;
  58.       }
  59.       ENDCG
  60.     }
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement