# Scene freezes when adding dynamically PointLight

**URL:** <https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281>\
**Category:** Questions\
**Tags:** lights\
**Created:** [July 23, 2021, 2:15pm UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281 "2021-07-23T14:15:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [July 23, 2021, 2:15pm UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/1 "2021-07-23T14:15:15Z")

</div>

Good day everyone, I have such a question, when a point of light is dynamically added to the scene, the scene freezes for a second and a half, everything is in a motionless state, how can this be processed?

---

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [July 23, 2021, 2:20pm UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/2 "2021-07-23T14:20:12Z")

</div>

In more detail, there is a scene with complete darkness, when adding fire to the sword, I add a point of light with a small area of illumination, and at this moment the whole game freezes for just a second.

---

<div class="post-metadata">

**Author:** ![gui](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gui/32/27258_2.png) [@gui](https://discourse.threejs.org/u/gui)\
**Post date:** [July 24, 2021, 8:10am UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/3 "2021-07-24T08:10:52Z")

</div>

It’s because materials are recompiled when you add or remove lights. Try and have your light from the beginning and instead change its intensity from 0 to 1. That should give you the same effect without freeze.

---

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [July 24, 2021, 10:40am UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/4 "2021-07-24T10:40:17Z")

</div>

> [@gui](#):
>
> intensity

Thanks, I’ll try, but if, for example, I need 5 or 10 points of light, when I try to add them immediately to the scene, there will be a bug.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/c/a/ca9deed786de91a9a17e1bd2ee3360ba47b7f7ed.jpeg)

---

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [July 24, 2021, 2:03pm UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/5 "2021-07-24T14:03:34Z")

</div>

It turned out to be done, the freeze became less, but you have to spend additional time to accurately handle the light using the setTimeout function with a delay to add and remove from the scene, and then call a promise at the end of the process.

However, this is a crutch, not a solution, as I understand it, there is no possibility of parallel loading of data in a separate thread so as not to interfere with the mainstream.

BUT EVERYTHING FOR THOUGHT THANKS)))

---

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [July 24, 2021, 2:25pm UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/6 "2021-07-24T14:25:44Z")

</div>

Intersting why this callback function dont work ( .onAfterRender and .onBeforeRender ) on PointLight ?

---

<div class="post-metadata">

**Author:** ![TimKraemer](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/timkraemer/32/24533_2.png) [@TimKraemer](https://discourse.threejs.org/u/TimKraemer)\
**Post date:** [May 12, 2022, 10:51am UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/7 "2022-05-12T10:51:37Z")

</div>

Did you or anybody find a good solution to those freezes?  
Unfortunately I can’t prevent placing lights on runtime (the user will be able to place objects with rect-area lights on them).  
Is there a way to process the material recompilation in a separate thread, so that the main scene doesn’t freeze? It would be fine to at least show a loading animation or something more elegant than a freeze.

---

<div class="post-metadata">

**Author:** ![KiborgMaster](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kiborgmaster/32/69616_2.png) [@KiborgMaster](https://discourse.threejs.org/u/KiborgMaster)\
**Post date:** [August 13, 2022, 6:19am UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/8 "2022-08-13T06:19:44Z")

</div>

Unfortunately there is no perfect solution yet.

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [August 13, 2022, 8:56am UTC](https://discourse.threejs.org/t/scene-freezes-when-adding-dynamically-pointlight/28281/9 "2022-08-13T08:56:33Z")

</div>

Maybe tiled\_forward lighting: [three.js examples](https://threejs.org/examples/?q=forw#webgl_tiled_forward)  
In old version of three.js was deffered rendering like this [three.js webgl - deferred rendering](https://alteredqualia.com/three/examples/webgl_deferred_postprocessing.html)
