Manual Frustum Culling problem

I’m trying to check if a vector is in the frustum.
Fortunately this is being done in a playground: https://www.babylonjs-playground.com/#ZU2FWP#57

Right now I’m using a function I got from a forum post, at line 565 which also calls a function at line 803, and is being called at line 477.
The frustum planes are being updated at line 385.

When I run the code I get this:


This happens when I check if the point is not in the frustum.

Logically, if I change the false to true at line 477 it should show the other side but it shows blank. Now if you remove the other culling part at line 471 you’d see that it’s displaying parts that are really far away but not parts right close to the camera:

I’m not sure what’s going on, I need help.

what about line 566

 if (UTILS.planeDotCoordinate(frustumPlanes[i], point) < 0) {

and like switching that to >?

I think that is working, because if you clip down to the lowest lod and then pass through the surface and then zoom backwards fast you can catch the missing chunks rebuild before the lod calc.

Cool scene btw.

1 Like

I think its working:

And I kinda see what you mean about zooming fast:


(at the bottom right corner)

Though I just realized I actually have no way of seeing if the culling worked.

2 Likes

I mean logically I think its working, just from reading over what’s going on. It would be really hard to tell unless you had two cameras rendering one from your perspective which is doing the frustum pass, and then one that is just one you can look around with that does not do anything to that.

2 Likes

You might be able to see in the inspector if it is working by active meshes.

I tried using 2 cameras and saw this:

It’s culling behind the camera

https://www.babylonjs-playground.com/#ZU2FWP#62

1 Like

The entire sphere is 1 mesh

1 Like

And plus how do I suppress these annoying warnings:


that say I can not set positions with an empty array!?!?

Regarding the warnings, that’s because you set an empty array for the position kind of your mesh. Just don’t set the positions if it is empty (or set a dummy vertex (0,0,0)).

1 Like

I didn’t think about using the dummy vertex, I tried it and the warnings disappeared! Thanks!

1 Like

So it looks like switching the > worked!

Its not entirely working.
Yea it is culling something, but the frustum is facing backwards.

the camera is facing this direction.

newest pg please?

https://www.babylonjs-playground.com/#ZU2FWP#66
I did the dummy vertex thing
I used SharedArrayBuffer to speed up the worker response message at line 620.
I inverted the position at the x and z at isInFrustum at line 605.

https://www.babylonjs-playground.com/#ZU2FWP#69

The lod gaps have been fixed and everything has been reduced to just the positions buffer.