MiniMapOverlayUnlit.shader 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. Shader "CompassNavigatorPro/MiniMapOverlayUnlit"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  6. _Color ("Tint", Color) = (1,1,1,1)
  7. _MiniMapTex ("MiniMap Render Texture", 2D) = "black" {}
  8. _BorderTex ("Border Texture", 2D) = "black" {}
  9. _FogOfWarTex ("Fog Of War Tex", 2D) = "black" {}
  10. _FogOfWarTintColor ("Fog Of War Color", Color) = (1,1,1,1)
  11. _NoiseTex ("Noise (RGB)", 2D) = "white" {}
  12. _StencilComp ("Stencil Comparison", Float) = 8
  13. _Stencil ("Stencil ID", Float) = 0
  14. _StencilOp ("Stencil Operation", Float) = 0
  15. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  16. _StencilReadMask ("Stencil Read Mask", Float) = 255
  17. _ColorMask ("Color Mask", Float) = 15
  18. _UVOffset ("UV Offset", Vector) = (0,0,0)
  19. _UVFogOffset("Fog Offset", Vector) = (0,0,0)
  20. _Rotation("Rotation", Float) = 0
  21. _Effects("Effects", Vector) = (1,1,0)
  22. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  23. }
  24. SubShader
  25. {
  26. Tags
  27. {
  28. "Queue"="Transparent"
  29. "IgnoreProjector"="True"
  30. "RenderType"="Transparent"
  31. "PreviewType"="Plane"
  32. "CanUseSpriteAtlas"="True"
  33. }
  34. Stencil
  35. {
  36. Ref [_Stencil]
  37. Comp [_StencilComp]
  38. Pass [_StencilOp]
  39. ReadMask [_StencilReadMask]
  40. WriteMask [_StencilWriteMask]
  41. }
  42. Cull Off
  43. Lighting Off
  44. ZWrite Off
  45. ZTest [unity_GUIZTestMode]
  46. Blend SrcAlpha OneMinusSrcAlpha
  47. ColorMask [_ColorMask]
  48. Pass
  49. {
  50. Name "Default"
  51. CGPROGRAM
  52. #pragma vertex vert
  53. #pragma fragment frag
  54. #pragma target 2.0
  55. #include "UnityCG.cginc"
  56. #include "UnityUI.cginc"
  57. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  58. #pragma multi_compile __ COMPASS_FOG_OF_WAR
  59. #pragma multi_compile __ COMPASS_ROTATED
  60. struct appdata_t
  61. {
  62. float4 vertex : POSITION;
  63. float4 color : COLOR;
  64. float2 texcoord : TEXCOORD0;
  65. UNITY_VERTEX_INPUT_INSTANCE_ID
  66. };
  67. struct v2f
  68. {
  69. float4 vertex : SV_POSITION;
  70. fixed4 color : COLOR;
  71. float2 texcoord : TEXCOORD0;
  72. float4 worldPosition : TEXCOORD1;
  73. float2 mapUV : TEXCOORD2;
  74. #if COMPASS_FOG_OF_WAR
  75. float2 fogUV : TEXCOORD3;
  76. #endif
  77. UNITY_VERTEX_OUTPUT_STEREO
  78. };
  79. fixed4 _Color;
  80. fixed4 _TextureSampleAdd;
  81. float4 _ClipRect;
  82. float3 _UVOffset;
  83. sampler2D _FogOfWarTex, _NoiseTex;
  84. fixed4 _FogOfWarTintColor;
  85. float4 _UVFogOffset;
  86. float _Rotation;
  87. fixed3 _Effects;
  88. #if COMPASS_ROTATED
  89. float2 Rotate(float2 uv) {
  90. uv -= 0.5;
  91. float s, c;
  92. sincos(_Rotation, s, c);
  93. float2x2 rotationMatrix = float2x2(c, -s, s, c);
  94. uv = mul(uv, rotationMatrix);
  95. uv += 0.5;
  96. return uv;
  97. }
  98. #else
  99. #define Rotate(v) v
  100. #endif
  101. v2f vert(appdata_t IN)
  102. {
  103. v2f OUT;
  104. UNITY_SETUP_INSTANCE_ID(IN);
  105. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  106. OUT.worldPosition = IN.vertex;
  107. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  108. OUT.texcoord = IN.texcoord;
  109. float2 rotatedUV = Rotate(IN.texcoord);
  110. float2 uv = rotatedUV - _UVOffset.xy / _UVOffset.z;
  111. uv = (uv-0.5) * _UVOffset.z + 0.5;
  112. OUT.mapUV = uv;
  113. #if COMPASS_FOG_OF_WAR
  114. uv = rotatedUV - _UVFogOffset.xy;
  115. uv = (uv-0.5) * _UVFogOffset.zw + 0.5;
  116. OUT.fogUV = uv;
  117. #endif
  118. OUT.color = IN.color * _Color;
  119. return OUT;
  120. }
  121. sampler2D _MainTex, _MiniMapTex, _BorderTex;
  122. #if COMPASS_FOG_OF_WAR
  123. fixed4 GetFogOfWar(float2 uv) {
  124. fixed fogAlpha = tex2D (_FogOfWarTex, uv).a;
  125. half vxy = (uv.x + uv.y);
  126. half wt = _Time[1] * 0.5;
  127. half2 waveDisp1 = half2(wt + cos(wt+uv.y * 32.0) * 0.125, 0) * 0.05;
  128. fixed4 fog1 = tex2D(_NoiseTex, (uv + waveDisp1) * 8);
  129. wt *= 1.1;
  130. half2 waveDisp2 = half2(wt + cos(wt+uv.y * 8.0) * 0.5, 0) * 0.05;
  131. fixed4 fog2 = tex2D(_NoiseTex, (uv + waveDisp2) * 2);
  132. fixed4 fog = (fog1 + fog2) * 0.5;
  133. fog.rgb *= _FogOfWarTintColor;
  134. fog.a = fogAlpha;
  135. return fog;
  136. }
  137. #endif
  138. fixed4 frag(v2f IN) : SV_Target
  139. {
  140. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  141. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  142. #ifdef UNITY_UI_ALPHACLIP
  143. clip (color.a - 0.001);
  144. #endif
  145. fixed4 minimapTex = tex2D(_MiniMapTex, IN.mapUV);
  146. // Clip out of range area
  147. minimapTex *= max( abs(IN.mapUV.x - 0.5), abs(IN.mapUV.y - 0.5))< 0.499;
  148. #if COMPASS_FOG_OF_WAR
  149. // Apply fog of war?
  150. fixed4 fogOfWar = GetFogOfWar(IN.fogUV);
  151. minimapTex = minimapTex * (1.0 - fogOfWar.a) + fogOfWar * fogOfWar.a;
  152. #endif
  153. minimapTex.rgb = (minimapTex.rgb - 0.5.xxx) * _Effects.y + 0.5.xxx;
  154. minimapTex.rgb *= _Effects.x;
  155. // Mask & border
  156. color *= minimapTex * _Color;
  157. fixed4 border = tex2D(_BorderTex, IN.texcoord);
  158. color = lerp(color, border, border.a);
  159. return color;
  160. }
  161. ENDCG
  162. }
  163. }
  164. }