Unity Shader 圆心颜色渐变扩散shader

在这里插入图片描述

Shader "Custom/ColorDiffusion" {
    
    
    Properties{
    
    
        _MainColor("MainColor",color) = (1,1,1,1)
        _Color("Color",color) = (1,1,1,1)
        _CenterX("CenterX",range(-4.1,2.1)) = 0
        _CenterY("CenterY",range(-4.1,2.1)) = 0
        _Speed("_Speed",float) = 1
        _Glossiness("Smoothness", Range(0,1)) = 0.5
        _Metallic("Metallic", Range(0,1)) = 0.0
    }
    SubShader{
    
    
        Tags{
    
     "RenderType" = "Opaque" }
        
        CGPROGRAM
        #pragma surface surf Standard vertex:vert
        
        fixed4 _Color;
        fixed4 _MainColor;
        float _CenterX;
        float _CenterY;
        float _Speed;
        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 - _CenterX);//该点距离中心点的距离,有正负
            float y = (IN.vertex.z - _CenterY);//该点距离中心点的距离,有正负
            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"
}

猜你喜欢

转载自blog.csdn.net/weixin_40137140/article/details/109365548