1、替换颜色

Unity Shader (五)Surface Shader示例-LMLPHP

Shader "Custom/Example_Frag_5" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainColor("MainColor",color)=(,,,)
_SecondColor("SecondColor",color)=(,,,)
_Center("Center",range(-2.7,2.7))=
_R("R",range(,0.5))=0.2 //颜色渐变的半径
_Glossiness ("Smoothness", Range(,)) = 0.5
_Metallic ("Metallic", Range(,)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD CGPROGRAM #pragma surface surf Standard vertex:vert fullforwardshadows #pragma target 3.0 sampler2D _MainTex;
half _Glossiness;
half _Metallic;
float4 _MainColor;
float4 _SecondColor;
float _R;
float _Center; struct Input {
float2 uv_MainTex;
float x;
}; void vert(inout appdata_full v,out Input o)
{
o.uv_MainTex=v.texcoord.xy;
o.x=v.vertex.x;
} void surf (Input IN, inout SurfaceOutputStandard o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a; float d=IN.x-_Center;
float s=abs(d);
d=d/s;
float f=s/_R;
f=saturate(f);
d*=f;
d=d/+0.5;
o.Albedo*=lerp(_MainColor,_SecondColor,d)*;
}
ENDCG
}
FallBack "Diffuse"
}
05-28 14:21