- Home /
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:
Make a fresh project.
Add a directional light, set to hard shadows(soft shadow also possible).
Add Plan and set layer as "Terrain"
Add Cube and set layer as "Terrain"
Add Sphere and set layer as "Unit"
- Set properties of "Main Camera"
Culling Mask : "Terrain" ( render plane ans cube )
Depth : -1 ( render before character camera )
Rendering Path : Forward
- Add camera and set properties :
Culling Mask : "Unit" ( render sphere )
Depth : 1 ( render after main camera )
Rendering Path : Forward
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?
Thank you.
Answer by NateJC · Jul 29, 2016 at 04:44 PM
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:
5) For the Shadow Only object, use these settings:
6) Now apply all physics & animations to the parent object, and everything else should work naturally!
Your answer
Follow this Question
Related Questions
What can cause shadow slicing while moving camera? 1 Answer
How to set SceneView culling mask programmatically? 1 Answer
How to get Directional Light Shadows to render through an Orthographic Camera? 1 Answer
Shadows from culled objects 0 Answers
What is causing the Abs(dist - shadowRadius ) error? 1 Answer