代码如下:
Shader "Hidden/Loading_02"
{
Properties
{
_BgColor("BgColor", Color) = (1, 1, 1, 1)
_MainColor("MainColor", Color) = (1, 1, 1, 1)
_Radius ("Radius", Range(0, 0.5)) = 0.1
_CircleRadius("CircleRadius", Range(0, 0.5)) = 0.1
_AniRange ("AniRange", Range(0, 1)) = 0.1
_NormalRate ("NormalRate", Range(0, 1)) = 1
_Breath ("Breath", float) = 1
_Num ("Num", int) = 1
}
SubShader
{
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 _BgColor;
fixed4 _MainColor;
fixed _Radius;
fixed _CircleRadius;
fixed _Breath;
fixed _AniRange;
int _Num;
fixed _NormalRate;
fixed drawCircle(fixed radius, fixed2 uv)
{
fixed r = sqrt(uv.x * uv.x + uv.y * uv.y);
return step(r, radius);
}
fixed getZeroToOneLoop()
{
return fmod(_Time.y * _Breath, 1);
}
fixed4 frag (v2f i) : SV_Target
{
fixed2 newUv = i.uv - fixed2(0.5, 0.5);
float angle = 360.0 / _Num;
fixed curAngle = degrees(atan2(newUv.y, newUv.x)) + 360.0;
int interval = curAngle / angle;
fixed intervalAngle = radians((interval + 0.5) * angle);
fixed2 circleCenter = _Radius * fixed2(cos(intervalAngle), sin(intervalAngle));
fixed2 circleUv = newUv - circleCenter;
// 每个区间索引自增
interval += _Num * (1 - getZeroToOneLoop());
interval = fmod(interval, _Num);
int normalNum = _NormalRate * _Num;
int normalInterval = clamp(normalNum - 1, 0, _Num - 1);
// 画小圆
fixed scale = 1 + step(normalInterval, interval) * _AniRange * (interval - normalInterval);
fixed c = drawCircle(_CircleRadius * scale, circleUv);
_BgColor.a = c;
_MainColor.a = c;
return step(normalNum - 1, interval) * _MainColor + step(interval, normalNum - 1) * _BgColor;
}
ENDCG
}
}
}