Skip to content

Instantly share code, notes, and snippets.

@CodeZombie
Created June 19, 2024 04:52
Show Gist options
  • Save CodeZombie/45495e4dfc62fd0371ce435568a63812 to your computer and use it in GitHub Desktop.
Save CodeZombie/45495e4dfc62fd0371ce435568a63812 to your computer and use it in GitHub Desktop.
mipmap-based blurry shadow for godot 4 canvas items
// The canvas item applied to this has two requirements before this will work:
// 1. The texture must have mipmaps generated at Import
// 2. The CanvasItem this shader is applied to must have Texture Filtering set to something with "mipmap" in the name.
shader_type canvas_item;
uniform float lod: hint_range(0.0, 8.0) = 0.0;
uniform float intensity : hint_range(0.0, 4.0) = 1.0;
uniform vec4 blur_color : source_color = vec4(1.0,1.0,1.0,1.0);
void fragment(){
vec4 modified_blur_color = blur_color;
modified_blur_color.a = textureLod(TEXTURE, UV, lod).a * intensity;
vec4 original_color = texture(TEXTURE, UV, 0);
if (original_color.a < 1.0) {
original_color = mix(modified_blur_color, original_color, original_color.a);
}
COLOR = original_color;
}
@CodeZombie
Copy link
Author

Extremely efficient drop shadow blur effect for canvas items for Godot 4.

NOTE: The canvas item applied to this has two requirements before this will work:

  1. The Texture resource must have mipmaps generated at Import
  2. The CanvasItem this shader is applied to must have Texture Filtering set to something with "mipmap" in the name.

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