ArenMook

Decal shader

Jan 23rd, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | None | 0 0
  1. Shader "Tasharen/Text Decal"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Color", Color) = (1,1,1,1)
  6.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  7.         _Cutoff ("Base Alpha cutoff", Range (0, 0.9)) = 0.5
  8.         _Specular ("Specular", Color) = (0.2,0.2,0.2,1)
  9.         _Smoothness ("Smoothness", Range(0,1)) = 0.81
  10.     }
  11.     SubShader
  12.     {
  13.         Tags
  14.         {
  15.             "Queue" = "AlphaTest+100"
  16.             "RenderType" = "Opaque"
  17.         }
  18.  
  19.         LOD 200
  20.         Offset -1, -1
  21.         Blend SrcAlpha OneMinusSrcAlpha
  22.         Cull Off
  23.         ZWrite Off
  24.  
  25.         Pass
  26.         {
  27.             Name "ShadowCaster"
  28.             Tags { "LightMode" = "ShadowCaster" }
  29.             Fog { Mode Off }
  30.  
  31.             // Seems to work with this removed too
  32.             Offset [_ShadowBias], [_ShadowBiasSlope]
  33.  
  34.             CGPROGRAM
  35.             #pragma vertex vert
  36.             #pragma fragment frag
  37.             #pragma multi_compile_shadowcaster
  38.             #pragma multi_compile _ LOD_FADE_CROSSFADE
  39.             #pragma fragmentoption ARB_precision_hint_fastest
  40.             #include "UnityCG.cginc"
  41.  
  42.             sampler2D _MainTex;
  43.             half _Cutoff;
  44.             half4 _Color;
  45.  
  46.             struct appdata
  47.             {
  48.                 float4 vertex : POSITION;
  49.                 float4 color: COLOR;
  50.                 float2 texcoord : TEXCOORD0;
  51.             };
  52.  
  53.             struct v2f
  54.             {
  55.                 V2F_SHADOW_CASTER;
  56.                 half2 uv : TEXCOORD1;
  57.                 half4 color : TEXCOORD2;
  58.                 UNITY_DITHER_CROSSFADE_COORDS_IDX(3)
  59.             };
  60.  
  61.             v2f vert (appdata v)
  62.             {
  63.                 v2f o;
  64.                 UNITY_TRANSFER_DITHER_CROSSFADE(o, v.vertex);
  65.                 o.uv = v.texcoord;
  66.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  67.                 o.color = v.color;
  68.                 TRANSFER_SHADOW_CASTER(o)
  69.                 return o;
  70.             }
  71.  
  72.             float4 frag (v2f IN) : COLOR
  73.             {
  74.                 half4 c = IN.color * _Color;
  75.                 c.a *= tex2D(_MainTex, IN.uv).a;
  76.  
  77. #ifdef LOD_FADE_CROSSFADE
  78.                 UNITY_APPLY_DITHER_CROSSFADE(IN);
  79. #endif
  80.                 SHADOW_CASTER_FRAGMENT(IN)
  81.             }
  82.             ENDCG
  83.         }
  84.        
  85.         CGPROGRAM
  86.         // Physically based Standard lighting model, and enable shadows on all light types
  87.         #pragma surface surf Tasharen vertex:vert fullforwardshadows
  88.         #pragma target 4.0
  89.         #pragma multi_compile _ LOD_FADE_CROSSFADE
  90.  
  91.         #include "Tasharen Lighting.cginc"
  92.  
  93.         sampler2D _MainTex;
  94.  
  95.         struct appdata
  96.         {
  97.             float4 vertex : POSITION;
  98.             float3 normal : NORMAL;
  99.             float2 texcoord : TEXCOORD0;
  100.             fixed4 color: COLOR;
  101.         };
  102.  
  103.         struct Input
  104.         {
  105.             half2 uv_MainTex;
  106.             half4 color;
  107.             UNITY_DITHER_CROSSFADE_COORDS
  108.         };
  109.  
  110.         half4 _Color, _Specular;
  111.         half _Smoothness, _Cutoff;
  112.  
  113.         void vert (inout appdata_full v, out Input o)
  114.         {
  115.             UNITY_INITIALIZE_OUTPUT(Input, o);
  116.             UNITY_TRANSFER_DITHER_CROSSFADE(o, v.vertex);
  117.             o.color = v.color;
  118.         }
  119.  
  120.         void surf (Input IN, inout Output o)
  121.         {
  122.             // Albedo comes from a texture tinted by color
  123.             half4 c = IN.color * _Color;
  124.             c.a *= tex2D (_MainTex, IN.uv_MainTex).a;
  125.             clip(c.a - _Cutoff);
  126.  
  127.             o.Albedo = c.rgb;
  128.             o.Smoothness = _Smoothness;
  129.             o.Specular = _Specular;
  130.             o.Alpha = c.a;
  131.  
  132.             UNITY_APPLY_DITHER_CROSSFADE(IN);
  133.         }
  134.         ENDCG
  135.     }
  136.     FallBack Off
  137. }
Advertisement
Add Comment
Please, Sign In to add comment