Unity Shader 圆心颜色渐变扩散shader

5 篇文章 0 订阅
4 篇文章 0 订阅

在这里插入图片描述

Shader "Custom/ColorDiffusion" {
    Properties{
        _MainColor("MainColor",color) = (1,1,1,1)
        _Color("Color",color) = (1,1,1,1)
        _Speed("_Speed",float) = 1
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
        _Radius("Radius",Float) = 1 //扩散半径
    }
    SubShader{
        Tags{ "RenderType" = "Opaque" }
        
        CGPROGRAM
        #pragma surface surf Standard vertex:vert
        
        fixed4 _Color;
        fixed4 _MainColor;
        float _CenterX;
        float _CenterY;
        float _Speed;
        float _Radius;
        half _Glossiness;
        half _Metallic;
        sampler2D _MainTex;
        
        struct Input {
            float2 uv_MainTex;
            float4 vertex;
        };
        //
        void vert(inout appdata_full v,out Input o)
        {
            o.uv_MainTex = v.texcoord.xy;
            o.vertex = v.vertex;
        }
        
        
        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
            float x = (IN.vertex.x/_Radius);//该点距离中心点的距离,有正负
            float y = (IN.vertex.z/_Radius);//该点距离中心点的距离,有正负
            float t = (_Time.y*_Speed)%2; //第一秒颜色1到颜色2,第二秒颜色2到颜色1,如此轮回
            float t2 = t%1; //过度插值时间
            float d = sqrt((x*x)+(y*y));  //当前粒子位置

            d = d>t2?(d - t2):-(d-t2); //当前粒子颜色插值

            o.Albedo =(t>1?lerp(_Color, _MainColor, d): lerp(_MainColor, _Color, d))*2; //赋值
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Cocos+u3d开发交流群:521643513

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值