Issue with spotlight shadows updates when modifying mesh with vertex shader.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By frankiezafe

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).

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.


extends SpotLight

export (bool) var _vibrate : bool = true

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

func _process(delta):
	if not _vibrate:
	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)

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!

:bust_in_silhouette: Reply From: Calinou

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

At each frame also?

frankiezafe | 2020-07-06 08:58