OutlineBufferShader.shader 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. // Copyright (c) 2015 José Guerreiro. All rights reserved.
  3. //
  4. // MIT license, see http://www.opensource.org/licenses/mit-license.php
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. */
  24. Shader "Hidden/OutlineBufferEffect" {
  25. Properties
  26. {
  27. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  28. _Color ("Tint", Color) = (1,1,1,1)
  29. [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
  30. }
  31. SubShader
  32. {
  33. Tags
  34. {
  35. "Queue" = "Transparent"
  36. "IgnoreProjector" = "True"
  37. "RenderType" = "Transparent"
  38. "PreviewType" = "Plane"
  39. "CanUseSpriteAtlas" = "True"
  40. }
  41. Cull [_Culling]
  42. Lighting Off
  43. CGPROGRAM
  44. #pragma surface surf Lambert vertex:vert nofog noshadow noambient nolightmap novertexlights noshadowmask nometa //keepalpha
  45. #pragma multi_compile _ PIXELSNAP_ON
  46. sampler2D _MainTex;
  47. fixed4 _Color;
  48. float _OutlineAlphaCutoff;
  49. struct Input
  50. {
  51. float2 uv_MainTex;
  52. //fixed4 color;
  53. };
  54. void vert(inout appdata_full v, out Input o)
  55. {
  56. #if defined(PIXELSNAP_ON)
  57. v.vertex = UnityPixelSnap(v.vertex);
  58. #endif
  59. UNITY_INITIALIZE_OUTPUT(Input, o);
  60. //o.color = v.color;
  61. }
  62. void surf(Input IN, inout SurfaceOutput o)
  63. {
  64. fixed4 c = tex2D(_MainTex, IN.uv_MainTex);// * IN.color;
  65. if (c.a < _OutlineAlphaCutoff) discard;
  66. /* float alpha = c.a * 99999999;
  67. o.Albedo = _Color * alpha;
  68. o.Alpha = alpha; */
  69. o.Albedo = _Color;
  70. o.Emission = o.Albedo;
  71. }
  72. ENDCG
  73. }
  74. Fallback "Transparent/VertexLit"
  75. }