Advertisement
ElectricJesus

CelShadingShadowsOnCutoff

Aug 26th, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Shader "Sprites/CelShadingShadowsOnCutoff"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _NormalsTex("Sprite Normals", 2D) = "bump" {}
  7. _CelRamp("Cel shading ramp", 2D) = "white" {}
  8. _Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.5
  9. _Color("Tint", Color) = (1,1,1,1)
  10. [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  11. }
  12.  
  13. SubShader
  14. {
  15. Tags
  16. {
  17. "Queue" = "Geometry"
  18. "RenderType" = "TransparentCutout"
  19. "IgnoreProjector" = "False"
  20. "PreviewType" = "Plane"
  21. "CanUseSpriteAtlas" = "True"
  22. }
  23. LOD 200
  24.  
  25. Cull Off
  26. Lighting On
  27. ZWrite Off
  28. Fog{ Mode Off }
  29. Blend SrcAlpha OneMinusSrcAlpha
  30.  
  31. CGPROGRAM
  32. #pragma surface surf CustomLambert vertex:vert addshadow fullforwardshadows
  33. #pragma multi_compile DUMMY PIXELSNAP_ON
  34. #pragma target 3.0
  35.  
  36. sampler2D _MainTex;
  37. sampler2D _NormalsTex;
  38. sampler2D _CelRamp;
  39. fixed4 _Color;
  40. fixed _Cutoff;
  41.  
  42. struct Input
  43. {
  44. float2 uv_MainTex;
  45. fixed4 color;
  46. };
  47.  
  48. half4 LightingCustomLambert(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
  49. half NdotL = dot(s.Normal, lightDir);
  50. half4 c;
  51. c.rgb = (s.Albedo * _LightColor0.rgb * (tex2D(_CelRamp, half2 (NdotL * 0.5 + 0.5, 0)))) * (atten * 2);
  52. c.a = s.Alpha;
  53. return c;
  54. }
  55.  
  56. void vert(inout appdata_full v, out Input o)
  57. {
  58. #if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH)
  59. v.vertex = UnityPixelSnap(v.vertex);
  60. #endif
  61. v.normal = float3(0,0,-1);
  62. v.tangent = float4(-1, 0, 0, 1);
  63.  
  64. UNITY_INITIALIZE_OUTPUT(Input, o);
  65. o.color = _Color * v.color;
  66. }
  67.  
  68. void surf(Input IN, inout SurfaceOutput o)
  69. {
  70. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
  71. o.Albedo = c.rgb;
  72. o.Normal = UnpackNormal(tex2D(_NormalsTex, IN.uv_MainTex));
  73. o.Alpha = c.a;
  74. clip(o.Alpha - _Cutoff);
  75. }
  76. ENDCG
  77. }
  78.  
  79. Fallback "Diffuse"
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement