Advertisement
Guest User

DecalProjector.shader

a guest
Oct 13th, 2018
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Shader "Projector/Decal" {
  3.     Properties {      
  4.         _Color("Main Color", Color) = (1,1,1,1)
  5.         _Decal ("Cookie", 2D) = "" {}    
  6.         _Slider("Slider", Range(0,1)) = 0.0
  7.         [Toggle(UV2)] _UV2("Use Second UV Map?", Float) = 0
  8.     }
  9.  
  10.     Subshader {
  11.         Tags {"Queue"="Transparent"}
  12.         Pass {
  13.             ZWrite Off
  14.             Cull Off
  15.             ColorMask RGBA
  16.             Blend SrcAlpha OneMinusSrcAlpha
  17.             Offset -1, -1
  18.  
  19.             CGPROGRAM
  20.             #pragma vertex vert
  21.             #pragma fragment frag  
  22.             #pragma shader_feature UV2
  23.             #include "UnityCG.cginc"
  24.          
  25.             struct v2f {
  26.                 float4 uvShadow : TEXCOORD0;
  27.                 float4 pos : SV_POSITION;
  28.             };
  29.          
  30.             float4x4 unity_Projector;
  31.             float4x4 unity_ProjectorClip;
  32.             float _Slider;
  33.             float4 _Color;
  34.          
  35.             v2f vert (appdata_full v)
  36.             {
  37.                 v2f o;
  38.                 float x = v.texcoord.x;
  39.                 float y = v.texcoord.y;
  40.                
  41.                 #if UV2
  42.                 x = v.texcoord2.x;
  43.                 y = v.texcoord2.y;             
  44.                 #endif
  45.                 x= x * 2 -1;           
  46.                 y= y * -2 +1;
  47.                
  48.                 float4 vertexUV = float4(x , y, 0, 1);
  49.                 float4 normalview = UnityObjectToClipPos(v.vertex);
  50.                 o.pos = lerp(vertexUV, normalview, _Slider);
  51.                 o.uvShadow = mul (unity_Projector, v.vertex);                          
  52.                 return o;
  53.             }          
  54.          
  55.             sampler2D _Decal;          
  56.          
  57.             fixed4 frag (v2f i) : SV_Target
  58.             {
  59.                 fixed4 texS = tex2Dproj (_Decal, UNITY_PROJ_COORD(i.uvShadow)) * _Color;                                                  
  60.                 return texS;
  61.             }
  62.             ENDCG
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement