godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.46k stars 21.07k forks source link

Multimesh shadows break when setting instance positions in shader #71549

Open outobugi opened 1 year ago

outobugi commented 1 year ago

Godot version

4.0 beta 12

System information

Windows 11, GTX 1060, Vulkan

Issue description

Screenshot_20230117_113525

Very interesting glitch. Offsetting the instances with camera position in vertex shader causes this. See code in the screenshot. Without the camera offset, only glitch left is the shadows turning on/off based on camera angle.

Steps to reproduce

Minimal reproduction project

N/A

MGilleronFJ commented 1 year ago

If you offset vertices based on camera position (by that I assume the camera matrix used to render the current pass), that means the shadow pass will have a different result than the main pass, because shadow mapping uses a different camera to render depth from the point of view of the light. So that seems expected to me. If it is your intention to use the main camera regardless of the pass, you should probably send it with a uniform parameter. Or the meaning of CAMERA_POSITION_WORLD would have to change but that might break things.

outobugi commented 1 year ago

If it is your intention to use the main camera regardless of the pass

My intention is to have the instances move with any camera. Idea is to render grass on a terrain and have the possibility to have them be visible on any number of viewports/cameras.

But maybe the shading reference should mention that CAMERA_POSITION_WORLD also includes the shadow camera, because it might not be obvious for everyone.