123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- Shader "DashGame/UIMask"
- {
- Properties
- {
- _MainTex("Texture", 2D) = "white" {}
- }
- SubShader
- {
- Tags
- {
- "Queue" = "Transparent"
- "RenderType" = "Transparent"
- "PreviewType" = "Plane"
- "IgnoreProjector" = "True"
- "CanUseSpriteAtlas" = "True"
- }
- Cull Off
- ZWrite Off
- Lighting Off
- Blend SrcAlpha OneMinusSrcAlpha
- ZTest[unity_GUIZTestMode]
- 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;
- };
- float _Angle;
- float _RadiusX;
- float _RadiusY;
- float2 _Center;
- float4 _MainTex_ST;
- sampler2D _MainTex;
- v2f vert(appdata v)
- {
- v2f o;
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.color = v.color;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.screenPos = ComputeScreenPos(o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- _Angle = _RadiusY/4;
- 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
- }
- }
- }
|