40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
shader_type canvas_item;
|
|
|
|
uniform sampler2D screen_texture : hint_screen_texture;
|
|
uniform float damage_amount : hint_range(0.0, 1.0) = 0.0;
|
|
uniform float noise_strength : hint_range(0.0, 1.0) = 0.3;
|
|
uniform float pulse_strength : hint_range(0.0, 1.0) = 0.2;
|
|
uniform float time;
|
|
|
|
// TODO: uniform vec2 player_uv; // use this to calculate player offset to camera
|
|
|
|
float random(vec2 uv) {
|
|
return fract(sin(dot(uv.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
|
}
|
|
|
|
void fragment() {
|
|
// Distance from screen center
|
|
vec2 center = vec2(0.5, 0.5);
|
|
float dist = distance(SCREEN_UV, center);
|
|
float edge_factor = smoothstep(0.4, 0.7, dist); // stronger at edges
|
|
float edge_factor_gray = smoothstep(0.0, 1.0-damage_amount, dist);
|
|
|
|
// Noise flicker
|
|
float n = random(SCREEN_UV * 200.0 + time * 2.0);
|
|
float noise = (n - 0.5) * noise_strength;
|
|
|
|
// Pulsing intensity
|
|
float pulse = sin(time * 5.0) * pulse_strength;
|
|
|
|
// Final intensity
|
|
float final_amount = damage_amount * edge_factor + noise + pulse;
|
|
final_amount = clamp(final_amount, 0.0, 1.0);
|
|
|
|
vec4 base = texture(screen_texture, SCREEN_UV);
|
|
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
|
base.rgb = mix(base.rgb, vec3(gray), edge_factor_gray * damage_amount);
|
|
|
|
vec4 red_tint = vec4(1.0, 0.0, 0.0, 1.0);
|
|
COLOR = mix(base, red_tint, final_amount);
|
|
}
|