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;
}