How to share shadow between two cameras

Hi~

There are two cameras in the scene,
one is named “Terrain camera” and the another is named “Character camera”.

Terrain camera renders terrains and Character camera renders unit models.

After I generate a scene, I can see the terrain and character models,
but the character’s shadow does not cast in terrain.

To reproduce:

  1. Make a fresh project.

  2. Add a directional light, set to hard shadows(soft shadow also possible).

  3. Add Plan and set layer as “Terrain”

  4. Add Cube and set layer as “Terrain”

  5. Add Sphere and set layer as “Unit”

  6. Set properties of “Main Camera”

  • Culling Mask : “Terrain” ( render plane ans cube )
  • Depth : -1 ( render before character camera )
  • Rendering Path : Forward
  1. Add camera and set properties :
  • Culling Mask : “Unit” ( render sphere )
  • Depth : 1 ( render after main camera )
  • Rendering Path : Forward
  1. Finally make the two camera have same position.

If you run the game, the cube cast shadow to the plane, because they have same layer id.
But, sphere does not cast shadow to the plane and cube.

I don’t know why… but because the camera has its own shadow data?
If so, can I make the two camera share same shadow data (= maybe shadow map texture?).

Also, I have to make the shadow data with objects that does not have same layer id.
Does Unity have some functions for this?

or any other alternative?

35003-unity_shadow_01.png

35004-unity_shadow_02.png

Thank you.

I figured out a workable solution for my case:

  1. Make a parent game object that has the collider & rigid body

  2. Now add two nested children to it, each with the same Mesh + Mesh Renderer components

  3. Name one of them “View” and the other “Shadow Only”

  4. For the View object, use these settings:

75095-view-settings.png

  1. For the Shadow Only object, use these settings:

75094-shadow-only-settings.png

  1. Now apply all physics & animations to the parent object, and everything else should work naturally!