0

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).

Bagofsheep
  • 159
  • 1
  • 1
  • 8

1 Answers1

0

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.

Daniel
  • 3,741
  • 1
  • 16
  • 21
  • I probably should have mentioned 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);` – Bagofsheep May 12 '14 at 08:05
  • if `(x + offsetX) / ChunkSize` is not an integer that should give you values. One other thing to note is that the output from the `GetValue` function is in the 0.0 to 1.0 range so you might want to scale that. – Daniel May 12 '14 at 08:27
  • Well if it is the first chunk, and it is at index 1 in the x axis of the array, it should be (1 + 0) / 32, which should be returning a double. – Bagofsheep May 12 '14 at 09:01
  • Ah, I had to caste the values to doubles. It is now giving output. Now to see how the terrain looks. – Bagofsheep May 12 '14 at 09:09
  • Well 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 and x and y values for the offset of the chunk. – Bagofsheep May 12 '14 at 11:52
  • What offset values are you using? From the image you posted in 'Edit 2' it looks like the you have 9 32x32 chunks which gives us a total area of 96x96 so to get everything continuous the following offsets should work (Assuming top left is coordinate (0,0)): Top Left: `GetValue((x + 0) / 96, (y + 0) / 96, 0);` Middle Top: `GetValue((x + 32) / 96, (y + 0) / 96, 0);` Middle Left: `GetValue((x + 0) / 96, (y + 32) / 96, 0);` Center: `GetValue((x + 32) / 96, (y + 32) / 96, 0);` Bottom Right: `GetValue((x + 64) / 96, (y + 64) / 96, 0);` ... and so on, you see the pattern? – Daniel May 12 '14 at 13:16
  • To get continuous perlin noise you need to use "global coordinates" (whats "global" can vary) that are unique and itself continuous over the whole "problem" area. Someone with a similar problem: http://answers.unity3d.com/questions/298703/perlin-noise-continuous-through-different-objects.html – Daniel May 12 '14 at 13:20
  • Yeah, that was my problem. the offset was the index of chunk * (Chunksize * TILE SIZE) so it was giving pixel coordinates instead of tile coordinates. It is now just Index of Chunk * Chunksize. It seems to work now, thanks! – Bagofsheep May 12 '14 at 20:46