UIMask.shader 3.3 KB

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