1.画圈 内外渐变色 可调整片段
Shader "ring"
{
Properties
{
_Color1 ("Color1", Color) = (1,1,1,1) //内圈颜色
_Color2 ("Color2", Color) = (1,1,1,1) //外圈颜色
_ColorLerp ("ColorLerp", Range(0,2)) = 0
_MaxRadius ("MaxRadius", Range(0,0.5)) = 0.5
_MinRadius ("MinRadius", Range(0,0.5)) = 0.4
_DiscarRange ("DiscarRange", Range(0,1)) = 0
}
SubShader
{
Tags { "Queue"="Transparent" }
LOD 100
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
half4 _Color1;
half4 _Color2;
half _MaxRadius;
half _MinRadius;
half _DiscarRange;
half _ColorLerp;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
half2 uv = i.uv;
uv -= 0.5;
half uvLen = length(uv);
half dis = _MaxRadius-uvLen;
clip(dis); //clip(x) x小于0则丢弃图元
dis = uvLen-_MinRadius;
clip(dis);
dis = 0-step(_DiscarRange,(atan2(uv.y,uv.x)/3.141+1)/2); //step(a,b) a小于b则返回0否则返回1
clip(dis);
half len = _MaxRadius - _MinRadius;
half idx = uvLen - _MinRadius;
half4 col = lerp(_Color1,_Color2,pow(idx/len,_ColorLerp)); //pow(a,b) a的b次方
return col;
}
ENDCG
}
}
}