I am following this tutorial: Understanding Perlin Noise | Blog
To understand Perlin Noise. In particular, right now I am focusing on the following code section:
int xi = (int)x & 255; // Calculate the "unit cube" that the point asked will be located in int yi = (int)y & 255; // The left bound is ( |_x_|,|_y_|,|_z_| ) and the right bound is that int zi = (int)z & 255; // plus 1. Next we calculate the location (from 0.0 to 1.0) in that cube. double xf = x-(int)x; double yf = y-(int)y; double zf = z-(int)z;
If I am correct, the first 3 lines of code are calculating a set of 3 coordinates (xi,yi,zi) that range from 0 to 255 inclusive, as integers. This is, in other words, a 255x255x255 3D grid of unit cubes.
The next 3 lines are calculating the relative 0-1 coordinates inside of the cube in the grid the point (x,y,z) is mapped to.
My question is:
Is there any reason for this number to be 255? Or is this simply a number that was chosen because it made the algorithm faster (smaller grid, less numbers, faster hash lookup, caching...) and could easily be extended to any other integer (theoretically).
In either case, won't this generate a repetitive pattern?
What I mean by the second question is: If I have a set of (x,y,z) values that extend to "infinity" at regular intervals (let's say they all change at intervals of 1), won't I start seeing a clearly predictable/repetitive pattern emerge after around 255 steps in a given direction?
Finally, if a repetitive pattern emerges, how can you create more variation while keeping pseudo randomness?