# CSM DepthRenderer on Camera change

**URL:** <https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260>\
**Category:** Questions\
**Created:** [September 18, 2020, 1:41pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260 "2020-09-18T13:41:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 18, 2020, 1:41pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/1 "2020-09-18T13:41:05Z")

</div>

Hi,  
I am currently running into the issue, that I do not know, how to update the right DepthRenderer for cascaded shadow maps.  
Have a look at the following playground. Zoom out on first camera! After the switch to the other camera, the shadows should disappear.  
[https://www.babylonjs-playground.com/#1ST43U#442](https://www.babylonjs-playground.com/#1ST43U#442)

The reason seems to be, that both cameras need different depth renderers and that they need to be set to the csm? But I still do not seem to get it to work.

Any recommendations?

Best,  
Martin

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 18, 2020, 5:15pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/2 "2020-09-18T17:15:20Z")

</div>

pinging @Evgeni_Popov

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 18, 2020, 6:10pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/3 "2020-09-18T18:10:45Z")

</div>

Why would the shadows disappear when switching to the 2nd camera?

---

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 21, 2020, 2:12pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/4 "2020-09-21T14:12:30Z")

</div>

Hi,  
I actually do not know. I guess the shadows are disappearing for you, too inside of the playground?  
My feeling is, that the Depth Renderer still renders from the perspective of the other camera an not from the current active one.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 21, 2020, 4:16pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/5 "2020-09-21T16:16:24Z")

</div>

No, the shadows are visible both from camera 1 and 2 in the PG (4.2.0-beta.5):

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/1/17196ce83529b1a369daad191245e414ebaab809.png)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/e372047ee800999c1ac988245a9a95294abb4477.png)

---

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 21, 2020, 7:21pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/6 "2020-09-21T19:21:09Z")

</div>

Is it the same even if you zoom out farther with the first camera?  
In the following two pictures you see the two depth renderers.  
I have also tried out a PG with only one depth renderer and when I refresh on second camera, its still the depth renderer of the first one. I am just not sure, how I can make it active. [https://www.babylonjs-playground.com/#1ST43U#443](https://www.babylonjs-playground.com/#1ST43U#443)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/318ca685d80becc0e3a75c18ffc6ce4a8fabbe81.png)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/f7336ba8e18e345534ef9121d4bf2d63f518509a.png)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 21, 2020, 8:43pm UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/7 "2020-09-21T20:43:25Z")

</div>

When switching cameras and depth renderers, you should set `autoCalcDepthBounds` to `true` each time so that internal data are recomputed to match the new depth renderer:

[https://www.babylonjs-playground.com/#1ST43U#444](https://www.babylonjs-playground.com/#1ST43U#444)

---

<div class="post-metadata">

**Author:** ![dennemark](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dennemark/32/10745_2.png) [@dennemark](https://forum.babylonjs.com/u/dennemark)\
**Post date:** [September 22, 2020, 8:48am UTC](https://forum.babylonjs.com/t/csm-depthrenderer-on-camera-change/14260/8 "2020-09-22T08:48:39Z")

</div>

Thanks a lot! That was easier than expected! Great to know! 🙂
