Mask.shader 3.6 KB

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