Procedurally Generated Infinite Dunes Terrain in Real Time
I’m working on my own role-playing game inspired by Wizardry 8 and Might & Magic 6. Since I chose the desert as the first biome, I’ve focused on optimizing procedural generation specifically for it. You can see the result in the video.
I experimented with various generation techniques, including vertex shader–based terrain generation - using a mesh that covered the required area, with a shader applying vertex transformations. In practice, the mesh itself stayed in place as the camera moved; only the vertices changed, creating the illusion of movement. However, this turned out to be slightly more expensive than generating the terrain dynamically on the CPU, since the vertex shader processes every vertex each frame. With CPU-based mesh generation, no recomputation happens for the entire lifetime of a chunk.
Chunks themselves are stored in a pool and reused: as the camera moves forward by one chunk's size, a new line of chunks is created ahead, while a line of chunks behind the camera is released and returned to the pool. New chunk generation is spread across several frames to keep the framerate perfectly stable. Generating everything in a single frame is possible, but can cause occasional drops.
At 800p (16:10), my modest MacBook Air M3 with 8 GB of memory pushes over 1,100 FPS - even with real-time terrain generation on a single CPU thread. The dunes come with collision meshes, so you can walk on them. 520k+ primitives drawn, ~65 draw calls. Draw distance is ~1,800 meters, flight speed is 500 m/s, and altitude is 60 meters.