# How to make terrain infinite?

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

## Recommended Posts

A Terrain is made by heightmap.I want to make it infinite. Must I make seamless heightmap and then tile it to infinite? If yes,how to make seamless map?

##### Share on other sites
I'm going to explain creating tiled noise functions in one dimension, it can then be extrapolated to 2D but that would need more text.

You have two noise functions (your height maps), f(x) and g(x) where 0 < x < 1

Let's assume those noise functions have a certain level of regularity (for instance, they're perlin noise) between 0 and 1, and that you want the same amount of regularity on the entire set of reals (to be able to tile it).

To do this, you create a third noise function, h, by averaging f and g this way:

Between 0 and 1/2:
h(x) = 2 * (x * f(x) + (1/2 - x) * g(x+1/2))

Between 1/2 and 1:
h(x) = 2 * ((x - 1/2) * g(x-1/2) + (1 - x)*f(x))

You can now tile h and the connections will appear to be seamless.

To do this in 2D, you need four functions: you create two seamless horizontally-tiling heightmaps using two of them each time, as seen above along the "x" variable, and then use these two to create a fully-tiling heightmap along the "y" variable.

##### Share on other sites
thanks.
but no function.
I just use a image file as height map.

##### Share on other sites
The most fundamental principle of a heightmap is that you have a function z = f(x,y). In your case, f(x,y) == (constant scale factor) * (the luminosity of pixel (x,y))

##### Share on other sites
If you really don't want to use any randomly generated data, then you'll need to tile your heightmap infinitely.

Possibly the easiest way to make a single heightmap tileable would be to make the values on the top edge the same as those on the bottom, and the same with right and left. At the very least, they should be close enough as to produce realistic slopes between the bottom pixels and the top of the next tile.

As far as coding it, you'd just need to draw some number of vertices away from the camera. You obviously can't draw an infinite number, but you should draw enough to reach past your line of sight. Basically, you draw the heightmap normally, then when you reach the end of the vertex data and haven't drawn far enough, you wrap arpund to the top and keep drawing as if it was extra height information.

Of course, unless your heightmap is huge and contains only a small number of distinguishing features your terrain will appear to repeat itself. It might work better to connect a series of heightmaps in random order, but it would be a little trickier to make it seamless.

##### Share on other sites
Yeah, infinite maps can be difficult to achieve. The two ways that I know of the accomplish it are to use a mathematical function that will creat a sort of hilly effect that can repeat forever. This may or may not be difficult to implement, but the map would probably be a bit repetetive depending on the complexity of the math (a sine wave probably wouldn't do it).

The other way is to just tile heightmaps together. This can be difficult to do since the maps will have line up perfectly in height and slope on the edges.

Both of these solution would create repetitive terrains, but if you use more complex algorithm/large heightmap, it may be possible to reduce the effect a bit.
Either way, you obviously need to implement some sort of culling/LOD system to make it easier to render. Maybe implement some basic fog and just set yourt max draw a little farther.

##### Share on other sites
Infinite Terrain Tutorial about 3/4 down the page.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634058
• Total Posts
3015288
×