D3/Char/Char_Components/After_Image/player_dash.gdshader
2025-05-10 23:19:52 +08:00

78 lines
3.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

shader_type canvas_item;
uniform bool time_slowed = false;
uniform float effect_mixture : hint_range(0.0, 1.0) = 0.0;
uniform float alpha_multiplier = 1.0;
uniform float color_offset = 0.0; // 颜色偏移值
uniform float glow_intensity = 1.2;
uniform float inner_glow_width = 0.5;
uniform float outer_glow_width = 2.0;
uniform float pulse_speed = 2.0;
uniform float pulse_strength = 0.2;
uniform bool high_quality = true; // 性能开关
// HSV转RGB函数
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void fragment() {
vec4 texture_color = texture(TEXTURE, UV);
if (texture_color.a > 0.0) {
vec3 blue_base = vec3(0.2, 0.6, 1.5);
float luminance = dot(texture_color.rgb, vec3(0.299, 0.587, 0.114));
// 脉冲动画效果
float pulse = (sin(TIME * pulse_speed) * 0.5 + 0.5) * pulse_strength;
// 内发光效果
float inner_glow = pow(luminance, inner_glow_width) * glow_intensity;
// 外发光效果
float outer_glow = 0.0;
if (high_quality) {
// 高质量模式 - 完整采样
vec2 size = 1.0 / TEXTURE_PIXEL_SIZE;
vec2 pixel_size = 1.0 / size;
for(float x = -outer_glow_width; x <= outer_glow_width; x += 1.0) {
for(float y = -outer_glow_width; y <= outer_glow_width; y += 1.0) {
vec2 offset = vec2(x, y) * pixel_size;
float sample_alpha = texture(TEXTURE, UV + offset).a;
float distance = length(vec2(x, y)) / outer_glow_width;
outer_glow += sample_alpha * (1.0 - distance);
}
}
outer_glow = outer_glow / (outer_glow_width * outer_glow_width * 4.0);
} else {
// 性能模式 - 简化采样
float sample_distance = outer_glow_width * 0.5;
vec2 pixel_size = 1.0 / (1.0 / TEXTURE_PIXEL_SIZE);
for(float i = 0.0; i < 4.0; i++) {
float angle = i * PI * 0.5;
vec2 offset = vec2(cos(angle), sin(angle)) * sample_distance * pixel_size;
outer_glow += texture(TEXTURE, UV + offset).a;
}
outer_glow = outer_glow * 0.25;
}
float total_glow = inner_glow + outer_glow + pulse;
// 基于color_offset生成颜色范围集中在黄色系
float hue = fract(color_offset) * 0.4 + 0.1; // 0.1-0.5范围,集中在黄色区域
vec3 rainbow_color = hsv2rgb(vec3(hue, 0.9, 0.95)); // 高饱和度,稍微降低亮度
// 混合发光效果
vec3 final_color = mix(blue_base, rainbow_color, total_glow);
final_color += rainbow_color * total_glow * 0.5;
// 最终颜色混合
vec3 mixed_color = mix(texture_color.rgb, final_color, effect_mixture);
COLOR = vec4(mixed_color, texture_color.a * alpha_multiplier);
} else {
COLOR = vec4(texture_color.rgb, texture_color.a * alpha_multiplier);
}
}