Frustrum Culling is causing lag in the scene

Hi Team,
We enabled frustrum culling on camera in our project. As we understood frustrum culling increases the performance as it calculates the viewed objects in the scene. But for the first time while checking the 360 degree view of our scene , we observed some lag in the scene. Once 360 degree view for the first time was done , next time on-wards scene is better as camera renders all the objects in the scene. So how can we overcome from this lag issue for the first time. Is this default behavior or do we need to something to overcome this issue.
Thanks in advance…

Hi @yaswanth,

I can’t relate from my experience on why frustum culling produces that kind of delay.

Are you able to share a sample repro project?

Hi @Leonidas , Thanks for your reply. Currently we are working on a private project , it contains many objects in the scene. So before we create repro project for you , is there anything can we check regarding frustrum culling

Try profiling the scene with browser devtools and posting the result/debug into where the time is going.

IIRC, frustum culling increases GPU performance at the cost of CPU for calculating what to cull.

1 Like

I’d start by checking the Cull Time and how the Forward Time in the profiler is affected when enabling/disabling frustum culling.

You can also check the profiler object where stats are being kept for the following property, to actually see how many draw calls are being saved by frustum culling:


@Leonidas

Frustum culling seems to be working, and saving a big number of draw calls. Check this manual page on how to activate the profiler to check the timers.

https://developer.playcanvas.com/en/user-manual/optimization/profiler/

For more advanced profiling you will have to profile using the browser dev tools as @yaustar suggested.

I think the problem you observe is that some things, like shader compilation, or texture uploads, are done only for visible meshes. So without culling, all this is done on the first frame, and no further slowdowns are done as you rotate around. With culling though, those things are done as meshes come to the view and you experience slowdowns.

You could perhaps enable the culling only after the first frame is done to avoid it.

3 Likes

Hi @mvaligursky , Thanks for the reply. I tried as per your suggestion. now that slowdown issue is not coming. I enabled camera’s frustrum culling after the first frame as like below.

``

in initialize method
this.frameCount = 0;`

in update method.
if (this.frameCount === 1) {
this.entity.camera.frustumCulling = true;
}
this.frameCount++;

Is that above code snippet is fine or do we have any other better way?
1 Like

It’s fine. There are a couple of other ways to do it but they aren’t that much different.

okay. Thanks for your support.