Mask.shader 3.7 KB

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