Jump to content
  • Advertisement
Sign in to follow this  
ReqPro

Perlin Noise seamless chunks problem

This topic is 2125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone!

First of all, hope this is in the right place ph34r.png

I've been fighting with this for a long time now, and I think I've come to the point where I've stared myself blind on the problem.
Here's hoping one of you can help me smile.png

Here's the thing; I've made a minecraft-type world, divided into chunks of each 32x32x128 blocks. I've got a perlin noise generator creating the heightmaps so that they'd (hopefully) be seamless.
I've come close, but there are some minor issues I just can't iron out.

As a picture says a thousand words, I'll attach a screenshot where I've highlighted the seams with a red line to highlight my problem.

fail.jpg

Now as you can see in the image above, there are some quite steep (and not very seamless) seams...
I'm completely at a loss as to how I'm going to remedy this.

Any pointers?

Thanks in advance,
Req

Edit:
Whoops, might be an idea if I included the code blink.png

Function call to generate and store noise:
[source lang="csharp"]
private void AddPerlinNoise(float f, float o)
{
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
Heights[i, j] += o + PerlinNoiseGenerator.Noise(f * (i + Index.X * Width) / (float)Width, f * (j + Index.Z * Height) / (float)Height, 0);
}
}
}
[/source]
PerlinNoise class functions:
[source lang="csharp"]
public static float Noise(float x, float y, float z)
{
int ix = (int)Math.Floor(x);
float fx0 = x - ix;
float fx1 = fx0 - 1;
float wx = Smooth(fx0);
int iy = (int)Math.Floor(y);
float fy0 = y - iy;
float fy1 = fy0 - 1;
float wy = Smooth(fy0);
int iz = (int)Math.Floor(z);
float fz0 = z - iz;
float fz1 = fz0 - 1;
float wz = Smooth(fz0);
float vx0 = Lattice(ix, iy, iz, fx0, fy0, fz0);
float vx1 = Lattice(ix + 1, iy, iz, fx1, fy0, fz0);
float vy0 = Lerp(wx, vx0, vx1);
vx0 = Lattice(ix, iy + 1, iz, fx0, fy1, fz0);
vx1 = Lattice(ix + 1, iy + 1, iz, fx1, fy1, fz0);
float vy1 = Lerp(wx, vx0, vx1);
float vz0 = Lerp(wy, vy0, vy1);
vx0 = Lattice(ix, iy, iz + 1, fx0, fy0, fz1);
vx1 = Lattice(ix + 1, iy, iz + 1, fx1, fy0, fz1);
vy0 = Lerp(wx, vx0, vx1);
vx0 = Lattice(ix, iy + 1, iz + 1, fx0, fy1, fz1);
vx1 = Lattice(ix + 1, iy + 1, iz + 1, fx1, fy1, fz1);
vy1 = Lerp(wx, vx0, vx1);
float vz1 = Lerp(wy, vy0, vy1);
return Lerp(wz, vz0, vz1);
}

private static float Lattice(int ix, int iy, int iz, float fx, float fy, float fz)
{
int index = Index(ix, iy, iz);
int g = index * 3;
return Gradients[g] * fx + Gradients[g + 1] * fy + Gradients[g + 2] * fz;
}

private static float Lerp(float t, float value0, float value1)
{
return value0 + t * (value1 - value0);
}

private static float Smooth(float x)
{
return x * x * (3 - 2 * x);
}
[/source] Edited by ReqPro

Share this post


Link to post
Share on other sites
Advertisement
Hi, I'm not entirely sure I understand your approach. I believe you're generating a heightmap based on a 2D slice of a 3D Perlin noise function. Is that correct? I gather that f is your frequency, and you call AddPerlinNoise once for each octave. I believe that you're meant to scale the contribution down by the frequency so it looks less spiky. I don't know what your float o is for, I suspect that may be the problem. if you pass a different value of o in for each block there would be inconsistencies. Given that your problem is between blocks, perhaps you need to show us the code for looping through blocks.

Share this post


Link to post
Share on other sites

Hi, I'm not entirely sure I understand your approach. I believe you're generating a heightmap based on a 2D slice of a 3D Perlin noise function. Is that correct? I gather that f is your frequency, and you call AddPerlinNoise once for each octave. I believe that you're meant to scale the contribution down by the frequency so it looks less spiky. I don't know what your float o is for, I suspect that may be the problem. if you pass a different value of o in for each block there would be inconsistencies. Given that your problem is between blocks, perhaps you need to show us the code for looping through blocks.


Hi Jeffery,

thanks for your response. You're right, I haven't provided the necessary information to give you guys the best chance of providing a solution.
I am indeed generating 2D heightmaps off of a 3D PerlinNoise function.
F is my frequency, o is an offset that is added to the result of the function as it generated slices of terrain with zero height. As I'm using it now, it has an offset of 0.25f.
I actually only run the noise function once per coordinate set as it is right now. I later on then add perturbation, erosion and smoothing. Wait a second....

I found the solution myself though, right now as I'm writing this - you gave me a lightbulb moment....
my erosion passes screwed up the seams! It's so obvious now... Since the erosion passes are performed on each chunk individually, they can't be truly seamless!

Thanks Jeffery for leading me on the right path - I hate when I sit with a problem so long that I just go completely blind to the obvious! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!