Shader "Text/Gradient" { Properties { _MainTex ("Font Texture", 2D) = "white" {} _Color ("Text Color", Color) = (1,1,1,1) _Color1 ("Color 1", Color) = (1,0,0,1) _Color2 ("Color 2", Color) = (0,0,1,1) } SubShader { Tags { "Queue"="Transparent" } Lighting Off Cull Off ZWrite Off Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _Color; fixed4 _Color1; fixed4 _Color2; v2f vert (appdata_t v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.color = v.color * _Color; o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.texcoord); col *= i.color; float lerpFactor = i.texcoord.x; // 可以根据需要调整渐变方向和方式,这里使用x坐标作为示例 col.rgb = lerp(col.rgb * _Color1.rgb, col.rgb * _Color2.rgb, lerpFactor); return col; } ENDCG } } }