0

I need additional theory on view frustum culling to better understand how to implement it. I understand that ray casting is involved in order to figure out what objects are in front, thus figuring out which objects not to render.

I am concerned about CPU usage. From what I understand, I should be casting out rays by my camera's width * height, and maybe increase the amount of rays depending how far the camera sees. Additionally, I would have to multiply that by the amount of object in the scene to verify which is closest to the ray.

Is my understanding of this concept accurate? How exactly could I do this more efficiently?

edit:

The goal is to achieve some type of voxel engine where the world can be sub-divided-up using an oct-tree. It could consist of hundreds of thousands of cubes.

Johnathan
  • 697
  • 4
  • 9
  • 19
  • What are you planning on doing with the scene in the end? – Blender Aug 19 '12 at 00:20
  • I would like to make a basic cube world where I can move around, remove blocks, and add blocks. This is mainly to understand how to implement view frustum culling. It should handle hundreds of thousands of cubes. – Johnathan Aug 19 '12 at 00:22
  • Are you trying to learn view frustum culling or are you trying to learn how to build Minecraft? Because learning about frustums by building Minecraft is a little bit like learning about shaders by building Halo; i.e. you might want to pick a simpler first project. – Nick Lockwood Aug 19 '12 at 00:37
  • Then where exactly does one begin to understand how to render only what you need with a world consisting of hundreds of thousands of cubes? – Johnathan Aug 19 '12 at 00:43
  • Wolfenstein is a good place to start. Same problem, but with only one layer of cubes. Wolfenstein originally used raycasting, but I'm guessing the OpenGL port doesn't any more. – Nick Lockwood Aug 19 '12 at 00:45
  • Alright, Wolfenstein clone could be a good place to start to help me understand where I am heading. Thanks for the suggestion. – Johnathan Aug 19 '12 at 00:49

1 Answers1

2

I don't think view frustum culling involves ray casting usually.

Normally you'd just z-transform all your geometry and then clip any polygons whose vertices fall outside of the viewport, or whose z value is greater or less than the near/far clipping planes.

Ray casting would be a lot more expensive, as you are essentially testing each pixel in the viewport to see if there's a polygon behind it, which is potentially NUMBER_OF_PIXELS * NUMBER_OF_POLYGONS math operations, instead of just NUMBER_OF_POLYGONS.

EDIT:

Oh, I see: You're trying to create a voxel-space world like Minecraft. That's a bit different.

The trick there is to make use of the fact that you know the world is a grid to avoid doing calculations for geometry that is occluded by cubes that are closer to the camera.

I'm still not sure that ray casting is the best approach for this - I suspect you want something like an oct-tree structure that lets you discard large groups of blocks quickly, but I'll let somebody with more experience of building such things weigh in ;-)

EDIT 2:

Looks like somebody else on StackOverflow had the same problem (and they used octrees): Culling techniques for rendering lots of cubes

Community
  • 1
  • 1
Nick Lockwood
  • 39,931
  • 11
  • 108
  • 100
  • I suppose an oct-tree would be the elegant and proper way of doing it. A voxel engine does better suit what I seek to achieve. I will add this additional info to my question. Thanks. – Johnathan Aug 19 '12 at 00:37
  • Thanks for the link, it seems to be helpful. – Johnathan Aug 19 '12 at 00:48