I am trying to create a set of functions to manipulate noise, similar to Libnoise, Fastnoise and the Accidental Noise Library. The end goal is to produce terrain.
As recommended by this article (http://accidentalnoise.sourceforge.net/minecraftworlds.html) I am starting out with a 'Gradient' function. Quoting the author:
The Gradient function is given a line-segment in N-dimensional space (ie, in whatever coordinate space we are working in, be it 2D, 3D, or higher) and calculates a gradient field aligned along this segment. Input coordinates are projected on this line, and their gradient value is calculated depending where on the line they lie in relation to the endpoints of the defining segment.
Even after repeatedly reading the article and looking at these two other questions I found (2D Terra(ria)in generation - Accidental noise and Accidental noise - Gradient function) I'm still having problems understanding exactly what the function is doing.
- My test chunk is of size 32x32x32 and ranges from -16 to +16 on the x, y and z axis. In this case, would the inputs to the function be x/32, y/32, z/32?
- Does the function map points between 0 and 1 (as input) to a point between 1 and -1 (as output)? I.e if my x, y and z where -16, -16, -16, would I get 1, 1, 1 back?
- Why in the extract below is the line segment (0,1)->(0,0) rather than (0,0)->(0,1)? Given that the example line segment is defined as x1=0, x2=0, y1=0, y2=1.
The Gradient function accepts a line segment in the form of (x1,x2, y1,y2) for the 2D case, extended to (x1,x2, y1,y2, z1,z2) for the 3D case. The point formed by (x1,y1) delineates the start of the line segment, which is mapped to 0. The point formed by (x2,y2) is the end of the line segment that maps to 1. So here we are mapping the line segment (0,1)->(0,0) to the gradient.
Any help on this would be greatly appreciated, thanks.