0
\$\begingroup\$

I am making a game with procedural terrain, like minecraft. I have a perlin noise function which takes one integer and returns a number between zero and one. However, for terrain, I need a single density value from three coordinates: x, y and z. But my noise function only takes one number. Should I take the average of the noise values for x, y and z for a single density value? Or something else?

\$\endgroup\$
1
\$\begingroup\$

The short answer is it depends.

Yes, you can use three Perlin noise functions, average them & use the result. This will map 3 input parameters to a single output noise parameter. But there are some complications.

First, the noise functions should be uniquely seeded, otherwise you'll get some odd results. For instance, if you use the same seed & function for each coord, the coords <1,2,3>,<1,3,2>,<2,1,3>,<2,3,1>,<3,1,2>,<3,2,1> will all have the same values & this can lead to undesirable symmetries & artifacts in the final result.

Second, even if you do use uniquely seeded functions for each coord, taking the average essentially washes out or mutes some of the original signal.

Usually, the preferable solution is to use a higher dimension Perlin noise function. Perlin noise can be defined as an n-dimensional function. If you need a unique output for 3 input parameters, using a 3D Perlin or Simplex noise function will give you what you want without worrying about multiple seeds, muted results & other annoyances.

That being said, if you haven't already done so, read through some of the procedural-generation & terrain posts. For instance you may discover that you actually want to use 2d noise function to create a height map for the surface & then use an additional technique to carve out caves beneath the surface.

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

There are higher-dimensional noise functions available, but if you're stuck with this one, you can always consider using the Cantor Pairing function. It is very easy to implement and can be pre-computed.

See https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function for further details.

\$\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.