Advertisement Jump to content
Sign in to follow this  
captain_crunch

Simplex noise algorithm always returns 0 noise at x = 0

This topic is 1057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
        }
Edited by captain_crunch

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!