Frustum Culling with a set of Index Vertex Arrays?

Hi all.

My terrain generator/viewer is comming along quite nicely now but I have to get it going quicker. So, the next thing to implement is an Octree and Frustrum culling of the triangles in the scene. I understand the maths for this and the concept is simplicity itself BUT how to implement it with the set of Index Vertex Array that the terrain currently uses for rendering?

My Terrain uses a height map generated from a picture. I then create a vertex array containing all the vertexes in this heightmap. Then I create Y index arrays, each with X2 elements in them. They are X2 long because the indexes produce a very nice triangle strip when passed to glDrawArrays.

But, I dont know how to cull these triangles against the frustum. Am I gogin to have to switch to a array of triangles and render these once I have got rid of the ones that cant be seen?

How do I use VA and Frustum Culling at the same time?

Any ideas would be most appreciated.


You can build your index arrays each frame, instead of once. Just calculate where along the first strip it itntersects the frustum. Start your index there, and stop at the next frustum intersection.

And do the same for all strips ofcourse

[This message has been edited by Bob (edited 01-13-2001).]

You can collect vertexes and indexes to use
and write into your array for each frame.
This is an extra copy step compared to
“canned” VAs, but the speed-up may be worth

You can also slice your terrain into a
number of “areas” and cull entire areas
instead of individual triangles; each area
would be one VA (or one contiguous part of
a giant VA). If you do this, you can also
use the “area” division for LOD (and in the
extreme case, recursively slice each area in
sub-areas, … down to individual triangles).
Watch out for gaps between areas of different
LOD if you do this, though.

Hi guys.

I came to sort of the same conclusion over the weekend. But I’m not sure how to set it up in the Octree. E.g.

I figure I will have a stl::vector holding structs something like this.

typedef struct tagIndexDescriptor
Vertex * pStart;
GLuint iLen;

typedef stl::vector IndexDecVector;

Then I will step through my index arrays, testing each triangle I come across. To do this I will have to test the triangle depicted by the current vertex and the two previous indexes in the array. While stepping through, I will store the current pointer position of the index in the array in pStart and step along until the triangle is no longer in the frustum (Or the triangle is back-faceing). Then I will store the length in iLen.

This will allow me to write this code for the drawing of the (now clipped) triangle list.

IndexDecVector::iterator iIter;

for(iIter = vIndexes.begin(); iIter != vIndexes.end(); iIter++)
glDrawElements(GL_TRIANGLE_STRIP, (iIter).iLen, GL_UNSIGNED_INT, (const GLvoid) (*iIter).pStart);

Ok. One last thing. How do I integrate this with my Octree? The vertex arrays go right accross the terrain but I want to use an octree to test for collision and visibility on a triangle level basis.

Maybe the Octree leaves should hold a set of IndexDescriptor structs themselves. That way I would know which triangle strips are in the octree node without having to compute it each time. I could then test the frustrum agains just these stored set of indexes? Maybe?

Any further ideas