# FPS reducing in large scene when camera gets close to the mesh

**URL:** <https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801>\
**Category:** Questions\
**Created:** [August 5, 2022, 10:36am UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801 "2022-08-05T10:36:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DWork](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DWork](https://forum.babylonjs.com/u/DWork)\
**Post date:** [August 5, 2022, 10:36am UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/1 "2022-08-05T10:36:25Z")

</div>

Hey guys, i got some questions about FPS. I test a scene about 3 million mesh, the scene run with dynamic CSM shadow(2048) and render every frame. When the camera was far from scene, FPS got range **53~60** , and got a lower FPS **20~30** close to the mesh.  
What happend to FPS or camera? What dose bbl FPS base on? In my opinion, the camera renders less mesh the FPS will be higher. How to handle it?

 ![20220805182042](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/5/d5d15c0764da698cb5de337fc20f91d4a55928b2.jpeg)  
 ![20220805182145](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/9/d9691eb11cb1517aba7cd7fb2562e29eab0cfcf5.jpeg)

---

<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:** [August 5, 2022, 3:20pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/2 "2022-08-05T15:20:41Z")

</div>

Can you run a profile? Using f12/profiler to see what is using your CPU

---

<div class="post-metadata">

**Author:** ![DWork](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DWork](https://forum.babylonjs.com/u/DWork)\
**Post date:** [August 5, 2022, 4:01pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/3 "2022-08-05T16:01:22Z")

</div>

The function realPixels occupy more cpu.

The nearest distane from mesh to camera, occupy cpu 30%

 ![20220805235646](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/e/5efc77d8cbaaa38e0a515623f3d65d49c9f4f766.png)

The farer distane from mesh to camera, occupy cpu 63%

 ![20220805235320](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/8/d8c1309c14628c1372e93a57608ceae733488bbf.png)

The farest distane from mesh to camera, occupy cpu 83%

 ![0220805235754](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/f/3f2b5bc3096aa837997d788909d3785e51546308.png)

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [August 5, 2022, 4:02pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/4 "2022-08-05T16:02:08Z")

</div>

Could you try to remove all trees and see what will happen?

---

<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:** [August 5, 2022, 4:15pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/5 "2022-08-05T16:15:47Z")

</div>

Also who is calling read pixels? That should not be something we would do per frame

---

<div class="post-metadata">

**Author:** ![DWork](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DWork](https://forum.babylonjs.com/u/DWork)\
**Post date:** [August 5, 2022, 4:15pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/6 "2022-08-05T16:15:58Z")

</div>

i did it, the scene without any trees, then i test again, although FPS was almost 60, the result was the same. I did records from Chrome Profile, the camera closed to mesh, “readPixels” increased double “Self Time”, reduced half when far from mesh.

 ![0220806001407](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/c/cc8731602bc76d5231a3b10079741d53173c99db.jpeg)  
 ![20220806001457](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/5/f5860c13a92f1c67d9131f70fb07734f4453c337.jpeg)

---

<div class="post-metadata">

**Author:** ![DWork](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DWork](https://forum.babylonjs.com/u/DWork)\
**Post date:** [August 5, 2022, 4:23pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/7 "2022-08-05T16:23:36Z")

</div>

Please check it ----“CascadedShadowGenerator”, that’s the problem cause

---

<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:** [August 5, 2022, 4:50pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/8 "2022-08-05T16:50:08Z")

</div>

Cc @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:** [August 5, 2022, 5:53pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/9 "2022-08-05T17:53:07Z")

</div>

Are you setting `autoCalcDepthBounds=true`?

If yes, try to set it to `false`. This option is heavy on performance so if it is the problem you won’t have any other choice than to disable it if the perf are not good enough for you.

---

<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:** [August 6, 2022, 1:04pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/10 "2022-08-06T13:04:29Z")

</div>

Note that you can try to set `autoCalcDepthBoundsRefreshRate` to a higher value than 1 and see if that helps without introducing too many artefacts.

See [Cascaded Shadow Maps | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/lights/shadows_csm#autocalcdepthbounds-default-false)

---

<div class="post-metadata">

**Author:** ![DWork](https://avatars.discourse-cdn.com/v4/letter/d/7993a0/32.png) [@DWork](https://forum.babylonjs.com/u/DWork)\
**Post date:** [August 6, 2022, 1:21pm UTC](https://forum.babylonjs.com/t/fps-reducing-in-large-scene-when-camera-gets-close-to-the-mesh/32801/11 "2022-08-06T13:21:17Z")

</div>

Thanks, it works. It’s much better now
