Sign in to follow this  
Aramil04

OpenGL Scrolling Terrain Problem

Recommended Posts

Hi-ya folks, I'm currently working on a sort of endless terrain that 'scrolls' it's height values to give the impression of movement. The entire terrain is implemented using VBOs. Right now, the scrolling is somewhat inefficient: I pass an array of height values into the proper 'shifting' function that performs a couple of memmoves() that scroll the heights. The inefficient part is that after this function completes, I have to update the vertex data of the entire terrain such that the vertex y coordinates match the height values I have just scrolled/calculated. This requires an iteration through about 65,000 vertices, which is what I'm trying to avoid. I'm trying to look for a more efficient solution (more specifically, something where I can avoid that expensive traversal), but without success. I gave some thought to storing the vertex data in a different form: (xxxyyyzzz) rather than the usual (xyzxyzxyz), which would allow me to store each set of coordinates (x, y and z) as parallel arrays. From then, I could just perform the memmove() shifts on the y-array and then simply update the vertex buffer object's chunk of y-coords through a call to glBufferSubData(). However, OpenGL expects all vertex data to be in the form (xyzxyzxyz), which renders my idea useless. Is there a way around this? So, is there a more efficient way to handle the terrain scrolling that doesn't involve updating every single vertex? Thanks.

Share this post


Link to post
Share on other sites
Pass the terrain in as a (static) flat mesh, then use a vertex shader to change the vertices individually. You can use a procedural function with changing uniform inputs to update the vertices or a scrolling heightmap texture.

65,536 (I assume 256 squared?) vertices may be a lot for the CPU to update, but it's nothing for the GPU, especially when it's in-line with rasterization.

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