Help needed eradicating SDF texture_sdf update lag

Godot Version

4.2.0

Question

Does anyone have any tips for fixing lag when using the SDF texture? I couldn’t use the Godot Light2D because I need to support lots of lights in close proximity, and would hit the Vulkan limit.

Instead, I started with Dynamic 2D Lights and Soft Shadows - Godot Shaders and manually create a depth texture using subviewport (major PITA, hope 2D depth buffer coming soon devs).

At the moment as I’m dragging the camera around there’s a clear lag as the SDF texture gets updated - perhaps one or two frames behind?

Progress thus far:

Depth in red channel, emission in green.

Given that each camera change alters the SDF, I’ll explore delaying the camera move until after the frame render.

You could disable V-Sync and cap the framerate to a multiple of the monitor refresh rate to hide (but not fix) the issue, but this will increase power consumption and isn’t guaranteed to work (on slower hardware or if V-Sync is enforced by the system).

I couldn’t use the Godot Light2D because I need to support lots of lights in close proximity, and would hit the Vulkan limit.

How many lights at once do you need to draw on a single sprite? The limit of lights in Godot is per-sprite, and IIRC, it’s pretty high for 2D (128 lights or so). It is lower in 3D if using the Mobile rendering method, but when using Forward+ in 3D, it’s 512 clustered elements by default (a clustered element being an omni/spot light, a decal or reflection probe).

If you’re actually hitting the limit, you can split large sprites (such as the background) into smaller ones. This can also improve performance as lights won’t need to make as many sprites redraw, reducing the fillrate requirements at the cost of more draw calls.