# How to render shadow map one time

**URL:** <https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176>\
**Category:** Questions\
**Tags:** shadow-map, shadows\
**Created:** [April 20, 2019, 3:58pm UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176 "2019-04-20T15:58:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [April 20, 2019, 3:58pm UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/1 "2019-04-20T15:58:45Z")

</div>

I found a tip of threejs about shadow rendering [here:](https://discoverthreejs.com/tips-and-tricks/)

> ## Shadows
> 
> 1. If your scene is static, only update the shadow map when something changes, rather than every frame

Is there anyone can tell me how to achieve this? when I set the castShadow to false. the shadow map just disappear.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [April 20, 2019, 4:04pm UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/2 "2019-04-20T16:04:07Z")

</div>

You can do this by setting `renderer.shadowMap.autoUpdate` to `false`. If an update is required, set `renderer.shadowMap.needsUpdate` to `true`.

Demo: [https://jsfiddle.net/2xbje0sn/](https://jsfiddle.net/2xbje0sn/)

---

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [April 21, 2019, 5:38am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/3 "2019-04-21T05:38:32Z")

</div>

Oh yes! that’s really cool!

---

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [May 12, 2019, 8:51am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/4 "2019-05-12T08:51:26Z")

</div>

I found this trick can’t significantly improve performance of shadow rendering on smart phone. see pictures below:  
 ![846032102](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/3/3342daa58ee2fadffaab77681911d628b0a15e57.png)

![1452966626](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/threejs/original/2X/0/06208e25cd7337550d791700d4cfcf96e204738e.png)

test code (most of them copied from mugen87’s jsfiddle demo): [https://codepen.io/iamnotstone/pen/yWJKzx](https://codepen.io/iamnotstone/pen/yWJKzx)  
@Mugen87 @looeee

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [May 12, 2019, 9:37am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/5 "2019-05-12T09:37:30Z")

</div>

> [@iamnotstone](#):
>
> I found this trick can’t significantly improve performance of shadow rendering on smart phone.

Probably because computing the shadow map is no real performance bottleneck in this simple app.

---

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [May 12, 2019, 9:46am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/6 "2019-05-12T09:46:18Z")

</div>

But, if I disable the shadowmap, and fps value will up to 60.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [May 12, 2019, 10:02am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/7 "2019-05-12T10:02:37Z")

</div>

I think we need to differentiate between _rendering_ a shadow map and just _updating_ it.

---

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [May 13, 2019, 2:15am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/9 "2019-05-13T02:15:03Z")

</div>

what do you mean by just updating it? You mean eliminate the animations and timeout ? If so, I have already do that , and it is unhelpful.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [May 13, 2019, 8:23am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/10 "2019-05-13T08:23:33Z")

</div>

> [@iamnotstone](#):
>
> what do you mean by just updating it?

There are two steps when using shadow mapping. The shadow map is generated and then used as a texture. `renderer.shadowMap.autoUpdate` controls the first part of this process.

---

<div class="post-metadata">

**Author:** ![iamnotstone](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/iamnotstone/32/1343_2.png) [@iamnotstone](https://discourse.threejs.org/u/iamnotstone)\
**Post date:** [May 13, 2019, 8:28am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/11 "2019-05-13T08:28:14Z")

</div>

> [@Mugen87](#):
>
> `renderer.shadowMap.autoUpdate` controls the first part of this process.

Does this controls the projection of a shadowMap to every surface?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [May 13, 2019, 11:06am UTC](https://discourse.threejs.org/t/how-to-render-shadow-map-one-time/7176/12 "2019-05-13T11:06:39Z")

</div>

As I said before, it just controls the update process of the shadow map. I suggest you study in more detail how shadow mapping works, then this topic will be more clear to you.
