Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. Shader "UnityCommunity/Sprites/SpriteDropShadow"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  6. _Color ("Tint", Color) = (1,1,1,1)
  7. [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
  8. _ShadowColor ("Shadow", Color) = (0,0,0,1)
  9. _ShadowOffset ("ShadowOffset", Vector) = (0,-0.1,0,0)
  10. }
  11. SubShader
  12. {
  13. Tags
  14. {
  15. "Queue"="Transparent"
  16. "IgnoreProjector"="True"
  17. "RenderType"="Transparent"
  18. "PreviewType"="Plane"
  19. "CanUseSpriteAtlas"="True"
  20. }
  21. Cull Off
  22. Lighting Off
  23. ZWrite Off
  24. Blend One OneMinusSrcAlpha
  25. // draw shadow
  26. Pass
  27. {
  28. CGPROGRAM
  29. #pragma vertex vert
  30. #pragma fragment frag
  31. #pragma multi_compile _ PIXELSNAP_ON
  32. #include "UnityCG.cginc"
  33.  
  34. struct appdata_t
  35. {
  36. float4 vertex : POSITION;
  37. float4 color : COLOR;
  38. float2 texcoord : TEXCOORD0;
  39. };
  40. struct v2f
  41. {
  42. float4 vertex : SV_POSITION;
  43. fixed4 color : COLOR;
  44. float2 texcoord : TEXCOORD0;
  45. };
  46.  
  47. fixed4 _Color;
  48. fixed4 _ShadowColor;
  49. float4 _ShadowOffset;
  50. v2f vert(appdata_t IN)
  51. {
  52. v2f OUT;
  53. OUT.vertex = UnityObjectToClipPos(IN.vertex+_ShadowOffset);
  54. OUT.texcoord = IN.texcoord;
  55. OUT.color = IN.color *_ShadowColor;
  56. #ifdef PIXELSNAP_ON
  57. OUT.vertex = UnityPixelSnap (OUT.vertex);
  58. #endif
  59. return OUT;
  60. }
  61. sampler2D _MainTex;
  62. sampler2D _AlphaTex;
  63. float _AlphaSplitEnabled;
  64. fixed4 SampleSpriteTexture (float2 uv)
  65. {
  66. fixed4 color = tex2D (_MainTex, uv);
  67. color.rgb = _ShadowColor.rgb;
  68. #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  69. if (_AlphaSplitEnabled)
  70. color.a = tex2D (_AlphaTex, uv).r;
  71. #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  72. return color;
  73. }
  74. fixed4 frag(v2f IN) : SV_Target
  75. {
  76. fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
  77. c.rgb *= c.a;
  78. return c;
  79. }
  80. ENDCG
  81. }
  82. // draw real sprite
  83. Pass
  84. {
  85. CGPROGRAM
  86. #pragma vertex vert
  87. #pragma fragment frag
  88. #pragma multi_compile _ PIXELSNAP_ON
  89. #include "UnityCG.cginc"
  90.  
  91. struct appdata_t
  92. {
  93. float4 vertex : POSITION;
  94. float4 color : COLOR;
  95. float2 texcoord : TEXCOORD0;
  96. };
  97. struct v2f
  98. {
  99. float4 vertex : SV_POSITION;
  100. fixed4 color : COLOR;
  101. float2 texcoord : TEXCOORD0;
  102. };
  103.  
  104. fixed4 _Color;
  105. v2f vert(appdata_t IN)
  106. {
  107. v2f OUT;
  108. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  109. OUT.texcoord = IN.texcoord;
  110. OUT.color = IN.color * _Color;
  111. #ifdef PIXELSNAP_ON
  112. OUT.vertex = UnityPixelSnap (OUT.vertex);
  113. #endif
  114. return OUT;
  115. }
  116. sampler2D _MainTex;
  117. sampler2D _AlphaTex;
  118. float _AlphaSplitEnabled;
  119. fixed4 SampleSpriteTexture (float2 uv)
  120. {
  121. fixed4 color = tex2D (_MainTex, uv);
  122. #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  123. if (_AlphaSplitEnabled)
  124. color.a = tex2D (_AlphaTex, uv).r;
  125. #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  126. return color;
  127. }
  128. fixed4 frag(v2f IN) : SV_Target
  129. {
  130. fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
  131. c.rgb *= c.a;
  132. return c;
  133. }
  134. ENDCG
  135. }
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement