Advertisement
Guest User

tk2d Lit Sprite Shader (example)

a guest
Feb 25th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "tk2d/BlendVertexColor (lit)"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  6.     }
  7.    
  8.     SubShader
  9.     {
  10.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  11.         ZWrite Off Lighting Off Cull Off Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha
  12.         LOD 110
  13.        
  14.         Pass
  15.         {
  16.             CGPROGRAM
  17.             #pragma vertex vert_vct
  18.             #pragma fragment frag_mult
  19.             #pragma fragmentoption ARB_precision_hint_fastest
  20.             #include "UnityCG.cginc"
  21.  
  22.             sampler2D _MainTex;
  23.             float4 _MainTex_ST;
  24.            
  25.             sampler2D LIGHT_TEX;
  26.  
  27.             struct vin_vct
  28.             {
  29.                 float4 vertex : POSITION;
  30.                 float4 color : COLOR;
  31.                 float2 texcoord : TEXCOORD0;
  32.             };
  33.  
  34.             struct v2f_vct
  35.             {
  36.                 float4 vertex : POSITION;
  37.                 fixed4 color : COLOR;
  38.                 float2 texcoord : TEXCOORD0;
  39.                 float2 lightCoord : TEXCOORD1;
  40.             };
  41.  
  42.             v2f_vct vert_vct(vin_vct v)
  43.             {
  44.                 v2f_vct o;
  45.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  46.                 o.lightCoord = 0.5 * (o.vertex.xy + float2(1.0, 1.0));
  47.                 o.color = v.color;
  48.                 o.texcoord = v.texcoord;
  49.                 return o;
  50.             }
  51.  
  52.             float4 frag_mult(v2f_vct i) : COLOR
  53.             {
  54.                 float4 col = tex2D(_MainTex, i.texcoord) * i.color;
  55.                 float4 light = tex2D(LIGHT_TEX, i.lightCoord);
  56.                 light.a = 1.0;
  57.                 return col * light;
  58.             }
  59.            
  60.             ENDCG
  61.         }
  62.     }
  63.  
  64.     SubShader
  65.     {
  66.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  67.         ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off Fog { Mode Off }
  68.         LOD 100
  69.  
  70.         BindChannels
  71.         {
  72.             Bind "Vertex", vertex
  73.             Bind "TexCoord", texcoord
  74.             Bind "Color", color
  75.         }
  76.  
  77.         Pass
  78.         {
  79.             Lighting Off
  80.             SetTexture [_MainTex] { combine texture * primary }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement