Simplex noise algorithm always returns 0 noise at x = 0

Started by
2 comments, last by swiftcoder 8 years, 1 month ago

I am using a Simplex noise algorithm to generate noise, both in 1D and 2D. The problem is that for both dimensions the noise value is always 0 for x=0 (or for x=0, y=0 in the 2D case).

Can I modify the algorithm to give random values at 0 also?

Here is the code:


public static float Generate1D(float x, float? noiseFrequency = null)
        {
            if (noiseFrequency.HasValue)
            {
                x *= noiseFrequency.Value;
            }

            int i0 = FastFloor(x);
            int i1 = i0 + 1;
            float x0 = x - i0;
            float x1 = x0 - 1.0f;

            float n0, n1;

            float t0 = 1.0f - x0 * x0;
            t0 *= t0;
            n0 = t0 * t0 * grad(SeedNumbers[i0 & 0xff], x0);

            float t1 = 1.0f - x1 * x1;
            t1 *= t1;
            n1 = t1 * t1 * grad(SeedNumbers[i1 & 0xff], x1);
            // The maximum value of this noise is 8*(3/4)^4 = 2.53125
            // A factor of 0.395 scales to fit exactly within [-1,1]
            float result = 0.395f * (n0 + n1);
                       

            return result;
        }
Advertisement

You can modify it by arbitrarily offsetting the coordinates before you feed them. e.g.:


static const float SuperSecretSauceValue = 1.5423f;

public static float MySpecialSnowflakeNoiseFunction1D(float x, float? noiseFrequency = null)
{
    return Generate1D(x+SuperSecretSauceValue, noiseFrequency);
}

Most forms of coherent noise are defined to be zero at lattice points, and (0,0) is usually a lattice point. Note that noise is not "random". It's designed so that the same inputs (without offsetting) always give the same output. That's desirable for a lot of reasons, particularly reproducibility.

Did not know about lattice points before. They are certainly not useful in my application, but at least I have a workaround.

There's an interesting post on the topic over on reddit.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement