Search code examples
c++openglviewportbounding-box

OpenGL, Culling objects that are outside the view


In my case I wanna render 50,000 or more cubes that are distributed randomly inside a large bounding box, I don't want using instancing right now so I have to render each cube, I wanna improve the performance by culling out the cubes that are outside the camera view. I have a camera class that has two matrices view and projection, each cube has its own bounding box, so I am planning to check each frame if the camera view bounding box contains the center of each cube if yes call its draw function if not ignore it.

I have for view matrix 3 vectors eye, target and up, and for projection width, height, near, far and FOV.

so I have two questions:

  • Is this a right scenario? I will calculate the camera view boumding box each frame then test each cube.
  • How can I calculate the camera bounding box each frame?

Solution

  • I got an idea from here how_to_check_if_vertex_is_visible_for_user that worked fine with me.

    multiplying the projection view matrix of the camera by the any point in the 3D space the visible ones should be between [-1,1].