Sign in to follow this  
i_luv_cplusplus

Terrain patches (subdivision)

Recommended Posts

Hello. I am going to implement some kind of Level-of-Detail to my terrain. Currently I have basic heightmap terrain, drawing triangle strips. What is the optimal patch size for rendering, and how to copy height data to patches easily?

Share this post


Link to post
Share on other sites
You shouldn't have any copying going on at all. Each patch should have its own vertex buffer already filled, or use some global vertex buffer for the entire terrain, then each patch indexes into it with a list of indices.

I've found that either 128x128 or 256x256 patches have been optimal for me. But everyone will have their own opinion on that.

Share this post


Link to post
Share on other sites
Basically you want a single, static patch on the graphics card. Then upload the heights, and merge them in the vertex-shader with the static x,y into a position.

Most important thing about the way you draw the triangles, is to make sure you're utillizing the vertex cache - ie. draw bands and merging them with degenerate triangles. This will allow you to draw an entire patch with a single drawcall. You might want to take a look at p.36 in this thesis on the subject.

Share this post


Link to post
Share on other sites
Quote:
Original post by gjoel
Basically you want a single, static patch on the graphics card. Then upload the heights, and merge them in the vertex-shader with the static x,y into a position.


I don't really see how that is practical using heightmaps without SM 3.0. Can you explain what you mean?

To the OP, I can't really offer an answer to your question, but if it spurs any thought maybe look into high order surface terrain - nurbs, bezier surfaces, etc. LOD is relatively simple to implement once you've got a patch renderer working, and is part of the very nature of HOS. Not only that, but bezier surfaces allow you to define a terrain of any shape, including concave zones and steep drop-offs. If it interests you, you can read about one possible implementation. Yann L has a lot to say on the topic too if you search past posts.

Example of HOS


Example of varying HOS LOD (closer patches = twice as detailed here)

Share this post


Link to post
Share on other sites
Currently with triangle strips I get around 32000 vertices for small 128x128 terrain... and thats a choker... so I must subdivide the terrain somehow for frustum culling and level of detail to make the farthest triangles as little detailed as possible

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
Quote:
Original post by gjoel
Basically you want a single, static patch on the graphics card. Then upload the heights, and merge them in the vertex-shader with the static x,y into a position.


I don't really see how that is practical using heightmaps without SM 3.0. Can you explain what you mean?


Actually, its very practical. You save huge amounts of memory. In my current terrain implementation I have a single vertex buffer that is 128x128 with x, y, and z coordinates. Then for each terrain page I have another vertex buffer with only height values. I then store the normals for each terrain page in a vertex buffer that stores the data in unsigned char format. And I do not store any texture coordinates.

Then in the vertex shader, as gjoel said above, I change the incoming vertex's y value to use the incoming height value from the terrain page's heightmap buffer. I then decompress the normal and compute the correct texture coordinates on the fly.

Share this post


Link to post
Share on other sites

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