0
\$\begingroup\$

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).

\$\endgroup\$
  • \$\begingroup\$ 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! \$\endgroup\$ – Engineer Jul 21 '15 at 12:18
  • \$\begingroup\$ Why do you think your algorithm is inefficient? \$\endgroup\$ – Anko Jul 21 '15 at 20:23
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Nick Savage Aug 21 '15 at 4:31
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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%.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.