A simple shader of Mana Wave Circle
A circular mana bar shader inspired by Hollow Knight, featuring a soft, dynamic wave that breathes over time. The wave height and motion can be adjusted via exposed parameters.
Designed to be applied to a Sprite2D node with a circular texture or mask. The wave distorts the upper edge to simulate a fluid, magical fill effect.
How to use:
Attach this shader to a Sprite2D node. Use a circular texture (or mask it appropriately). Adjust freq_times_PI, strength, wave_speed, and amp_osc_freq to customize the wave’s frequency, amplitude, speed, and oscillation behavior.
一个受《空洞骑士》启发的圆形法力槽 Shader,具备随时间轻柔波动的动态上缘。波形幅度与速度可调。
使用方法:
将此 Shader 挂载至 Sprite2D 节点上,并使用圆形贴图或遮罩。通过调节参数 freq_times_PI、strength、wave_speed 和 amp_osc_freq 来定制波形频率、强度与动态振幅变化。适用于制作圆形能量槽、法力槽等界面特效。
Shader code
shader_type canvas_item;
uniform float freq_times_PI : hint_range(0.0, 10.0) = 2.0;
uniform float strength : hint_range(0.0, 1.0) = 0.1;
uniform float center : hint_range(0.0, 1.0) = 0.5;
// 时间控制频率
uniform float wave_speed : hint_range(0.0, 10.0) = 1.0;
// 动态振幅的时间频率
uniform float amp_osc_freq : hint_range(0.0, 5.0) = 0.5;
bool draw_circle_polar(float radius,vec2 uv){
//把UV原点放到中间去,并且扩展成了原来的四倍大(从 [0,1]放大到了[-1,1])
vec2 centered_uv = (uv-0.5)*2.0;
//让我们复习一下极坐标。极坐标需要两个参数:长度和角度。
//这里的atan代表反正切,得到y/x的反正切值,就是一个角度。
vec2 polar = vec2(atan(centered_uv.y,centered_uv.x),length(centered_uv));
return polar.y < radius;//小于radius的渲染
}
bool wave(vec2 uv){
// 让振幅随时间在 -1 到 1 之间波动
float amp_mod = sin(TIME * amp_osc_freq);
// 真正的振幅 = strength * [-1, 1]
float dynamic_amp = strength * amp_mod;
float wave_y = dynamic_amp * sin(freq_times_PI * PI * uv.x + TIME * wave_speed) + (1.0-center);
return uv.y > wave_y;
}
void fragment() {
if (wave(UV)&&draw_circle_polar(0.8,UV)) {
COLOR = vec4(1.0);
} else {
COLOR = vec4(0.0);
}
}
