I have a white circle sprite. I know how to change its color to a solid fill color. using GetComponent<Renderer>().material.color
.
But how would I give it a gradient fill color.
I've been trying to do this with a shader. But so far the shader I've created doesn't take the circle sprite into account, simply its bounding box. It also looks a bit weird.
here's my shader code
Shader "Custom/SpriteGradient" {
Properties {
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Left Color", Color) = (1,1,1,1)
_Color2 ("Right Color", Color) = (1,1,1,1)
_Scale ("Scale", Float) = 1
}
SubShader {
Tags {"Queue"="Background" "IgnoreProjector"="True"}
LOD 100
ZWrite On
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
fixed4 _Color2;
fixed _Scale;
struct v2f {
float4 pos : SV_POSITION;
fixed4 col : COLOR;
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.col = lerp(_Color,_Color2, v.texcoord.x );
return o;
}
float4 frag (v2f i) : COLOR {
float4 c = i.col;
c.a = 1;
return c;
}
ENDCG
}
}
}