xiandie/scene/shading/ghost.gdshader

49 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

shader_type canvas_item;
uniform float time_scale : hint_range(0.1, 5.0) = 1.0;
uniform float fog_intensity : hint_range(0.0, 1.0) = 0.8;
// 噪声函数
float noise(vec2 uv) {
return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453);
}
float fbm(vec2 uv) {
float value = 0.0;
float amplitude = 0.5;
float frequency = 1.0;
for(int i = 0; i < 4; i++) {
value += amplitude * noise(uv * frequency);
amplitude *= 0.5;
frequency *= 2.0;
}
return value;
}
void fragment() {
vec2 uv = UV;
float time = TIME * time_scale;
float sin_time_x = sin(time * 2.1) * 0.15 + 2.0;
float sin_time_y = sin(time * 3.5) * 0.15 + 2.0;
// 基础轮廓
vec2 center = vec2(0.5, 0.5); // 重心稍微偏上
float body_shape = 1.0 - length((uv - center) * vec2(sin_time_x, sin_time_y));
float base_shape = smoothstep(0.0, 0.8, body_shape);
// 飘动的雾气效果
float fog_noise = fbm(uv * 5.0 + vec2(time * 0.3, time * 0.2));
fog_noise = mix(fog_noise, fbm(uv * 9.0 - vec2(time * 0.4, 0.0)), 0.5);
// 组合形状和噪声
float final_alpha = base_shape * fog_noise * fog_intensity;
//// 添加边缘发光效果
//float edge_glow = 0.6 - smoothstep(0.0, 0.4, abs(base_shape - 0.3));
//final_alpha += edge_glow * 0.02;
// 最终颜色
COLOR.rgb = vec3(0.0);
COLOR.a = final_alpha * 2.5;
}