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

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?

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

The function realPixels occupy more cpu.

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

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

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

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

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

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.

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

Cc @Evgeni_Popov

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.

1 Like

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

Thanks, it works. It’s much better now