# How can I improve the efficiency of my procedural terrain generation and smoothing?

I'm developing an algorithm that generates infinite procedural terrain. It is currently inefficient. How can I improve it?

The algorithm starts by generating a 16×16 height-map with simplex noise per terrain tile, then goes through a few "smoothing iterations" (averaging height relative to neighbors, and adjusting height to look connected).

• Smoothing passes are by their nature, costly. The best you can do is adapt the simplex parameters to produce a smoother result, so that no post-processing is necessary. Or, don't worry about speed when you have no idea yet of how it's going to impact your game! Commented Jul 21, 2015 at 12:18
• Why do you think your algorithm is inefficient?
– Anko
Commented Jul 21, 2015 at 20:23
• You could post your code to the code review stack exchange to get some insight. It's hard to suggest improvements without being able to see what you're doing. Commented Aug 21, 2015 at 4:31

With Simplex noise, lower frequencies are smoother and higher frequencies are bumpier. The first thing to try is to use a lower frequency, and take out the smoothing step.

I have a rough demo here — use a lower freq start and freq range to see smoother noise, or use a higher freq start or range or see bumpier noise.

Always hard to answer a "best way" question, it really depends on what you want to generate.

But anyway, you say you are smoothing out the vertices in relation to it's neighbor. But the smoothing should already be done by the noise itself with the correct parameters. You can generate all kinds of noise patterns with multiple iterations of different parameters and just just build your map on that final noise result, whether that is a tile map with smooth gradients of color a map of blocks or voxels or a terrain mesh.

You could also not re-invent the wheel and use some already existing library for noise-generation.

I recommend libnoise2, which is highly optimized and uses SSE/2/3/4/AVX to speed up the process and does a great job. It also has multiple generators and multiple parameters which make later terrain varieties easier to implement.

You could also use libnoise, which has much more options, but is a bit slower.

Another way you can speed up your terrain generation is parallellism. Most CPUs already run 4 cores, so your gain can be well above 50%.