Heightmap with short datatype height values

I need to operate with quite large terrains and there could be problem with memory consumed by heightmap.

I need only one meter precision heights, so I don’t need float type to store them in.

Short datatype would be enough. The point is, that float is 32bit but short is only 16bit type in java.

So memory consumption by heightmap could be reduced nearly to half.

Is this possible? I have had a look on some TerrainQuad and related code, but it seems like quite complex problem to make it work.

I suggest not using large maps but do mapping of (maybe on-disk) data onto (a) smaller one(s). You can never view all of the data at full resolution anyway so putting in some kind of scaling mechanism that gathers the data and makes a map that is suitable for displaying it on screen.

Ok, I know there are other solutions like reduce density of heights or as you say not to display all terrain in full resolution but the idea of short type heights seems not too bad to by thrown away…

Anyway, is there any way how to compose several heightmaps with different grid density together? It could partially replace LOD algorithm but the main purpose is still to reduce memory consumption.

Think more like having one terrain that covers the visible area, not too huge. Then you have a helper class that has a method getAreaHeight(x,y). The returned value is based on the current “world” location and current scale that gets updated when you move the cam too far. The terrain is generated using this method and looks like a small part of a canyon or like a whole continent accordingly. The basic info for the heightmap can be stored in a database or something else. The idea is to interpolate data that you dont need for display before you fill the memory with it.

1 Like

Even if you could store terrain height as shorts, it still has to be converted to floating point to be displayed, its just that this conversion happens in the driver.

Another way would be to write a vertex shader that would fetch heights from a Luminance16 texture, this way the format of the data is short on both the CPU and the GPU and no intermediate conversion is required.

1 Like

to normen:

I am not sure if I understand. Do you mean getInterpolatedHeight(float x, float z) method from any heightMap class? If yes, is the idea to create low detailed terrain with more detailed data which I have not used and when camera moves close enough use overriden getInterpolatedHeight(float x, float z) method and get detailed data from database for example?

to Momoko_Fan:

Good to know there is a posibility. Thank you.

Yes, thats basically what I mean. Will give you lots of joy later when you project grows compared to lots of pain with big arrays. Arrays are good in/for theory but in practice take away way too much memory for no actual (or not needed) data. In practice a “magic box” class with a getValue(x,y) method is much more efficient. It could return an endless amount of values by storing just two basic numbers and generating a fractal from them for example, or read data from a database or from google… :slight_smile:

Thank you very much. This is very nice idea. I look forward to the “joy” :slight_smile: