Unity3D攻击范围光圈Shader实现(UGUI)

在Unity的UGUI下用Shader实现的攻击范围光圈效果

fixed4 frag(v2f IN) : COLOR
		{
			 half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;

			 //以纹理中心为中心
			 float radius = 0.5;
			 float2 center = float2(radius, radius);
			 float2 dir = center - IN.texcoord.xy;
			 float dis = length(dir);

			 color.a *= 1 - step(radius, dis);
			

			 #ifdef UNITY_UI_CLIP_RECT
			 color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
			 #endif

			 #ifdef UNITY_UI_ALPHACLIP
			 clip(color.a - 0.001);
			 #endif

			 if (dis - _Radius < 0) {
				 color.a *= 0.015;
			 }
			 else {
				 float bezieratT = (dis - _Radius) / (0.5 - _Radius);
				 color.a *= GetBezierat(bezieratT).y/ _AlphaAppend;
				 //color.a *= bezieratT;
			 }

			 return color;
		}

边上光圈的透明度采用先慢后快的贝塞尔曲线来过度

float2 GetBezierat(float t) {
			_BezieratP1 = (0, 0);
			_BezieratP2 = (6, 0);
			_BezieratP3 = (10, 0);
			_BezieratP4 = (11, 5);
			return pow(1 - t, 3)*_BezieratP1 + 3 * t*pow(1 - t, 2)*_BezieratP2 + 3 * pow(t, 2)*(1 - t)*_BezieratP3 + pow(t, 3)*_BezieratP4;
		}

 工程地址:

Unity攻击范围光圈Shader实现(UGUI)-Unity3D文档类资源-CSDN下载

猜你喜欢

转载自blog.csdn.net/waterdsm/article/details/124865003
今日推荐