Created
June 19, 2024 04:52
-
-
Save CodeZombie/45495e4dfc62fd0371ce435568a63812 to your computer and use it in GitHub Desktop.
mipmap-based blurry shadow for godot 4 canvas items
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
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: