Shader 等待界面的圈圈 (二)

照例先放效果

shader代码

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
        }
    }
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值