godotengine / godot

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

Camera3D does not draw shadows casted by objects on other render layers #98231

Closed DillonSteyl closed 1 week ago

DillonSteyl commented 1 week ago

Tested versions

4.3.stable

System information

Windows 11

Issue description

I'm uncertain if this should be a feature proposal or not, but I seem to recall older versions of Godot supporting what I want to do here so I thought I would raise as a bug first.

A common solution to the "gun clipping" issue in FPS games is to use a separate camera to render the weapon mesh. This also allows us to modify the FOV of the player without distorting the look of the weapon mesh.

In Godot, we can accomplish this by having the gun mesh be on Render Layer 2, and having a separate "gun camera" which culls all render layers except Layer 2. However, with this setup, the gun mesh will not receive shadows correctly.

To illustrate this, I have set up a scene where the world is on Render Layer 1, and the weapon is on Render Layer 2. Here's what it looks like with a single camera, culling no layers. {0A8BE2C5-455A-4D66-8113-C6613AB447D3}

Here's what it looks like with the setup described above: {0ACCCE5C-64B4-49F5-8342-29E884F57894}

Steps to reproduce

  1. Set up "world" meshes, and ensure they are drawn on Render Layer 1.
  2. Add a directional light with shadow casting on.
  3. Create another mesh on Render Layer 2. Position it so that it is in the shade casted by the "world" meshes from Step 1.
  4. Add a camera to the scene so that everything is in view, and preview it
  5. Note that culling Render Layer 1 removes all shadows from the mesh on Render Layer 2.

Minimal reproduction project (MRP)

test-viewport-shadows.zip

AThousandShips commented 1 week ago

Related:

AThousandShips commented 1 week ago

Thank you for reporting, consolidating in:

See there for more details, if you think something was missed about this and it's not the same issue, please comment here and it can be reopened