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