Skip to content

Instantly share code, notes, and snippets.

@deakcor
Last active July 23, 2025 18:43
Show Gist options
  • Select an option

  • Save deakcor/f9dfed4cf82cbd86b49bd1b56a6ebd9e to your computer and use it in GitHub Desktop.

Select an option

Save deakcor/f9dfed4cf82cbd86b49bd1b56a6ebd9e to your computer and use it in GitHub Desktop.
Shadow 2D for Godot Engine
/**
* Shadow 2D.
* License: CC0
* https://creativecommons.org/publicdomain/zero/1.0/
*/
shader_type canvas_item;
render_mode blend_mix;
uniform vec2 deform = vec2(2.0, 2.0);
uniform vec2 offset = vec2(0.0, 0.0);
uniform vec4 modulate : hint_color;
void fragment() {
vec2 ps = TEXTURE_PIXEL_SIZE;
vec2 uv = UV;
float sizex = float(textureSize(TEXTURE,int(ps.x)).x);
float sizey = float(textureSize(TEXTURE,int(ps.y)).y);
uv.y+=offset.y*ps.y;
uv.x+=offset.x*ps.x;
float decalx=((uv.y-ps.x*sizex)*deform.x);
float decaly=((uv.y-ps.y*sizey)*deform.y);
uv.x += decalx;
uv.y += decaly;
vec4 shadow = vec4(modulate.rgb, texture(TEXTURE, uv).a * modulate.a);
vec4 col = texture(TEXTURE, UV);
COLOR = mix(shadow, col, col.a);
}
@Jeremi360

Copy link
Copy Markdown

In godot 3.5 this shadow is cut to sprite image boundaries

@deakcor

deakcor commented Jan 4, 2023

Copy link
Copy Markdown
Author

In godot 3.5 this shadow is cut to sprite image boundaries

Hey, yes maybe the shader could be improved by resizing the vertex. I'll check to update it

@scharissis

Copy link
Copy Markdown

How can this be rotated; could that be a parameter?

@deakcor

deakcor commented Jan 5, 2024

Copy link
Copy Markdown
Author

How can this be rotated; could that be a parameter?

Yes I made this shader a long time ago, I guess I'll need to rewrite it

@CrawfishPress

Copy link
Copy Markdown

Appreciate the code, thanks - currently trying to learn both shaders, and 2D shadows in Godot. And just FYI for anyone,
https://www.reddit.com/r/godot/comments/10i1x06/expected_value_hint_error_shaders_in_godot_4/

in Godot 4 hint_color has been renamed to source_color

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