"I think it would be a very good idea."
- Gandhi, when asked what he thought about western civilization.

Framework 3 (Last updated: February 6, 2017)
Framework 2 (Last updated: October 8, 2006)
Framework (Last updated: October 8, 2006)
Libraries (Last updated: September 16, 2004)
Really old framework (Last updated: September 16, 2004)
Infinite terrain
Sunday, November 17, 2002 | Permalink

Source code
InfiniteTerrain.zip (602 KB)

GL_ARB_vertex_buffer_object or GL_ATI_vertex_array_object
This demo shows how to create a highly detailed infinite world which basically requires no storage space. The terrain is based on a mathematical formula, pretty much any continuous function can be used. I'm using a function based on perlin noise, one perlin function defines the large scale detail and on top of that I add another perlin function for finer details.
It's a no brainer to use such a formula for defining your world. The tricky part is to let the user go anywhere in the world and still be able to maintain some level of performance. Evaluating perlin noise functions isn't that quick and even if it would be you would still have to pass all your geometry over the AGP bus every frame. To solve that problem I have splitted the world into blocks. I'm deciding which blocks will be in view in the current frame, then evaluate the blocks as neccesary from the provide formula, then upload them to the graphic card and draw. The next frame it'll repeat the procedure, except that this time there are stored block on the card that it can reuse. As soon as a new block is needed it's evalutated and uploaded. Obviously, you can't just upload new stuff in infinity, you'll have to delete sometime too. I haven't implemented any fancy scheme to decide which blocks to drop and when, instead I just use a fifo and delete the first uploaded block when a certain amount of blocks have been uploaded. For this demo it's good enough.
Another great thing, it's quite easy to do LOD with this approach. Just use an appropriate index buffer for each block depending on distance, quite analogous to mipmapping, except there's no filtering. This simple LOD scheme improves performance (believe it or not) more than 6x.

This demo should run on all graphics cards. Decent performance can only be expected on cards that support GL_ARB_vertex_buffer_object or GL_ATI_vertex_array_object though.

Updated with support for the GL_ARB_vertex_buffer_object extension.