0 votes

The issue I have is simple: a mesh is animated via a vertex shader (a swimming fish).
It is lighten by a spotlight that projects its shadow on a plane.

If spotlight, plane and mesh are still (no modification of transform), the shadow is not updated, and it ends up with an inaccurate shadow on the ground (see screenshot).

error in shadow due to optimised shadow computation

If I move any of the spatials, the shadows is updated correctly, but as soon as everything is still, the issue reappear.

I've temporarly fixed this with a script on the spotlight that randomises slightly its position.

tool

extends SpotLight

export (bool) var _vibrate : bool = true

var initialised : bool = false
var fixed_translation : Vector3 = Vector3()

func _process(delta):
    if not _vibrate:
        return
    if not initialised:
        fixed_translation = translation
        initialised = true
    translation = fixed_translation + Vector3(rand_range(-0.001,0.001),0,0)

It triggers the shadows rendering (see below)

vibrating spotlight to update shadows

I think it's a dirty solution, but I couldn't find a way in the documentation to enforce shadow re-computation in a standard scene.

Does anybody have a solution for this?

All the best, godot rocks!

asked Jul 3 in Engine by frankiezafe (86 points)

1 Answer

0 votes

You should be able to force recomputation by changing the SpotLight's cull margin or some property like that.

answered Jul 5 by Calinou (6,336 points)

At each frame also?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.