Get Objects from Frustum Cull Pre-Draw

As the topic says, I’m looking for a way to get a list of objects that passed the camera’s frustum cull before anything gets drawn so I can do a quick occlusion test on some of my larger, draw call heavy items that might be in the background. My experience has a single camera and it follows a rail system stopping at points of interest so the camera is pretty stationary for large amounts of time.

So my thought is:

  • Tag some objects as occlusion ready, put a collider on them
  • Tag some objects as occluders and put a collider on them
  • Post frustum cull, and pre render do a simple raycast from camera to in frustum occlusion ready objects and if they are being blocked by an occluder, turn off their renderer or remove them from the ready to draw objects

Not even sure if this is a feasible means to do what I want, just hitting some spots in an interior scene where other room’s objects are ramping up my draw calls.

Hi @derek9nine,

There is the onPostCull callback that you can use on one or more render layers:

That will fire as soon as the frustum culling check has finished. From there you can query all mesh instances included in that layer and check the visibleThisFrame property. That way you can build a list of all visible mesh instances per frame.

Afterwards I’m not sure how to toggle off rendering based on your viz calculations. @mvaligursky I think meshInstance.visible isn’t used in the renderForward() method right?

Your system can work independently of the engine culling. Based on the position of the camera, just make meshInstances invisible as needed by setting MeshInstance.visible to false on those that are occluded. Engine will not render them (remove them during culling).

1 Like

Thanks for all of the help!

Ultimately I came up with a system that works for my specific needs. I was over thinking it early on for sure :slight_smile:

1 Like