Gradient.shader 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Shader "Text/Gradient" {
  2. Properties {
  3. _MainTex ("Font Texture", 2D) = "white" {}
  4. _Color ("Text Color", Color) = (1,1,1,1)
  5. _Color1 ("Color 1", Color) = (1,0,0,1)
  6. _Color2 ("Color 2", Color) = (0,0,1,1)
  7. }
  8. SubShader {
  9. Tags { "Queue"="Transparent" }
  10. Lighting Off Cull Off ZWrite Off Fog { Mode Off }
  11. Blend SrcAlpha OneMinusSrcAlpha
  12. Pass {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #include "UnityCG.cginc"
  17. struct appdata_t {
  18. float4 vertex : POSITION;
  19. fixed4 color : COLOR;
  20. float2 texcoord : TEXCOORD0;
  21. };
  22. struct v2f {
  23. float4 vertex : SV_POSITION;
  24. fixed4 color : COLOR;
  25. float2 texcoord : TEXCOORD0;
  26. };
  27. sampler2D _MainTex;
  28. float4 _MainTex_ST;
  29. fixed4 _Color;
  30. fixed4 _Color1;
  31. fixed4 _Color2;
  32. v2f vert (appdata_t v) {
  33. v2f o;
  34. o.vertex = UnityObjectToClipPos(v.vertex);
  35. o.color = v.color * _Color;
  36. o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  37. return o;
  38. }
  39. fixed4 frag (v2f i) : SV_Target {
  40. fixed4 col = tex2D(_MainTex, i.texcoord);
  41. col *= i.color;
  42. float lerpFactor = i.texcoord.x; // 可以根据需要调整渐变方向和方式,这里使用x坐标作为示例
  43. col.rgb = lerp(col.rgb * _Color1.rgb, col.rgb * _Color2.rgb, lerpFactor);
  44. return col;
  45. }
  46. ENDCG
  47. }
  48. }
  49. }