Shader "UI/CircleDissolveEffect" { Properties { _MainTex("Main Texture", 2D) = "white" {} _Center("Dissolve Center", Vector) = (0.5, 0.5, 0, 0) _Radius("Dissolve Radius", Range(0, 1)) = 0.5 _EdgeWidth("Edge Width", Range(0, 0.1)) = 0.05 _EdgeColor("Edge Color", Color) = (1,1,1,1) _AspectRatio("Aspect Ratio", Float) = 1.0 } SubShader { Tags {"Queue" = "Transparent" "RenderType" = "Transparent"} LOD 100 Blend SrcAlpha OneMinusSrcAlpha Cull Off ZWrite Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float2 _Center; float _Radius; float _EdgeWidth; fixed4 _EdgeColor; float _AspectRatio; v2f vert(appdata_t v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag(v2f i) : SV_Target { float2 uv = i.uv; fixed4 mainColor = tex2D(_MainTex, uv); // 调整 UV 坐标的比例,使得圆形遮罩在非方形图片上保持为圆形 float2 adjustedUV = uv; adjustedUV.x = (uv.x - _Center.x) * _AspectRatio + _Center.x; // 计算当前像素到遮罩中心的距离 float dist = distance(adjustedUV, _Center); // 根据距离和半径计算溶解值 float dissolveThreshold = smoothstep(_Radius - _EdgeWidth, _Radius, dist); // 混合边缘颜色 fixed4 edgeColor = _EdgeColor * (1.0 - dissolveThreshold); // 应用溶解效果 return lerp(edgeColor, mainColor, dissolveThreshold) * mainColor.a; } ENDCG } } FallBack "Diffuse" }