Shader waits for the circle of the interface (2)

As usual, put the effect first

shader code

Shader "Hidden/Loading bar"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Color1("Color1",Color) = (1,1,1,1)
        _Color2("Color2",Color) = (1,1,1,1)
        _RingColor("_RingColor",Color) = (1,1,1,1)
        _Speed("Speed",float) = 1
        _Radiu("Radiu",Range(0.01,0.5)) = 0.25
        _Width("Width",Range(0.01,0.5)) = 0.1
        _Interval("Interval",Range(1,20)) = 8        
    }
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        Tags{"Queue"="Transparent"}

        Pass
        {
            CGPROGRAM
            
  
                        
            #pragma vertex vert
            #pragma fragment frag
            #define PI 3.1415926
            #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;
            }

            sampler2D _MainTex;
            fixed4 _Color1;
            fixed4 _Color2;
            fixed4 _RingColor;
            fixed _Radiu;
            fixed _Width;
            fixed _Interval;
            fixed _Speed;

            fixed4 frag (v2f i) : SV_Target
            {
                fixed2 uv = i.uv -0.5;
                fixed distance = length(uv);
      
                //ring
                fixed ring = (1  - smoothstep(_Radiu,_Radiu,distance)) * smoothstep(_Radiu - _Width,_Radiu - _Width,distance);
                
                //interval
                fixed angle = atan2(uv.x,uv.y) / PI * _Interval;
                fixed fract = frac(angle);
                fixed interval = 1 - step(smoothstep(0,0.1,fract) * smoothstep(1,0.9,fract),0.1);
                
                //light
                angle = floor(fmod( _Time.y * _Speed,_Interval * 2)) * PI / _Interval;
                uv = mul(uv,float2x2(cos(angle),sin(angle),-sin(angle),cos(angle)));
                fixed lightEnd = atan2(uv.x,uv.y);     
                angle = PI /_Interval;
                uv = mul(uv,float2x2(cos(angle),sin(angle),-sin(angle),cos(angle)));
                fixed lightStart = atan2(uv.x,uv.y);           
                fixed light = sign(lightStart - lightEnd) * smoothstep(_Radiu-_Width,_Radiu,length(uv));
                
                //color
                fixed ringColorMask = step(lightStart - lightEnd,1) *  ring * interval;
                fixed4 ringCol = _RingColor * ringColorMask;
                
                fixed tickColorMask = (1 - ringColorMask) * ring * interval;
                fixed4 tickColor = lerp(_Color1,_Color2,light) * tickColorMask;
   
                return tickColor + ringCol;
            }
            ENDCG
        }
    }
}

 

Guess you like

Origin blog.csdn.net/chooselove/article/details/106403143