A simple shader to make hit/damage effect on sprite
shader_type canvas_item;
uniform float hit_flash_duration : hint_range(0.0, 1.0) = 0.2;
uniform float hit_intensity : hint_range(0.0, 2.0) = 1.5;
// Change 'hint_color' to 'source_color'
uniform vec3 hit_color : source_color = vec3(1.0, 1.0, 1.0);
uniform float hit_timer : hint_range(0.0, 1.0) = 0.0;
void fragment() {
vec4 color = texture(TEXTURE, UV);
// Calculate damage effect
float damage_effect = smoothstep(hit_flash_duration, 0.0, hit_timer);
// White flash effect
vec3 flash = mix(color.rgb, hit_color, damage_effect * hit_intensity);
// Screen shake distortion
float shake = sin(hit_timer * 50.0) * damage_effect * 0.02;
vec2 distorted_uv = UV + vec2(shake, shake);
vec4 distorted_color = texture(TEXTURE, distorted_uv);
// Final color blending
vec3 final_rgb = mix(flash, distorted_color.rgb, 0.5);
final_rgb = mix(final_rgb, vec3(1.0), damage_effect * 0.3);
COLOR = vec4(final_rgb, color.a); // Preserving original alpha
}This feature is currently in beta.
Join the discussion! Log in to share your thoughts.
Log In to Comment