SimpleTerrain - Faster terrain generation

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 :smirk: (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

  1. 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.
  2. Maybe by trying out more with GeoMipTerrain, with different parameters, I would have gotten satisfactory results.
  3. 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.
  4. The heightfield image resolution seems to affect this speed difference.
3 Likes

A short video for if you want to see just the sample program in action

https://youtu.be/k5F2mx5U1Rs

1 Like

Cool! I’ve been watching your devlogs too, they’re pretty cool! Keep up the amazing work, joni! :smiley:

1 Like

Cool, thanks for sharing!

I do notice that ShaderTerrainMesh is conspicuously absent in your comparison. :slight_smile:

2 Likes

@xTrayambak Big thanks! I’m new to the video making “business” and I guess there is still room to improve a lot from the audience’s perspective :smile:

@rdb Yes, I’m in the process of finding a GPU that makes the numbers favourable for SimpleTerrain :smirk: :joy: No but seriously, when I started, anything related shaders seemed scary voodoo and HeightfieldTesselator and GeoMipTerrain had thick dedicated manual pages so I went with them. It would be actually interesting to add ShaderTerrainMesh to the benchmarks and see if there are (any) hardware configurations where the CPU guys come on top (probably not).