Advertisement
ElectricJesus

CelShadingSpriteShadowsOnShader

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