Skip to content

Instantly share code, notes, and snippets.

@CodeZombie
Created June 19, 2024 03:55
Show Gist options
  • Save CodeZombie/ddd5e3f41f66f5f2dc2e147ea9fed778 to your computer and use it in GitHub Desktop.
Save CodeZombie/ddd5e3f41f66f5f2dc2e147ea9fed778 to your computer and use it in GitHub Desktop.
Blurry drop shadow, godot canvas shader
shader_type canvas_item;
uniform float blur_radius : hint_range(0.0, 1.0) = 0.25;
uniform vec4 shadow_color : source_color = vec4(0.0, 0.0, 0.0, 1.0);
void fragment() {
vec4 original_texture_color = texture(TEXTURE, UV);
float shadow_alpha = 0.0;
if (original_texture_color.a < 1.0) {
for (float x = -blur_radius; x <= blur_radius; x+=0.01) {
for (float y = -blur_radius; y <= blur_radius; y+=0.01) {
shadow_alpha += texture(TEXTURE, UV + vec2(x, y)).a * 0.01;
}
}
}
vec4 sc = shadow_color;
sc.a = shadow_alpha;
COLOR = mix(sc, original_texture_color, original_texture_color.a);
}
@CodeZombie
Copy link
Author

This is wildly inefficient, you probably shouldn't use it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment