Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Perlin Noise seamless chunks problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ReqPro   Members   -  Reputation: 103

Like
0Likes
Like

Posted 24 August 2012 - 08:05 PM

Hey everyone!

First of all, hope this is in the right place Posted Image

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 Posted Image

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.

Posted Image

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 Posted Image

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, 24 August 2012 - 08:30 PM.


Sponsor:

#2 jefferytitan   Crossbones+   -  Reputation: 2246

Like
0Likes
Like

Posted 24 August 2012 - 09:57 PM

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.

#3 ReqPro   Members   -  Reputation: 103

Like
0Likes
Like

Posted 25 August 2012 - 08:55 PM

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! :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS