画图shader

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
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值