I have read some tutorials on perlin noise (for example this one) for my terrain generation, and I wanted to make sure that I understood it and can correctly implement it.
I start with 1 Dimension:
amplitude = persistence^i // persistence can have any value but mostly it is 1 or lower. It changes the amplitude of the graphs with higher frequency since:
frequency = 2^i //the 2 effects, that each graph reflects one octave, wich is not 100% necessary but the example happens do do it like this
'i' is the octave we are looking at.
Here is my attempt:
private float[] generateGraph()
{
float[] graph = new float[output.Width];
for (int i = 0; i < output.Width; i += 1/frequency)
{
graph[i] = random.Next((int)(1000000000000*persistence))/1000000000000f;
}
return graph;
}
I imagined the array as a graph, where the index is X and the value is Y. I search for a value for every multiple of texture.Width/frequency until the end of the array.
I have some random values I am using for now, which I have to connect with either Linear Interpolation/Cosine Interpolation or Cubic Interpolation. Which one should I use? Which is the most performant when I want to use the noise for terrain generation in 2D?
I would like to put the graphs in a 2D-array after this and then check for each value, if its higher than 0.5, it should get some material or texture.
Is this situation, how should I do it? Am I totally on the wrong track?
edit1: Before I put the graph in a 2D array, I would like to generate perhaps 5 other graphs with a higher 'i' and blend them (which shouldn't be too hard).
edit2: this implementation is nice and 'easy'.