- Home /
How does Mathf.PerlinNoise Work?
I've been trying to make a sort of randomized terrain for a while, and I'm unable to write a perlin noise function myself, partly due to laziness and partly to being a total noob.
So I borrowed the Mathf.PerlinNoise function. The documentation says that you give it the two coordinates, and it gives you a random number on a texture with the same coordinates or something.
But when I printed a bunch of Mathf.PerlinNoises, with different hand-typed values, all of them printed the same number : 0.4652731. So can anyone explain this to me?
EDIT: Here's my script:
function Start () {
print(Mathf.PerlinNoise(0, 0));
print(Mathf.PerlinNoise(2, 0));
print(Mathf.PerlinNoise(0, 5));
print(Mathf.PerlinNoise(10, 3));
print(Mathf.PerlinNoise(2, 0));
print(Mathf.PerlinNoise(1, 1));
}
Here's the results (one of them):
0.4652731 UnityEngine.MonoBehaviour:print(Object) PerlinHeight:Start() (at Assets/PerlinHeight.js:5)
Answer by Eric5h5 · Jul 04, 2013 at 04:52 AM
Whole numbers will return the same result; use fractions.
Answer by robertbu · Jul 04, 2013 at 03:41 AM
Think of PerlinNoise() as producing value in a random terrain. That is adjacent values are not random, but instead will produce similar values (perhaps a bit more, or perhaps a bit less) as if you are walking some hilly countryside. I find that when working with Perlin noise I have to get the range of values right. Here is a answer with a script for creating a hilly plane. It should be straight forward to modify it for use in a Terrain.
http://answers.unity3d.com/questions/417793/perlin-noise-plane-manipulation.html
But I don't want a mesh - I want the heights of different points.
The mesh part is irrelevant; the point is that it's a demonstration of how perlin noise works.
As @Erich5h5 says, the link was to demonstrate how to use PerlinNoise(). Lines 24-26 make the height calculation. The height of the mesh (which will be the same or similar calculation for a Terrain) is done on line 26. If you know Terrains, the conversion should be easy.
Answer by gonzolot · Sep 25, 2016 at 11:14 AM
Mathf.PerlinNoise work with smaller values marked as float. Like:
Debug.Log(Mathf.PerlinNoise(0 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(0 / 100f, 5 / 100f));
Debug.Log(Mathf.PerlinNoise(10 / 100f, 3 / 100f));
Debug.Log(Mathf.PerlinNoise(2 / 100f, 0 / 100f));
Debug.Log(Mathf.PerlinNoise(1 / 100f, 1 / 100f));
Answer by ebogguess · Jul 04, 2013 at 03:42 AM
I've never used it, but from the documentation, it appears that given x and y coordinates, the algorithm will return a value between 0.0 and 1.0. Different coordinates should give different values.
That's what I thought too, but different coordinates somehow yield the same results.
Your answer
Follow this Question
Related Questions
Random Terrain Generation (Trees, Details, Textures) by passing a Seed? 0 Answers
Any Reason this would make Unity Freeze up? 0 Answers
Tree position on random Terrain (y axis) 0 Answers
Tiling problem with Perlin generated terrain chunks 1 Answer
How can I correctly offset seeded perlin noise over multiple terrains? 1 Answer