Frustum culling problem

Hi bjs team,

I am playing with the default frustum culling in bjs in this PG.

I have two cameras in this PG. A second camera is used to visualize the grids in frustum (red) and those are outside frustum (green).

The problem is if you rotate very fast, you can see the some green on the the view of the primary camera (if you look at the large ground, you can see green colors blinking on the left and right edge of the screen).

This there any solution I can apply so I only see red color on the large ground? Otherwise, player can notice a tile is missing temporarily and cause a blinking effect.

As you are using onAfterRenderObservable, you are setting new colors at the end of the frame based on what is visible at this frame, but those colors will be the ones that will be seen on next frame. You should use onBeforeRenderObservable to render the right colors for the current frame.

2 Likes

Hi @Evgeni_Popov

Thanks a lot to point it out. Actually onBeforeRenderObservable is used in my main repo. So there are some other issues caused this. I think I managed to fixed some of them. But I still see some tiles missing occasionally at the edges of the browser.

I guess the problem is I use invisible flat ground meshes to utilize bjs frustum culling. The actual tiles rendered are thin instance tiles with height displacement in shader. Because of this, there are some high hill area that need to be visible on the scene, but their corresponding flat ground meshes for culling are actually outside the frustum.

Do you know if there is standard method for fixing such issue? What I am thinking is like this:

Assume the * are the grids in frustum marked by bjs frustum culling. ^ are grids outside.

*  *  ^  ^
*  *  *  ^
^  *  *  ^
^  ^  ^  ^

This terrain has 4 tiles in the center.

   *  *  
   *  * 

12 tiles around it like a belt. Bigger terrain can have multiple belts of tiles.

*  *  ^  ^
*        ^
^        ^
^  ^  ^  ^

Then I force two extra tiles at the border of frustum to be included for rendering:

*  *  *  ^
*  *  *  ^
*  *  *  ^
^  ^  ^  ^

And doing this adding 2 extra tiles for each belt.

Do you think this would work?

I don’t know, but I think the problem is the displacement done in the shader, as you say, because you don’t know the true bounding volume because of that.

Adding border tiles may help, I guess it will depend on how much the displacement impacts the geometry… If there is a limit to the displacement, you could be conservative by creating a bounding volume around each tile with the maximum displacement possible.

1 Like

Thanks @Evgeni_Popov.

Am I right to understand that the bounding volume as “instead of using flat ground meshes (tiles) for frustum culling, I conceptually use boxes that captures the maximum displacement on y-axis?”

Yes, exactly.

1 Like