Question

The Perlin.GetValue(x, y, z) method of libnoise (using the C# port) returns 0's if the input values are integers. How could I go about mapping a 2D array of tiles--as the indices of an array are integers--to the values of the noise? This makes little sense to me as even 3D terrain eventually rests upon whole integer values. For those who are generating such 3D landscapes, are these positions in the terrain always restrained to being a value of 0?

EDIT: I should mention that I am using a chunk system, so I loop through each chunk's [32, 32] array of tiles to get the Perlin noise values. I was hoping that by adding the offset of the chunk in world space to the [x, y] value of the tile in the array I could have continuous terrain. Regardless, I tried something like this and still got zero from the noise function:

double temp = generator.GetValue((x + offsetX) / ChunkSize, (y + offsetY) / ChunkSize, 0);

EDIT 2: I output the values of the noise functions to 32x32 textures and put them next to each other. Noise is being produced but it isn't continuous despite adjusting the input of the x and y values for the offset of the chunk.

enter image description here

EDIT 3: Problem solved. My offset values were set to pixel coordinates instead of tile/chunk coordinates. I was multiplying the index of the chunk by the chunk size times the tile size instead of just the chunk size (which is in tiles).

Was it helpful?

Solution

The input values to Perlin.GetValue(x, y, z) are doubles and not technically limited to the range 0.0-1.0 but I would recommend you take all your array indices and divide them with the length of the array in that dimension so they all fall in the range 0.0-1.0 and you should get nice noise values, if get too much noise you can adjust that with the scaling if the indices, for example scaling between 0.0 to 2.0 instead might produce a bit smoother noise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top