UIMask.shader 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. Shader "DashGame/UIMask"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. Tags
  10. {
  11. "Queue" = "Transparent"
  12. "RenderType" = "Transparent"
  13. "PreviewType" = "Plane"
  14. "IgnoreProjector" = "True"
  15. "CanUseSpriteAtlas" = "True"
  16. }
  17. Cull Off
  18. ZWrite Off
  19. Lighting Off
  20. Blend SrcAlpha OneMinusSrcAlpha
  21. ZTest[unity_GUIZTestMode]
  22. Pass
  23. {
  24. CGPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27. #include "UnityUI.cginc"
  28. #include "UnityCG.cginc"
  29. struct appdata
  30. {
  31. float2 uv : TEXCOORD0;
  32. float4 color : COLOR;
  33. float4 vertex : POSITION;
  34. };
  35. struct v2f
  36. {
  37. float2 uv : TEXCOORD0;
  38. float4 color : COLOR;
  39. float4 vertex : SV_POSITION;
  40. float4 screenPos : TEXCOORD1;
  41. };
  42. float _Angle;
  43. float _RadiusX;
  44. float _RadiusY;
  45. float2 _Center;
  46. float4 _MainTex_ST;
  47. sampler2D _MainTex;
  48. v2f vert(appdata v)
  49. {
  50. v2f o;
  51. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  52. o.color = v.color;
  53. o.vertex = UnityObjectToClipPos(v.vertex);
  54. o.screenPos = ComputeScreenPos(o.vertex);
  55. return o;
  56. }
  57. fixed4 frag(v2f i) : SV_Target
  58. {
  59. _Angle = _RadiusY/4;
  60. fixed4 col = tex2D(_MainTex, i.uv)*i.color;
  61. float x = i.screenPos.x - _Center.x;
  62. float y = i.screenPos.y - _Center.y;
  63. if (abs(x) < _RadiusX && abs(y) < _RadiusY)
  64. {
  65. float2 ulo = _Center + float2(-_RadiusX, _RadiusY);
  66. float2 uli = ulo + float2(_Angle, -_Angle/(_ScreenParams.y/_ScreenParams.x));
  67. float2 uro = _Center + float2(_RadiusX, _RadiusY);
  68. float2 uri = uro + float2(-_Angle, -_Angle / (_ScreenParams.y / _ScreenParams.x));
  69. float2 lro = _Center + float2(_RadiusX, -_RadiusY);
  70. float2 lri = lro + float2(-_Angle, _Angle / (_ScreenParams.y / _ScreenParams.x));
  71. float2 llo = _Center + float2(-_RadiusX, -_RadiusY);
  72. float2 lli = llo + float2(_Angle, _Angle / (_ScreenParams.y / _ScreenParams.x));
  73. float urox = uro.x - i.screenPos.x;
  74. float urix = i.screenPos.x - uri.x;
  75. float uroy = uro.y - i.screenPos.y;
  76. float uriy = i.screenPos.y - uri.y;
  77. float ulox = i.screenPos.x - ulo.x;
  78. float ulix = uli.x - i.screenPos.x;
  79. float uloy = ulo.y - i.screenPos.y;
  80. float uliy = i.screenPos.y - uli.y;
  81. float lrox = lro.x - i.screenPos.x;
  82. float lrix = i.screenPos.x - lri.x;
  83. float lroy = i.screenPos.y - lro.y;
  84. float lriy = lri.y - i.screenPos.y;
  85. float llox = i.screenPos.x - llo.x;
  86. float llix = lli.x - i.screenPos.x;
  87. float lloy = i.screenPos.y - llo.y;
  88. float lliy = lli.y - i.screenPos.y;
  89. if(ulox > 0 && ulix > 0 && uloy > 0 && uliy > 0)
  90. {
  91. float2 vec = uli - i.screenPos;
  92. vec.y *= _ScreenParams.y / _ScreenParams.x;
  93. if (length(vec) < _Angle)
  94. {
  95. col.a = 0;
  96. }
  97. }
  98. else if(urox > 0 && urix > 0 && uroy > 0 && uriy > 0)
  99. {
  100. float2 vec = uri - i.screenPos;
  101. vec.y *= _ScreenParams.y / _ScreenParams.x;
  102. if (length(vec) < _Angle)
  103. {
  104. col.a = 0;
  105. }
  106. }
  107. else if (lrox > 0 && lrix > 0 && lroy > 0 && lriy > 0)
  108. {
  109. float2 vec = lri - i.screenPos;
  110. vec.y *= _ScreenParams.y / _ScreenParams.x;
  111. if (length(vec) < _Angle)
  112. {
  113. col.a = 0;
  114. }
  115. }
  116. else if (llox > 0 && llix > 0 && lloy > 0 && lliy > 0)
  117. {
  118. float2 vec = lli - i.screenPos;
  119. vec.y *= _ScreenParams.y / _ScreenParams.x;
  120. if (length(vec) < _Angle)
  121. {
  122. col.a = 0;
  123. }
  124. }
  125. else
  126. {
  127. col.a = 0;
  128. }
  129. }
  130. return col;
  131. }
  132. ENDCG
  133. }
  134. }
  135. }