Shader "Law/Car" {
Properties{
_MainColor("MainColor",color) = (1,1,1,1)
_Color("Color",color) = (1,1,1,1)
_Center("Center",range(-4.1,2.1)) = 0
_R("R",range(0,1)) = 0.2
_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 _Center;
half _Glossiness;
half _Metallic;
float _R;
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 d = IN.vertex.x - _Center;//该点距离中心点的距离,有正负
float s = abs(d);
d = d / s; //取符号,正表示在上,负表示在下
float f = s / _R;
f = saturate(f);
d *= f;
d = d / 2 + 0.5;
o.Albedo *= lerp(_MainColor, _Color, d)*2;
}
ENDCG
}
FallBack "Diffuse"
}
unity 模型颜色渐变shader
最新推荐文章于 2025-05-24 08:37:04 发布