Shader "DashGame/UIMask" { Properties { _MainTex("Texture", 2D) = "white" {} } SubShader { Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" } Cull Off Lighting Off ZWrite Off ZTest[unity_GUIZTestMode] Blend SrcAlpha OneMinusSrcAlpha Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityUI.cginc" #include "UnityCG.cginc" struct appdata { float2 uv : TEXCOORD0; float4 color : COLOR; float4 vertex : POSITION; }; struct v2f { float2 uv : TEXCOORD0; float4 color : COLOR; float4 vertex : SV_POSITION; float4 screenPos : TEXCOORD1; }; sampler2D _MainTex; float4 _MainTex_ST; float _Angle; float _RadiusX; float _RadiusY; float2 _Center; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.screenPos = ComputeScreenPos(o.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.color = v.color; return o; } fixed4 frag(v2f i) : SV_Target { //_Center = float2(0.5,0.5); _Angle = _RadiusY/4; //_RadiusX = 0.2; //_RadiusY = 0.2; fixed4 col = tex2D(_MainTex, i.uv)*i.color; 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 } } }