• Advertisement
Sign in to follow this  

How should I save heightmaps?

This topic is 4218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am creating a height map editor right now and I need to know how height maps are generally saved? Should I include the height and width at the beginning of the file or should the user have to know that before he loads it in? Also, should I use signed bytes, unsigned bytes or floats? Using bytes doesn't seem like it would give me enough height.

Share this post


Link to post
Share on other sites
Advertisement
You should save the height and width in the file. Do not make a user/program guess.

How are you using the heights internally? Floats? Unsigned chars? Why would you save them in another format (unless scaling them to 0-255 so as to save disk space, that is - but then why not just use uchars to begin with).

Share this post


Link to post
Share on other sites
I just use a TGA file, and divide the channels up (R,G,B,A), and multiply them by scalar values. For example, in a 32bit TGA, each component is 8bits (0-256), so just multiply the red component by 4, green by 3, blue by 2, and the alpha is left alone. Then add them together to get each vertex height. That way, the red and green channels defines your large scale features (mountains, valleys etc.), and the blue and alpha channels contain the smaller details, and overall terrain roughness.

I do it this way because it's easy to separate an image into channels in photoshop, and manipulate them separately. Usually for the large scale channels (red and green) you draw larger features at a low frequency, so you don't get stepping. The lower-scale channels (blue, alpha) can be higher frequency (even low contrast random noise) to provide the roughness and detail.

I usually convert the vertex heights to floats, and box-filter the terrain (upon loading it), just to get rid of any integer stepping artifacts.

HTH,

- Andrew

Share this post


Link to post
Share on other sites
If you have multiple files for a single map to describe textures and/or materials, I recommend using RAW file format, where you simply write or read a value in-between 0-255 and then do additional manipulations with it to achieve desired height. An example would be a map where you have ground level of 0 and top height of a 1000, is to read a value from the file at that particular location utilizing one dimensional array uipRawImageData and accessing particular height at (uiX, uiY) by using uipRawFileData[uiY * uiMapWidth + uiX], get the height value, then have formula to (1000/256)*uipRawFileData[uiY * uiMapWidth + uiX] to have height on scale from 0 to 1000.
Arudson's method, however is better than mine, in sense that it provides multiple channels in one file, one that can provide you with additional information such as features, stepping and other things.

Share this post


Link to post
Share on other sites
The traditional way of doing it is saving a TGA file - either as greyscale (if 8bit heights are used), or RGB, using the R and G channels as the most and least significant bytes of a 16-bit height value.

This is what Fractint does certainly.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement