Perlin noise gradient function

I am looking to adapt Perlin's 3D noise algorithm to lower dimensions, but I am having problems with the gradient function as I do not fully understand the reasoning.

The original Perlin gradient function takes four arguments: a hash and a three-dimensional coordinate (x, y, z) . The result of the function is returned based on the value of hash mod 16 , as follows.

  • 0 : x + y
  • 1 : -x + y
  • 2 : x - y
  • 3 : -x - y
  • 4 : x + z
  • 5 : -x + z
  • 6 : x - z
  • 7 : -x - z
  • 8 : y + z
  • 9 : -y + z
  • 10 : y - z
  • 11 : -y - z
  • 12 : y + x
  • 13 : -y + z
  • 14 : y - x
  • 15 : -y - z

Return values ​​from 0 to 11 create a kind of pattern, since each combination is presented once. However, the last four are duplicates. Why were they chosen to match the last four returned values? And what would be the similar cases with two (x, y) and one size (x) ?

+7
source share
1 answer

... the late answer is better than no one ?; -)

The grad function in the “enhanced noise” implementation computes the point product between the x, y, z vector and the pseudo-random gradient vector.

In this implementation, the gradient vector is selected from 12 parameters. They lower uniformity of choice and add the numbers 12 and 14, because faster hash & 15 to make hash % 12

For two-dimensional perling noise, I used only 4 gradient vectors without any visible problems:

 return ((hash & 1) ? x : -x) + ((hash & 2) ? y : -y); 
+9
source

All Articles