Skip to main content
gamedev.net
🔒 Locked

Heightmap internal datatype

Started by Ivo Leitao 3 replies 550+ views
Original Post
Ivo Leitao
Ivo Leitao
What is the best way to represent an height map, should i use an int array or a float array? I'm trying to build an abstract height map representation as the basis of some concrete implementation like mid point displacement, perlin noise etc... Tnks in advance
circlesoft
circlesoft
Since heightmaps are grey-scale, you can use a single channel for them. Storing them as floats should work just fine. If you want to store them as textures, you can use the following formats that are intended for single-channel maps:

- D3DFMT_L8 (supported by all recent cards)
- D3DFMT_L16 (supported on SM2+ hardware)
- D3DFMT_R16F (supported by some SM2 hardware)
- D3DFMT_R32F (supported on SM2+ hardware)
NickGravelyn
NickGravelyn
Definitely use an array of float values. Otherwise scaling it becomes too hard and you wind up with weird intervals between heights. Trust me.

The best way, IMHO, of storing data for heightfields is in a pointer to an array. That way your size is determined at runtime. Assuming you're using C++, here's a bit of code to look at:

class Heightfield{public:   Heightfield(int w, int d);   ~Heightfield();   float HeightAtCoord(int x, int y);private:   float *height;   int width, depth;};...Heightfield::Heightfield(int w, int d):width(w), depth(d){   height = new float[w * d];}Heightfield::~Heightfield(){   delete[] height;}float Heighfield::HeightAtCoord(int x, int y){   return height[y * width + x];}


Now obviously you'd want to put some checks in there to prevent using indices over width * depth and below 0, and make sure that the initializer doesn't accept values less than 1, but that's the base for a decent heightfield class. Again this is all in my opinion so other people may suggest other ideas.
Promit
Promit
There's no reason to use anything other than floats. You're going to want to submit the data to the graphics card in 32 bit floating point anyway, so you may as well keep the same representation throughout.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Ivo Leitao
Ivo Leitao
Tnks a lot for your kind answers, now my problem is the output, should i build textures directly (with D3DXFillTexture for example) or there is some kind of advantages in keeping an array of floats ?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.