Shader "DashGame/Mask" { Properties { _Color("Tint", Color) = (1,1,1,1) [MaterialToggle] PixelSnap("Pixel snap", Float) = 0 [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} } SubShader { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "PreviewType" = "Plane" "IgnoreProjector" = "True" "CanUseSpriteAtlas" = "True" } Cull Off ZWrite Off Lighting Off Pass { Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ ETC1_EXTERNAL_ALPHA #include "UnityCG.cginc" struct appdata_t { float4 color : COLOR; float4 vertex : POSITION; float2 texcoord : TEXCOORD0; }; struct v2f { fixed4 color : COLOR; float4 vertex : SV_POSITION; float2 texcoord : TEXCOORD0; float4 screenPos : TEXCOORD1; }; float _Angle; float _RadiusX; float _RadiusY; float2 _Center; fixed4 _Color; sampler2D _MainTex; v2f vert(appdata_t IN) { v2f OUT; OUT.color = IN.color * _Color; OUT.vertex = UnityObjectToClipPos(IN.vertex); OUT.texcoord = IN.texcoord; OUT.screenPos = ComputeScreenPos(OUT.vertex); return OUT; } fixed4 SampleSpriteTexture(float2 uv) { fixed4 color = tex2D(_MainTex, uv); return color; } fixed4 frag(v2f i) : SV_Target { fixed4 col = SampleSpriteTexture(i.texcoord) * i.color; _Angle = _RadiusY / 4; float x = i.screenPos.x - _Center.x; float y = i.screenPos.y - _Center.y; if (abs(x) < _RadiusX && abs(y) < _RadiusY) { float2 ulo = _Center + float2(-_RadiusX, _RadiusY); float2 uli = ulo + float2(_Angle, -_Angle / (_ScreenParams.y / _ScreenParams.x)); float2 uro = _Center + float2(_RadiusX, _RadiusY); float2 uri = uro + float2(-_Angle, -_Angle / (_ScreenParams.y / _ScreenParams.x)); float2 lro = _Center + float2(_RadiusX, -_RadiusY); float2 lri = lro + float2(-_Angle, _Angle / (_ScreenParams.y / _ScreenParams.x)); float2 llo = _Center + float2(-_RadiusX, -_RadiusY); float2 lli = llo + float2(_Angle, _Angle / (_ScreenParams.y / _ScreenParams.x)); float urox = uro.x - i.screenPos.x; float urix = i.screenPos.x - uri.x; float uroy = uro.y - i.screenPos.y; float uriy = i.screenPos.y - uri.y; float ulox = i.screenPos.x - ulo.x; float ulix = uli.x - i.screenPos.x; float uloy = ulo.y - i.screenPos.y; float uliy = i.screenPos.y - uli.y; float lrox = lro.x - i.screenPos.x; float lrix = i.screenPos.x - lri.x; float lroy = i.screenPos.y - lro.y; float lriy = lri.y - i.screenPos.y; float llox = i.screenPos.x - llo.x; float llix = lli.x - i.screenPos.x; float lloy = i.screenPos.y - llo.y; float lliy = lli.y - i.screenPos.y; if (ulox > 0 && ulix > 0 && uloy > 0 && uliy > 0) { float2 vec = uli - i.screenPos; vec.y *= _ScreenParams.y / _ScreenParams.x; if (length(vec) < _Angle) { col.a = 0; } } else if (urox > 0 && urix > 0 && uroy > 0 && uriy > 0) { float2 vec = uri - i.screenPos; vec.y *= _ScreenParams.y / _ScreenParams.x; if (length(vec) < _Angle) { col.a = 0; } } else if (lrox > 0 && lrix > 0 && lroy > 0 && lriy > 0) { float2 vec = lri - i.screenPos; vec.y *= _ScreenParams.y / _ScreenParams.x; if (length(vec) < _Angle) { col.a = 0; } } else if (llox > 0 && llix > 0 && lloy > 0 && lliy > 0) { float2 vec = lli - i.screenPos; vec.y *= _ScreenParams.y / _ScreenParams.x; if (length(vec) < _Angle) { col.a = 0; } } else { col.a = 0; } } return col; } ENDCG } } }