jess-hammer / 2d-shadows-demo-godot

Demo of a shader to create directional 2D shadows of limited length!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2d-shadows-demo-godot

This project is a demo of how to use a shader to create 2D directional shadows! You can customise the color, length, angle and softness of the shadows. The shader uses Signed Distance Fields provided by the Godot engine.

Built with Godot 4.1.2

With soft shadows:

Screenshot of shadows demo

With hard shadows:

(Adjust the gradient in the shader params to acheive this)

Screenshot 2024-02-05 at 5 29 47 pm

SDF performance and quality

On my M1 Macbook Pro, I found that this shader ran fine. However, I noticed some framerate issues when the resolution is particularly large, for example on an ultra-wide monitor. Thankfully Godot provides some project settings that helps us combat this:

  • Oversize controls how much of the original viewport size should be covered by the 2D signed distance field.
  • Scale is the resolution scale to use for the 2D signed distance field. Higher values lead to a more precise and more stable signed distance field as the camera moves, at the cost of performance. The default value (50%) renders at half the resolution of the viewport size on each axis, which means the SDF is generated with 25% of the viewport's pixel count.

Screenshot 2024-03-17 at 11 50 12 AM

References:

Pixel art assets are from https://cupnooble.itch.io/sprout-lands-asset-pack

Shader code heavily based from https://godotengine.org/article/godots-2d-engine-gets-several-improvements-upcoming-40/

About

Demo of a shader to create directional 2D shadows of limited length!

License:MIT License