Loading效果之三Shader


代码如下:

Shader "Hidden/Loaing_03"
{
    Properties
    {
       _MainColor("MainColor", Color) = (1, 1, 1, 1)
	   _RectWidth("RectWidth", Range(0, 1)) = 0.1
	   _RectHeight("RectHeight", Range(0, 1)) = 0.1
	   _Spacing("Spacing", Range(0, 1)) = 0.1
	   _Wait("Wait", Range(0, 1)) = 0.1
	   _Scale("Scale", Range(0, 1)) = 0.1
	   _Breath("Breath", float) = 1
	   _Num("Num", int) = 1
	   _Dir("Dir", 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 _MainColor;
			fixed _RectWidth;
			fixed _RectHeight;
			fixed _Spacing;
			fixed _Breath;
			fixed _Scale;
			fixed _Wait;
			int _Num;
			int _Dir;

			fixed drawRect(fixed2 uv, fixed2 center, fixed2 size)
			{
				fixed2 newUv = uv - center;
				return step(-0.5 * size.x, newUv.x) * step(newUv.x, 0.5 * size.x) * step(-0.5 * size.y, newUv.y) * step(newUv.y, 0.5 * size.y);
			}


            fixed4 frag (v2f i) : SV_Target
            {
                fixed2 newUv = i.uv - fixed2(0.5, 0.5);

				// 显示区域长度
				fixed displayAreaWidth = (_RectWidth + _Spacing) * _Num - _Spacing;

				fixed x = newUv.x + displayAreaWidth * 0.5;

				int displayArea = step(0, x) * step(x, displayAreaWidth);

				fixed itemWidth = _RectWidth + _Spacing * (_Num - 1) / _Num;

				int index = x / itemWidth;

				x = index * _RectWidth + _RectWidth * 0.5 + index * _Spacing - displayAreaWidth * 0.5;

				fixed h = _RectHeight + _Dir * _Scale * sin(_Time.y * _Breath + radians(index * _Wait * 360));

				fixed rect = drawRect(newUv, fixed2(x, 0),fixed2(_RectWidth, h));
				
				_MainColor.a = rect * displayArea;

				return _MainColor;
			}
            ENDCG
        }
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值