I'm looking to adapt the 3D Perlin noise algorithm to lower dimensions, but I'm having trouble with the gradient function, since I don't 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 listed below.
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
The return values from 0
to 11
make a kind of pattern, since every combination is represented once. The last four, however, are duplicates. Why were they chosen to fit the last four return values? And what would be the analagous cases with two (x, y)
and one (x)
dimensions?