-
-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Improve DirectionalLight shadow rendering efficiency #57549
Description
Godot version
3.4.2
System information
Windows 11, GLES3, NVIDIA RTX 3090 (511.23)
Issue description
A screenshot was posted to the discord memes channel a few days ago, and I got curious. The screenshot is below, along with the original comment.
Godot demo project. 12 cubes. 100k vertices. 20! drawcalls.
And people asking why Godot so slow when they run demos.
I created a test scene with a few objects and found that DirectionalLight with shadows enabled was the biggest issue. There is also some odd behavior with this combination that looks like false positives in the renderer culling, but I haven't found any reason for it while looking through the spatial partitioning code. At certain camera angles, objects that are no where near the camera frustum will contribute to the "Vertices Drawn", "Surface Changes", and "Draw Calls" metrics in the monitor.
Here are some screenshots from the test procedure described below. First, the scene is running, and I have the monitor shown in the editor:
Then I hide the SportsCar node, and "Vertices Drawn" is reduced by over 20,000! Surface Changes and Draw Calls also see some improvements:
Then I turn SportsCar back on and disable the shadow on DirectionalLight. Vertices Drawn has reduced by almost 60,000 (a massive 76% improvement)! and Surface Changes and Draw Calls see a 75% reduction; another huge improvement!
And finally, changing SportsCar visibility with the shadow off has no impact whatsoever, exactly what is expected for a node that cannot be seen by the camera at all.
This might be the cause of #35746.
Steps to reproduce
- Open the example repro project and run the scene.
- Open the Debugger/Monitors tab and enable everything under Raster.
- Change the visibility of the "SportsCar" node, which is behind the camera and its shadow is being cast away from it.
- Notice that this object is being drawn when it should not.
- Do the same SportsCar visibility test with the DirectionalLight shadow disabled.
- Notice that the monitor numbers no longer change with the SportsCar visibility! The numbers are also much lower with the shadow disabled.
- Do the very same test, but hide the DirectionalLight, and use either of the other lights instead.
- I found that any combination of the omni light and spotlight with their shadows does not change how many things are drawn, regardless of the SportsCar visibility. Shadows for these lights are free???
- Do the same test but this time use DirectionalLight+Shadow and change the camera rotation along its local X axis while SportsCar visibility is enabled.
- Even a slight adjustment upward from the camera's default rotation will reduce the number of things drawn. And yes, these are all from the SportsCar. Do the same rotation test with SportsCar hidden.




