Twitter  Facebook  Google+  YouTube  E-Mail  RSS
The One Man MMO Project
The story of a lone developer's quest to build an online world :: MMO programming, design, and industry commentary
An Algorithm for Generating Contour Maps
By Robert Basler on 2017-02-13 10:41:06
Homepage: onemanmmo.com email:one at onemanmmo dot com

or How I Discovered World Machine was Mangling my Terrain

I use World Machine to generate the terrain for my open-world RTS The Imperial Realm::Miranda. I chose World Machine because it generates beautiful terrains, and because it supports tiled rendering for really huge maps. I had a lot of trouble finding tools that could manipulate a 300x300km dataset. It also generates this nice looking contour map of the terrain (scaled down from 2K resolution map.)
contour_wm.jpg


Playing the game, I always felt that the contour map didn't really line up with the terrain. If you clicked on the high point of the contour map, it was a 50/50 chance you'd end up on a hill. I always suspected I might have done something wrong importing the World Machine terrain so I decided I would generate my own contour map from the imported terrain heightmap to see what I had done.

I was surprised to find that nobody really has written up an algorithm for generating a contour map from a height map. I thought on it for a bit and came up with this: Treat each contour map pixel like it is in the centre of four heightmap samples. northeast/southeast/northwest/southwest are the floating point corner sample heights, contourHeight is the vertical distance between the contour lines. To fill in the bitmap, we just need to find if the edges of each pixel are on different sides of a contour line.

if ( floor( northeast / contourHeight ) != floor( southeast / contourHeight ) ||
floor( northwest / contourHeight ) != floor( southwest / contourHeight ) ||
floor( northeast / contourHeight ) != floor( northwest / contourHeight ) ||
floor( southeast / contourHeight ) != floor( southwest / contourHeight ) )
{
SetPixel( black );
}
else
{
SetPixel( white );
}

Iterate over every pixel and you're done. Here's a tiny section from the top left of the full 8K resolution contour map.

contour_cropped.png


I needed a contour map that was a lower resolution than my terrain, so originally I generated the contour map at the same resolution as the terrain and then scaled it using GIMP. That produced disappointing results. (Note that the bitmaps here are scaled-down with GIMP because they don't need to be pixel-perfect.) A better solution was to decrease the resolution of the contour map by testing heightmap samples that are farther apart.

When I generated the contour map from my imported World Machine heightmap, I was very surprised to see that it looks like this.

contour_mangled.jpg


Wow, not even close to what it is supposed to look like. The reason was immediately obvious, I used the Tiled Rendering feature of World Machine to generate an 8x8 tiled heightmap. Apparently that doesn't actually work. I got on the World Machine forums for help, and received a suggestion to render with a higher blending percentage. I had originally used 25%, so I tried 100% (the maximum setting) and got this:

contour_100.jpg


That's better, but still not really at all accurate. As an experiment I rendered the terrain in a single tile, and the results as expected are perfect.

contour_single_file.jpg


Now when I click on the map, the terrain lines up perfectly in-game. Unfortunately, I still need tiled rendering to support my 300x300km terrain. With no help forthcoming from the World Machine developer, the takeaway here is that if you need to render a really large terrain with World Machine, you should render the largest possible resolution tiles to reduce the unavoidable tiling artifacts.

New Comment

Cookie Warning

We were unable to retrieve our session cookie from your web browser. If pressing F5 once to reload this page does not get rid of this message, please read this to learn more.

You will not be able to post until you resolve this problem.

Comment (You can use HTML, but please double-check web link URLs and HTML tags!)
Your Name
Homepage (optional, don't include http://)
Email (optional, but automatically spam protected so please do)
What is four plus three? (What's this?)

  Admin Log In



[The Imperial Realm :: Miranda] [Blog] [Gallery] [About]
Terms Of Use & Privacy Policy