# Cascaded Shadow Map issue when rendering once

**URL:** <https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554>\
**Category:** Questions\
**Created:** [November 25, 2021, 9:49am UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554 "2021-11-25T09:49:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Regit](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@Regit](https://forum.babylonjs.com/u/Regit)\
**Post date:** [November 25, 2021, 9:49am UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/1 "2021-11-25T09:49:34Z")

</div>

Hello,

I’m having troubles with cascaded shadow maps when they are only rendered once.

This is how it looks when I do use:  
`generator.getShadowMap().refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;`

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/1/11ac33b6510902b32e51e41c4ecf2f1cc1d5b1fc.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/1/11ac33b6510902b32e51e41c4ecf2f1cc1d5b1fc.mp4)

And this is when I don’t (wanted look, but not with recalculating every frame):

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/b/cba159ab625ba5d68a5072932b4bbb4fb0f5e58c.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/b/cba159ab625ba5d68a5072932b4bbb4fb0f5e58c.mp4)

Obviously I only need to render it once for better performance.  
What is causing this and how can I counteract it?

---

<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:** [November 25, 2021, 9:56am UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/2 "2021-11-25T09:56:01Z")

</div>

Using REFRESHRATE\_RENDER\_ONCE with cascaded shadow maps will only work if you don’t move the camera: the generated shadow maps depend on the camera position, so if you move the camera the shadows will be off.

---

<div class="post-metadata">

**Author:** ![Regit](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@Regit](https://forum.babylonjs.com/u/Regit)\
**Post date:** [November 25, 2021, 10:21am UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/3 "2021-11-25T10:21:56Z")

</div>

Ok, so I should not use cascaded shadows if I don’t want to recalculate them every frame.

I’m a little confused why this is, since PlayCanvas seems to use a cascaded approach as well, but there it can be rendered only once:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/a/1ad7af0d702f766065e6edacf9ad77267c7de2f0.png)

The cascaded method gave me much better shadows, but I guess I’ll have to stick with a normal shadow map.

---

<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:** [November 25, 2021, 12:24pm UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/4 "2021-11-25T12:24:28Z")

</div>

You will see that using SHADOWUPDATE\_THISFRAME (which is the setting used when you choose “Once” in the editor) [here](https://playcanvas.github.io/#/graphics/shadow-cascades) won’t work:

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/c/3c0d9285812d8048d9e67780af4c00ffd96a110b.png)

Add the entry `shadowUpdateMode: 1,` (see screenshot) line 71: that will set the mode to SHADOWUPDATE\_THISFRAME.

Excute the updated code by clicking on:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/3/e3aec1e6ca8b11a321717625f7331341ff7fe50c.png)

You will see the shadows are not ok.

You need to set `shadowUpdateMode = 2` for the shadows to work correctly, this setting corresponding to `SHADOWUPDATE_REALTIME` (meaning shadows updated each frame - default setting).

---

<div class="post-metadata">

**Author:** ![Regit](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@Regit](https://forum.babylonjs.com/u/Regit)\
**Post date:** [November 25, 2021, 1:05pm UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/5 "2021-11-25T13:05:30Z")

</div>

You’re right, with those settings it behaves the same as in babylon.

However in the editor it does not. There is a visible performance loss when changing from `Once` to `Realtime`.

(I upped the shadow settings a bit for better distinction)  
Once:  
 ![IMG_0168](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/c/ec534756b67a300e1c3fb333c0c3b6d3b6c120b8.png)

Realtime:  
 ![IMG_0167](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/7/17de6e696a9603a137e5a1ed1a7d609a89aa2b28.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:** [November 25, 2021, 1:16pm UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/6 "2021-11-25T13:16:37Z")

</div>

Yes, I think when you choose “Once” in the editor you are really in the "once "mode, so that shadow maps are generated a single time. But you will get artifacts, depending on your scene and how you move the camera. Note that when you choose “once” in the editor, you have a button that pops on the right which is titled “Update shadows”.

---

<div class="post-metadata">

**Author:** ![Regit](https://avatars.discourse-cdn.com/v4/letter/r/6a8cbe/32.png) [@Regit](https://forum.babylonjs.com/u/Regit)\
**Post date:** [November 25, 2021, 1:24pm UTC](https://forum.babylonjs.com/t/cascaded-shadow-map-issue-when-rendering-once/25554/7 "2021-11-25T13:24:35Z")

</div>

Ok, I see where the issue was in my understanding.  
PlayCanvas’ single “Shadow Generator” is just cascading = 1 and when set to 2-4 the issue when changing the camera starts to happen.  
Now it makes sense to me, that Babylon only allows 2-4 cascades and not 1 😅

Thanks for being patient with me, I’ll have to stick with single “cascading” 😇
