unity 扫描圈 圆扩展方法

unity 扫描圈 圆扩展方法

请添加图片描述工程文件下载地址

完整shader代码

Shader "SongShaderDemo/RadiationCircle"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
	    _CentorPoint("CentrePoint",Vector)= (0, 0, 0, 0)
		_Dis("Float", Float) = 30//最大距离
		_Range("Range", Range(0, 1.0)) = 0.01//移动范围
		_LineWide("LineWide", Range(0, 1)) = 0.001//线宽
		_Color("color",Color) = (1,1,1,1)   //颜色,一般用fixed4
		_TransColor("TransColor",Color) = (1,1,1,0)   //颜色,一般用fixed4
		_FillTex("FillTexture", 2D) = "white" {}
		_FillColor("FillColor",Color) = (1,1,1,1)   //颜色,一般用fixed4
    }
    SubShader
    {
        Tags { "RenderType" = "Transparent" "IgnoreProjector" = "True" "Queue" = "Transparent" }
        LOD 100
	    Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
		
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
				float2 uv0 : TEXCOORD0;
                float2 uv : TEXCOORD2;
                float4 vertex : SV_POSITION;
				float3 worldPos : TEXCOORD3;
            };
			CBUFFER_START(UnityPerMaterial)
			sampler2D _MainTex;
			float4 _MainTex_ST;
			sampler2D _FillTex;
			fixed4 _FillColor;
            float4 _FillTex_ST;
			float4 _CentorPoint;
			float _Dis;
			float _Range;
			float _LineWide;
			fixed4 _Color;
			fixed4 _TransColor;
			CBUFFER_END
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _FillTex);
				o.uv0 = TRANSFORM_TEX(v.uv, _MainTex);
				o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
			     fixed4 col = tex2D(_MainTex, i.uv0);
				float dis = distance(i.worldPos, _CentorPoint.xyz);
			    float rangeMax = _Dis * _Range ;
			    float rangeMin = (_Dis)*_Range - _LineWide;
				fixed4 Circle= _TransColor;
				fixed4 FillCol = _TransColor;
				if (dis> rangeMin&&dis< rangeMax)
	            {
					Circle= fixed4(_Color.xyz, ((dis - rangeMin) / _LineWide)*(1 - _Range));
	             }
				if (dis < rangeMin)
				{
					fixed4 FillTex = tex2D(_FillTex, i.uv);
					if (FillTex.w!=0)
					{
						FillCol = fixed4(FillTex.xyz, (1 - _Range)) + _FillColor;
					}
					else
					{
						FillCol = FillTex + _FillColor;
					}
					
				}
				fixed4 all = Circle + FillCol;
				return  all*all.w+ col*(1- all.w);
            }
            ENDCG
        }
			
    }
}
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小生云木

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值