SpriteEdgeOutline.shader 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Shader "Hidden/2D-Animation-SpriteEdgeOutline"
  2. {
  3. Properties
  4. {
  5. _OutlineColor("Outline Color", Color) = (1,0,1,1)
  6. }
  7. SubShader
  8. {
  9. Tags
  10. {
  11. "Queue" = "Transparent"
  12. "IgnoreProjector" = "True"
  13. "RenderType" = "Transparent"
  14. }
  15. Cull Off
  16. Lighting Off
  17. ZTest Less
  18. Blend SrcAlpha OneMinusSrcAlpha
  19. Pass
  20. {
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #include "UnityCG.cginc"
  25. struct appdata_t
  26. {
  27. float4 vertex : POSITION;
  28. };
  29. struct v2f
  30. {
  31. float4 vertex : SV_POSITION;
  32. float2 clipUV : TEXCOORD1;
  33. };
  34. uniform float4x4 unity_GUIClipTextureMatrix;
  35. sampler2D _GUIClipTexture;
  36. uniform bool _AdjustLinearForGamma;
  37. v2f vert(appdata_t IN)
  38. {
  39. v2f OUT;
  40. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  41. float3 eyePos = UnityObjectToViewPos(IN.vertex);
  42. OUT.clipUV = mul(unity_GUIClipTextureMatrix, float4(eyePos.xy, 0, 1.0));
  43. return OUT;
  44. }
  45. fixed4 _OutlineColor;
  46. fixed4 frag(v2f i) : SV_Target
  47. {
  48. if (tex2D(_GUIClipTexture, i.clipUV).a == 0)
  49. discard;
  50. float4 c = _OutlineColor;
  51. if (_AdjustLinearForGamma)
  52. c.rgb = LinearToGammaSpace(c.rgb);
  53. return c;
  54. }
  55. ENDCG
  56. }
  57. }
  58. }