Created
June 19, 2024 03:55
-
-
Save CodeZombie/ddd5e3f41f66f5f2dc2e147ea9fed778 to your computer and use it in GitHub Desktop.
Blurry drop shadow, godot canvas shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is wildly inefficient, you probably shouldn't use it!