Advertisement
Sciman101

Outline Only Sprite Shader

Oct 20th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "Sprites/Character Sprite"
  4. {
  5. Properties
  6. {
  7. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  8. //Outline
  9. _OutlineColor ("Outline Color", Color) = (1,1,1,1)
  10. //_OutlineWidth ("Outline Width", Range(0,4)) = 1
  11. _OverlayColor("Addative Overlay Color", Color) = (1,1,1,1)
  12. //Hidden
  13. [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  14. [HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
  15. [HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
  16. }
  17.  
  18. SubShader
  19. {
  20. Tags
  21. {
  22. "Queue" = "Transparent"
  23. "IgnoreProjector" = "True"
  24. "RenderType" = "Transparent"
  25. "PreviewType" = "Plane"
  26. "CanUseSpriteAtlas" = "True"
  27. }
  28.  
  29. Cull Off
  30. Lighting Off
  31. ZWrite Off
  32. Fog { Mode Off }
  33. Blend SrcAlpha OneMinusSrcAlpha
  34.  
  35. Pass
  36. {
  37. CGPROGRAM
  38. #pragma vertex vert
  39. #pragma fragment frag
  40. #pragma multi_compile DUMMY PIXELSNAP_ON
  41. #include "UnityCG.cginc"
  42.  
  43. struct appdata_t
  44. {
  45. float4 vertex : POSITION;
  46. float4 color : COLOR;
  47. float2 texcoord : TEXCOORD0;
  48. };
  49.  
  50. struct v2f
  51. {
  52. float4 vertex : SV_POSITION;
  53. fixed4 color : COLOR;
  54. half2 texcoord : TEXCOORD0;
  55. };
  56.  
  57. fixed4 _Color, _OutlineColor;
  58.  
  59. v2f vert(appdata_t IN)
  60. {
  61. v2f OUT;
  62. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  63. OUT.texcoord = IN.texcoord;
  64. OUT.color = IN.color;
  65. #ifdef PIXELSNAP_ON
  66. OUT.vertex = UnityPixelSnap(OUT.vertex);
  67. #endif
  68.  
  69. return OUT;
  70. }
  71.  
  72. sampler2D _MainTex;
  73. float4 _MainTex_TexelSize;
  74.  
  75. fixed4 _OverlayColor;
  76.  
  77. fixed4 frag(v2f IN) : COLOR
  78. {
  79. fixed4 col = tex2D(_MainTex,IN.texcoord);
  80.  
  81. //Get color values of pixels adjacent
  82. float a = tex2D(_MainTex,IN.texcoord + fixed2(0, _MainTex_TexelSize.y)).a;
  83. a += tex2D(_MainTex, IN.texcoord + fixed2(0, -_MainTex_TexelSize.y)).a;
  84. a += tex2D(_MainTex, IN.texcoord + fixed2(-_MainTex_TexelSize.x,0)).a;
  85. a += tex2D(_MainTex, IN.texcoord + fixed2(_MainTex_TexelSize.x,0)).a;
  86.  
  87. a = step(a,.5);//Clamp the a value
  88. col.rgb = lerp(_OutlineColor, col.rgb, col.a);
  89. col.a = step(a, col.a);
  90.  
  91. col.rgb += _OverlayColor;
  92. col.rgb = min(col.rgb, 1);
  93.  
  94. //Spit out a color
  95. return col;
  96. }
  97.  
  98. ENDCG
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement