How to compute slightly bigger frustum from the camera?

Hello!

I’m trying to handle frustum culling with instances, and I need to know which instances are in.
Everything seems to work fine using the functions below, but there is one problem. As I’m checking
just against point, and that my instances are rectangular, they don’t appear if they are at the border of the frustum. Then they pop in when their center (posVec) is in.
I could eventually do multiple tests which might be costly, and not sure what would be the most effective. The other idea is to “enlarge” a little bit the frustum without changing the camera characteristics(Fov…), and tune the enlargement until it’s good.
But I have no idea how to make the frustum match the camera as below, but with a slightly bigger frustum.
If there is another way to do it better, I’ll take it!

frustum.setFromProjectionMatrix(
    m.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
);
// ...
frustum.containsPoint(posVec)

If you want to maintain camera.fov and the camera’s aspect ratio, the only way I see is to move the camera away from the scene just a little bit.

To be honest, I have never used Instances and I doubt it, I ever will.

But I do know a thing or two about frustum and how 3JS interacts with it to cull meshes.

If the elements in your cluster (Instances) remain free of transformation. Then creating a boundingSphere can force 3JS to render em as they were nomal mesh.

Meaning Instances are rendered when boundingSphere is within or intersecting frustum.

And to tweak it, you just change the radius of boundingSphere object.

Now, boundingSphere for culling is the most efficient way to go, but depending on the shape of object, it can be rendered despite being way out of frustum.

If you are interested, I can show you a demo.

3 Likes

I tried this approach, this is what worked the best for me. Thank you!

1 Like