Question

I'm programming a terrain engine that uses Minecraft-esque chunks. The chunks are generated seperately using the Diamond-square algorithm.

The problem is that these chunks aren't lining up, they're completely seperate. I've tried a lot of things to make them do so, but so far nothing has worked as it should.

Edit: Also, the world I'm trying to create is not infinite; it generates a 33x33 array of chunks, each with a global height value assigned by another Diamond-square generator.

Is there a (simple, preferably) way to modify the diamond-square engine to make the chunks line up?

Was it helpful?

Solution

So you generate each top-level square of the diamond-square algorithm as a separate chunk?

You have to share the four corner points of that chunk with surrounding chunks.

There is very easy way to do this. You just require a noise function with two parameters (assuming you are generating the terrain in 2D) - a function which returns always the same pseudo-random number for the same seed (which remains constant for the whole map) and the two parameters. So if you ask the function for the value on coordinate [-100, 500], you will always get the same number (which ensures that the surrounding chunks line up).

Example of such function is this:

function Noise1(integer x, integer y)
    n = x + y * 57
    n = (n<<13) ^ n;
    return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);    
end function

Source.

EDIT:

My bad - you should not rely on the parametrized noise function only for the four corner points, you have to use it for all the random numbers generated within the diamond-square algorithm.

If this doesn't work, you are doing something wrong on your side.

OTHER TIPS

See this answer: Making the diamond square fractal algorithm infinite

Your better bet would be to either go entirely noise, or use my nifty infinite diamond squared algorithm. And just truncate it, at your edge. If you want to call some region a chunk so be it. It's easy to lookup any point in an such and such an infinite field.

Or my explanation and implemented example here: http://godsnotwheregodsnot.blogspot.com/2013/11/field-diamond-squared-fractal-terrain.html

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