Terrain LOD

Download (src+exe)

Motivation (nothing really worth reading, so skip if you want)

Recently I participated in the recruitment process of a certain game-making company and I was assigned a task to create an application which could render a heightmap on a GeForce 6800. I was looking for the right algorithm for some time, and I decided to use the one described in Game Programming Gems 6: Chapter 5.5 – GPU Terrain Rendering. The app itself is not too fancy, as a spent way too much time working out minor issues with D3D9 (this lib was the requirement). I prefer OpenGL for it’s beautiful API which combines simple and logical design with cutting-edge features. I dislike D3D9 for it’s inherent ugliness, but still it’s much, much better than it used to be back in the times of DirectX 5 (if my memory serves me right, the first one I stumbled across as a programmer). Nonetheless, the app didn’t get me the job, so maybe at least it will benefit someone out there in the Internets:)

BTW >> I just recently read about a new OpenGL extension (ATI only for now, s**t) – AMD_vertex_shader_tessellator – at http://fireuser.com/blog/tessellation_enhance_your_geometry/. Looks nice and seems to be able to replace large part of this algorithm. I hope NVIDIA implements this soon:)

Tech stuff

As mentioned above, this demo uses algorithm proposed in Game Programming Gems 6: Chapter 5.5 – GPU Terrain Rendering which is described in tons of places, so just google bing it. The basic idea is to assemble the terrain from a set of patches of different sizes and levels of detail. These patches however are rendered using a single precalculated vertex buffer, which is repeated all over the place with different offsets and scale. The interesting stuff is that it uses vertex texture fetch to get the right vertex height for the given coordinates within the map. Simple, yet fast and elegant.

My implementation differs slightly from the one described in the book:

  • LOD is continuous, with no “popping” (height of a vertex is lerped between value from patch LOD and patch LOD+1)
  • LOD calculation is linear instead of quadratic (just my preference)
  • Reference LOD adjusts itself to the machine, so that the demo tries to get at lest 30 fps
  • Terrain is nicely textured in fragment shader
  • Normals are calculated during heightmap loading

Misc

By default the demo runs windowed in 800×600 with default map. You can choose other settings by running it with arguments [mapfilename] -width:MyWidth -height:MyHeight. The map should be a DDS file of R16F format and with precalculated mipmaps.

Controls: WSAD + RF (up/down) + mouse look.

The default map is 4096×4096 (derived from a 10 MP photo of mine…) and works smoothly on my GeForce 9600:)

The app requires a recent DirectX9 to be installed (so that d3dx9_39.dll is not missing…).

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: