In OMAPELI, I use a grid-based approach to manage terrain tiles, from Python. Calls are made to the HeightFieldTesselator (or GeoMipTerrain) to generate the terrain tiles on-the-fly but I struggled not to cause noticeable inter-frame-time spikes especially with high-detail tiles next to the player (1,2).
To solve this, I considered parallelization (threading, or Python multiprocessing->save>async-load) but before just throwing more resources (CPU cores) at at the problem, I wanted to first see if the terrain could be generated any faster.
So I coded the simplest type of terrain generator that I could imagine (vertices on a regular grid), in C++, hoping that without the competitors’ focal point systems maybe it could be faster. However, it didn’t really become faster until I commented out some stuff and discovered that only adding every second triangle made the generation nearly twice faster. And that leads us here.
This Panda3D modification (a git patch on release/1.10.x) introduces SimpleTerrain that can generate a terrain really fast from a heightfield image. But how fast?
It can be 40x-100x faster (3,4)
Attached are the patch, my benchmarking script and a sample. Not so polished or really ready to release but I have been sitting on this for months now doing nothing so maybe it’s better to get it out.
simpleterrain_20221114.zip (73.3 KB)
Known issues/disadvantages:
- I haven’t checked if the normals are correctly generated
- No focal point
- No tesselation (the used heighfield sets the max polygon-count)
- You have to build Panda from source (and to apply the patch before)
- more…?
Footnotes
- Here, I could have downsized the tiles and increased their numerosity but then I would have increased the Python overhead and the mesh-count-dependent batch overhead.
- Maybe by trying out more with GeoMipTerrain, with different parameters, I would have gotten satisfactory results.
- This benchmark is of course not fair for GeoMipTerrain because in its case you would be mostly using its much faster update method, not generate.
- The heightfield image resolution seems to affect this speed difference.