โ† All examples

godot shaders

Projected ground shadow for 2D sprites

Turn a copy of a sprite into its cast shadow on the ground: the vertex stage flattens and skews it from the sprite's base toward a light direction, and the fragment stage fills it with a shadow colour that fades with distance from the feet.

Recorded render of Projected ground shadow for 2D sprites

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • component.json
  • demo.tscn
  • inspect_shader.py
  • material.tres
  • preview.png
  • sprite_ground_shadow.gdshader
  • test_package.py
  • verification/native.json

How it works

Shader type
canvas_item
Parameters
shadow_color (vec4 = 0.05, 0.05, 0.1, 0.5), flatten (float = 0.45), skew (float = 1.1), base_v (float = 1), fade (float = 0.6), sway (float = 0)
Use it on
A second sprite node with the same texture, placed at the character's position and drawn first.
Result
A sprite standing on the ground with a flattened dark shadow stretching to its lower right.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/sprite_ground_shadow/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • contract_static
  • engine_run
  • engine_log_clean
  • shader_in_scene
  • capture_written
  • render_not_uniform
  • shader_changes_pixels

Limits to consider

Use a second node with the same texture and this material, drawn before the character (as in the demo). The shadow is a projection of the sprite outline, not lit by Godot's 2D lights, and does not bend over terrain.