Sign in to follow this  

Frustum culling brute force terrain ???

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I just wondered whether it is possible to frustum cull a brute force terrain rendered through an indexed D3DPT_TRIANGLELIST ? I can frustum cull single objects but now I was wondering if it's possible to cull out parts from a vertexbuffer. Keep coding, Leoric

Share this post


Link to post
Share on other sites
Its a trade off really. You could frustum cull every triangle but then you are doing a lot of work on the CPU that may not be worth it. Instead I would split your terrain into sections and frustum cull those rather than at a triangle level.

Share this post


Link to post
Share on other sites
If by brute force you are implying that you are using no spatial partitioning algorithm and are simply treating the terrain as one big triangle soup, then you can perform frustum culling per poly but it will be *very* slow. Your best option is to implement a basic quad tree structure and treat each node as an object that you recursively test for frustum culling. If you've already implemented a quad tree and are using it for LOD, then you can also very easily use the same structure for your frustum culling.

If you are using an indexed vertex buffer for your terrain data you can either use one large vertex buffer for the terrain data, and then pass the visible nodes' index buffers to the renderer each frame, or you can create a vertex buffer for each leaf node and then only pass the visible nodes' vertex buffers to the renderer. The former technique may be a little faster but will result in a lot of wasted memory, esp. in large scenes where the majority of the terrain is culled, whereas the latter techique is much more suitable for general cases. The latter also more readily lends itself to LOD techniques IMO.

Kyle

Share this post


Link to post
Share on other sites
@Trip99: So dividing the terrain into sections means having a vertexbuffer for each section ?

@Kyle N: No, I am not using a quadtree or a thing like that. I have investigated into this but wasn't able to find any good information for quadtree-noobs on how to implement one. I tried to code one myself but the problem I had was how to fill the nodes with the polygons. Any hint on that ?

Bye,
Leoric

Share this post


Link to post
Share on other sites
OK, you may have seen this already but here is what seems, at a glance, a good quadtree tutorial. Essentially you want to have the nodes only contain two coordinates representing a bounding box which encloses that area of the terrain. Only the leaf nodes need to contain data, and you can just use a vertex buffer for each of these. So at render time, build a list of visible leaf nodes by frustum culling and then simply render those vertex buffers.

Kyle

Share this post


Link to post
Share on other sites
Thankx for your help Kyle but:

-I know how to code the quadtree nodes and dividing the nodes etc.
-My problem is having a single vertexbuffer at first and telling node XY: "This are your vertices !"

The only thing I still need to know is how to fill the nodes with (indexed ?) vertex data so all I have to do is calling Node->Render() and only the polys contained in the node are rendered.

Say I have a vertexbuffer an an indexbuffer. How will I divide the indexbuffer into pieces to fill the nodes with ? Is it testing every single vertex and if contained inside the nodes bounding box, the polygon to which the vertex belongs is stuffed into the node ? How is this coded actually ?

I hope you know what I mean ?

So long,
Leoric

Share this post


Link to post
Share on other sites
Ah, so you're having trouble actually dividing the terrain data up initially so that it is placed in the correct nodes in the quadtree? You do this as a preprocess on engine initialization, and yes, you want to test each triangle to see which node it belongs to.

You will have problems when triangles straddle the boundary between nodes (i.e. one vertex lies in one node and the other two lie in a different node) which results in clipping issues. There are various techniques to get around this, probably the easiest is to make sure that your node bounding boxes are aligned with the heightmap data.

EDIT:
Ultimately you want to do this as an offline process because these quadtree nodes and the data they contain will not change during the game. So you want to write a scene compiler which generates the nodes and then saves them as a file. When you start the engine, it just loads the data in. This will save a lot of engine initialization time on start up.

Kyle

Share this post


Link to post
Share on other sites
Hey Kyle,

so I will scan through the Indexbuffer, pulling out the indices, then test the triangles vertices against the nodes bounding box. When the triangle is contained, I copy the indices to the nodes indexbuffer ? Is that what you meant ?

And, preprocessing the nodes means that the number of nodes cannot change at runtime, right ? So I would have to decide before the app starts how many nodes I want to use ?!

Bye,
Leoric

Share this post


Link to post
Share on other sites

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this