77 lines
2.1 KiB
Plaintext
77 lines
2.1 KiB
Plaintext
Shader "Custom/GlowText"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex ("Base (RGB)", 2D) = "white" {}
|
|
_GlowColor ("Glow Color", Color) = (1, 1, 1, 1)
|
|
_GlowIntensity ("Glow Intensity", Float) = 1.0
|
|
_GlowRadius ("Glow Radius", Float) = 0.1
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "Queue"="Overlay" }
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
|
|
struct appdata_t
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float4 pos : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
// 材质属性
|
|
sampler2D _MainTex;
|
|
float4 _GlowColor;
|
|
float _GlowIntensity;
|
|
float _GlowRadius;
|
|
|
|
// 简单的距离函数来计算发光效果
|
|
float DistanceToEdge(float2 uv)
|
|
{
|
|
// 假设文本为白色,透明背景,计算距离非透明区域
|
|
float alpha = tex2D(_MainTex, uv).a;
|
|
return alpha;
|
|
}
|
|
|
|
v2f vert(appdata_t v)
|
|
{
|
|
v2f o;
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.uv;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(v2f i) : COLOR
|
|
{
|
|
// 获取原始文本的颜色
|
|
half4 texColor = tex2D(_MainTex, i.uv);
|
|
|
|
// 如果文本是透明的,则返回原色
|
|
if (texColor.a < 0.1)
|
|
return texColor;
|
|
|
|
// 计算周围区域的发光强度
|
|
float glowFactor = 1.0 - DistanceToEdge(i.uv); // 离边缘越远,发光越强
|
|
|
|
// 高亮效果
|
|
half4 glow = _GlowColor * _GlowIntensity * glowFactor;
|
|
|
|
// 输出最终的颜色(包含文本本身的颜色和边缘发光效果)
|
|
return texColor + glow;
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
FallBack "Diffuse"
|
|
}
|