How can I set the sides of a cube to not render when they're not visible to the user?

Hello there! I’m creating a cubic game using BabylonJS and I’m worried about how will the game perform when there’s a lot of cubes that are being rendered. I want to make sure that the game won’t have any performance issues when rendering a lot of cubes. As a result, I want a way to make sure that the sides of the cube/the cubes that are not visible to the user won’t be rendered. How can I do that?

Are any of the rendering behaviors 2 or 3 possible to code in BabylonJS?

EDIT: Can I make it so blocks that are too far off the player won’t be rendered?

Welcome aboard!

Here’s what happens:

  1. if a cube is at least partially visible it is sent to the graphic card (gpu), but the gpu won’t render the faces that are back facing the camera
  2. if a cube is not in the camera frustum (view), it is not sent to the gpu at all.

However, if a cube is inside the camera frustum but is completely occluded by another cube, it is still managed as described above in point 1.

It may be possible to detect that a cube is fully occluded by doing some occlusion testing, but I’m not sure it is worth it… As I have 0 experience with that, I will let others answer about it.

Now, if you are speaking about voxels rendering where each cube are well aligned with each other, then it may be possible to find quickly which cubes are at least partially visible and render only those ones and not the cubes fully occluded by them (even if in the camera frustum).

1 Like

Is it doable?