Help with 1D Perlin Noise

Today I began to delve into the world of Perlin Noise to simulate a wind effect.

var turb = Mathf.PerlinNoise(Time.time, 0.0);

Sometimes, “turb” remains unchanged.
For example, from 12 to about 14 seconds “turb” remains completely unchanged.
This happens again at random points for random amounts of time, but always be the same every time I play the scene (ex: will always be unchanged between 12 and 14 seconds).

What did I do wrong?

PerlinNoise isn’t a random change from value to value.

Look at the image generated in the documentation:

You can see areas of the same shade over certain areas in some direction. When you sample across that region, you’ll get that value.

PerlinNoise is like a choppy sea. It’s got a rythmic rise and fall in its values like waves in a choppy sea. But at times… that sea will have a section of it that shows odd calmness amongst the choppiness. That’s what you hit.

Note, PerlinNoise is deterministic. You’ll get the same result for any given x,y coordinate. So every time you play it you’ll get the same results if you continue down the x axis (which you are doing since you pass in 0 for y).

You could get a random path every time by doing this:

public class SomeScript : MonoBehaviour
{

    private Vector2 _dir;

    void Start()
    {
        var a = Random.value * Mathf.PI * 2f;
        _dir = new Vector2(Mathf.Cos(a), Mathf.Sin(a));
    }

    void Update()
    {
        var v = _dir * Time.time;
        float turb = Mathf.PerlinNoise(v.x, v.y);
    }

}

You can get more variance with a random start point.
And you could also get faster or slower chop by including a scale value.

var v = _start + _dir * Time.time * _scale;
float turb = Mathf.PerlinNoise(v.x, v.y);
2 Likes

Or you can sum several perlin noises with different param scale and get more turbulent noise:

Like:

var turb = Mathf.PerlinNoise(Time.time,0.0) + Mathf.PerlinNoise(0.5 * Time.time,0.0) + Mathf.PerlinNoise(0.25 * Time.time,0.0) + ...;

http://paulbourke.net/texture_colour/perlin/

Then it shouldn’t be calm anymore

1 Like

You should also change the amplitude when you change the frequency, for proper spectral synthesis. The higher the frequency, the lower the amplitude.