MiniMapEffect.shader 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  4. Shader "MiniMapEffect/MapOutline"
  5. {
  6. Properties
  7. {
  8. _MainTex ("Sprite Texture", 2D) = "white" {}
  9. _Color ("Tint", Color) = (1,1,1,1)
  10. PixelSnap ("Pixel snap", Float) = 1
  11. // Add values to determine if outlining is enabled and outline color.
  12. _Outline ("Outline", Float) = 1
  13. _OutlineColor("Outline Color", Color) = (1,1,1,1)
  14. _TexelSizeX ("TexelSizeX", Float) = 1
  15. _TexelSizeY ("TexelSizeY", Float) = 1
  16. }
  17. SubShader
  18. {
  19. Tags
  20. {
  21. "Queue"="Transparent"
  22. "IgnoreProjector"="True"
  23. "RenderType"="Transparent"
  24. "PreviewType"="Plane"
  25. "CanUseSpriteAtlas"="True"
  26. }
  27. Cull Off
  28. Lighting Off
  29. ZWrite Off
  30. Blend One OneMinusSrcAlpha
  31. Pass
  32. {
  33. CGPROGRAM
  34. #pragma vertex vert
  35. #pragma fragment frag
  36. #pragma multi_compile _ PIXELSNAP_ON
  37. #pragma shader_feature ETC1_EXTERNAL_ALPHA
  38. #include "UnityCG.cginc"
  39. struct appdata_t
  40. {
  41. float4 vertex : POSITION;
  42. float4 color : COLOR;
  43. float2 texcoord : TEXCOORD0;
  44. };
  45. struct v2f
  46. {
  47. float4 vertex : SV_POSITION;
  48. fixed4 color : COLOR;
  49. float2 texcoord : TEXCOORD0;
  50. };
  51. fixed4 _Color;
  52. float _Outline;
  53. fixed4 _OutlineColor;
  54. //fixed4 _MainTex_TexelSize;
  55. float _TexelSizeX;
  56. float _TexelSizeY;
  57. v2f vert(appdata_t IN)
  58. {
  59. v2f OUT;
  60. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  61. OUT.texcoord = IN.texcoord;
  62. OUT.color = IN.color * _Color;
  63. #ifdef PIXELSNAP_ON
  64. OUT.vertex = UnityPixelSnap (OUT.vertex);
  65. #endif
  66. return OUT;
  67. }
  68. sampler2D _MainTex;
  69. sampler2D _AlphaTex;
  70. fixed4 SampleSpriteTexture (float2 uv)
  71. {
  72. fixed4 color = tex2D (_MainTex, uv);
  73. #if ETC1_EXTERNAL_ALPHA
  74. // get the color from an external texture (usecase: Alpha support for ETC1 on android)
  75. color.a = tex2D (_AlphaTex, uv).r;
  76. #endif //ETC1_EXTERNAL_ALPHA
  77. return color;
  78. }
  79. fixed4 frag(v2f IN) : SV_Target
  80. {
  81. fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
  82. // If outline is enabled and there is a pixel, try to draw an outline.
  83. if (_Outline > 0 && c.a != 0) {
  84. // Get the neighbouring four pixels.
  85. fixed4 pixelUp = tex2D(_MainTex, IN.texcoord + fixed2(0, _TexelSizeY));
  86. fixed4 pixelDown = tex2D(_MainTex, IN.texcoord - fixed2(0, _TexelSizeY));
  87. fixed4 pixelRight = tex2D(_MainTex, IN.texcoord + fixed2(_TexelSizeX, 0));
  88. fixed4 pixelLeft = tex2D(_MainTex, IN.texcoord - fixed2(_TexelSizeX, 0));
  89. // &&
  90. // pixelDown.rgba == fixed4(0, 0, 0, 1) &&
  91. // pixelRight.rgba == fixed4(0, 0, 0, 1) &&
  92. // pixelLeft.rgba == fixed4(0, 0, 0, 1)
  93. if (pixelUp.r == pixelDown.r == pixelRight.r == pixelLeft.r) {
  94. pixelUp.a = 0;
  95. }
  96. // If one of the neighbouring pixels is invisible, we render an outline.
  97. if (pixelUp.a * pixelDown.a * pixelRight.a * pixelLeft.a == 0) {
  98. c.rgba = fixed4(1, 1, 1, 0.5f) * _OutlineColor;
  99. }
  100. }
  101. c.rgb *= c.a;
  102. return c;
  103. }
  104. ENDCG
  105. }
  106. }
  107. }