The right way to save terrain

I’m working on ‘infinite’ terrain in my game, but I hit into several problems.

Loading terrain from image makes terrain too stairy (it’s probably caused by poor grayscale wide of png (0-255)), this can be partically fixed by smooth(). But it cause another problem, smooth moves with terrain edges and two maptiles doesn’t fit to each other. And I found out that creating TerrainQuad from heightmap is real bottleneck (it takes ~1s on my laptop to load one tile) So I was going to write my own map editor which would save directly terrainquads which I would load in my mapmanager (I tried to use terrain editor in jmonkeyplatform but I gave up after 15 tries which each of them ended with frozen jmp).



I’m using patchsize 64 and totalsize 513 and if I save this using BinaryExporter I get >10MB file, which is too huge (I’m going to have ~1000 of these tiles in my game and 10GB just terrain data is IMO too much. Even compressed it would be ~3.5GB)


  1. What’s the right way to save terrain data to have it fast loaded, smooth enough and in small package (~1MB).
  2. What does patchsize affects? I mean this in performance/memory usage way…





    please excuse my lame english

Are you using the latest version of the terrain editor from SVN? The Alpha4 version is buggy.

Smooth your heightmaps before they are loaded using a gaussian blur, this will remove the steps.

If you have 1000 tiles, are you using TerrainGrid? If not you are going to run into memory issues.



If you are loading in your terrain each time with a heightmap image, you do not need to persist the terrain as a binary file.



Patch size is the smallest tile size (patch) of a terrain quad tree. It is the actual mesh. If you have a terrain quad with a total size of 512, and patch sizes of 64, then there will be 64 patches.



I am planning to reduce the saved file size of terrain in the future. By how much, I can’t say yet.

I’ll give a shot the version from svn.



Right now I’m not using TerrainGrid, I’m dropping and loading map tiles by my own map manager, but I was reading about TerrainGrid several minutes ago and it looks really good.



Heighmap is created by gradient in photoshop, I’ll try bluring it but… Right now I’m saving heightmap as gzipped binary files of float[], it’s small enough and it loads 5-10 times faster then from image and I have full range of float available.



About patch size… I was interested about memory usage and cpu performance… is it better to have more smaller patches or less bigger?



Is there any reason why BinaryExporter doesnt use any compression, at least as option?

I’d also advise on using async loading of tiles. I don’t know if terraingrid has it built in, if so then use it. I had tiles of 129 size but had only files of several 100 kb. Are you saving the textures within the files?

The terrain file size will be about 10mb if it is 512x512 in size, without textures. The size is due to the fact that there are about 260k vertices, normals, texture coordinates, and tangents all being saved.

I made a change this evening to have the terrain not save the mesh, but just the heightfield. It reduces the save size down to 1.1mb from 10mb. I just have to test it thoroughly to make sure it is not going to break things for people. If it is happy, I will commit it tomorrow.

I just committed the change to reduce file size for the terrain. Grab the latest version from svn and give it a try and see if it helps you out any.

Thanks a lot, I’ll give it a try tomorrow.