โ† All examples

godot shaders

Soft drop shadow inside the sprite rectangle

Add an offset, softened drop shadow behind a sprite's shape without an extra node: the shader samples the alpha at an offset with a small blur and composites the sprite over it.

Recorded render of Soft drop shadow inside the sprite rectangle

What this component contains

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

How it works

Shader type
canvas_item
Parameters
shadow_color (vec4 = 0, 0, 0.05, 0.6), offset_x (float = 7), offset_y (float = 7), softness (float = 2.5)
Use it on
A Sprite2D (or other textured CanvasItem) with transparent space around its shape, assigned to the node as usual. Effects outside the shape are drawn inside the texture rectangle, so the texture needs a margin.
Result
An orange disc floating above the background with a soft dark shadow to its lower right.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/sprite_drop_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

Effects outside the shape are drawn inside the texture rectangle, so the texture needs a margin. Offsets larger than the margin are cut at the texture edge. The shadow ignores what lies under the sprite (it is not a light).