Unity Text 透明

Unity Text透明化问题

Shader "UI/TextBlend"
{
    Properties
    {
        [HideInInspector]_MainTex ("Texture", 2D) = "white" {}
        [HideInInspector]_BlendTex("Blend Tex", 2D) = "white" {}
        _Color("Text Color", Color) = (1,1,1,1)
 
        _Width (" Width", Range(0, 4096)) = 0
        _Height (" Height", Range(0, 4096)) = 0

        _R ("Radius", Range(0, 6)) = 0.1
		_X ("OffsetX", Range(-1, 1)) = 0.5
		_Y ("OffsetY", Range(-1, 1)) = 0.5
		_ScaleX ("ScaleX", Range(0, 10)) = 1
		_ScaleY ("ScaleY", Range(0, 20)) = 1
		_ExpandLen ("_ExpandLen", Range(0, 100)) = 1
    }
    SubShader
    {
        // No culling or depth
     	Tags { 	"Queue"="Transparent" 
				"IgnoreProjector"="True" 
				"RenderType"="Transparent" 
		}

		Cull Off
		ZWrite Off
		Lighting Off
		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 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                float4 v : TEXCOORD1;
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.v = v.vertex;
                o.uv = v.uv;
                return o;
            }

            sampler2D _MainTex;
            sampler2D _BlendTex;
            float4 _MainTex_TexelSize;
            fixed4 _Color;
        

            float _Width;
            float _Height;

      	    float _R;
			float _X;
			float _Y;
			float _ScaleX;
			float _ScaleY;
			float _ExpandLen;
        
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                col.rgb = _Color.rgb;
               

               fixed newU = i.v.x / _Width;
               fixed newV = i.v.y / _Height;
               //fixed4 texColor = tex2D(_BlendTex, fixed2(newU + _flipX / 100, newV + _flipY / 100));
               //clip(texColor.a - 0.1);
               //fixed clipAlpha = texColor.a;
               //col.a = clipAlpha * col.a;

               	float x = (newU - _X) *_ScaleX;
				float y = (newV - _Y) *_ScaleY;
				float S = sqrt(x * x + y * y);
				float k = pow(2, S/_R * -4) * _ExpandLen;
				float clipAlpha = clamp(0, 1, k);
                col.a = clipAlpha * col.a;
                return col ;
            }
            ENDCG
        }
    }
}


效果:  
![效果图](https://img-blog.csdnimg.cn/d6e724bfff8a40a48d14225009d6a8d1.png#pic_center)

猜你喜欢

转载自blog.csdn.net/qq_36460731/article/details/129444987
今日推荐