0

Many Perlin Noise tutorials and implementations (here, here, here, etc.) use a function for generating pseudo-random values like this:

function Noise(integer x, integer y)
    n = x + y * 57
    n = (n<<13) ^ n;
    return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);    
end function

This function gives strange output: http://jsfiddle.net/byoybjkw/
Function is not working, since it often returns constant (not pseudo-random) value.

  1. Why this function is so popular and everybody recommend it?
  2. What are other possible implementations? jsfiddle demo will be appreciated.
Community
  • 1
  • 1
topright gamedev
  • 2,617
  • 7
  • 35
  • 53

1 Answers1

3

First, it's important to note that what you're looking at isn't Perlin Noise. You're looking at Hugo Elias' explanation of something called value noise, at the link that's perhaps responsible for 90%+ of the confusion on the matter. Value noise can definitely create some similar effects, but it's considerably slower (especially if you use the cubic interpolator, which is what you'd want for most effects). In addition, the function you're looking at is just the random base, not the actual interpolated value noise function.

Second, honestly I'd skip Perlin Noise and take a look at sommething called OpenSimplex Noise. Perlin Noise is an older algorithm that tends to exhibit significant grid artifacts by way of lining up all of its features along the cardinal axes and 45-degree diagonals. OpenSimplex Noise is useful for basically all of the same things as Perlin Noise: the noise takes an input point (in 2D, 3D, or 4D) and returns a value between -1 and 1, and the output values vary smoothy with the input coordinate changes.

OpenSimplex Noise is actually an algorithm I've developed on my own as part of a game deveelopment project, to serve as an alternative to the Simplex Noise algorithm that's patent-saddled for 3D+ implementations.

"Official" repo: https://gist.github.com/KdotJPG/b1270127455a94ac5d19 (Java)

Javascript port by someone else: https://gist.github.com/KdotJPG/b1270127455a94ac5d19 (Note: Only the 2D implementation so far, but you might not need more than that)

3D Perlin vs 3D OpenSimplex, in 2D slices: enter image description here (left is raw noise(x,y,0), next is b/w for negatives/positives, next is black near zero, next is noise(x,y,0.5))

2D OpenSimplex: enter image description here (for comparison's sake, note that 2D Perlin Noise looks almost identical to 3D at z=0)

KdotJPG
  • 811
  • 4
  • 6