For a game I'm making in the blender game engine, I need to generate an infinite terrain - preferably in chunks and unloading when they get too far away. Perlin noise would probably be a good way to do it (I think) but I'd need to have it split into chunks and also not only infinitely generate but unload itself.
-
By infinite terrain, do just mean a repeating texture? A mesh object cannot be infinite in size, but it can appear that way if you fade it out towards the horizon. – Todd McIntosh Jun 23 '15 at 03:53
-
Could I use this repeating texture as a heightmap? @ToddMcIntosh – Jacob_ Jun 23 '15 at 07:41
-
Of course, you would want something with a fractal perlin noise probably. – Todd McIntosh Jun 23 '15 at 07:46
-
What's a fractal perlin noise? and how would I make the repeating texture?@ToddMcIntosh – Jacob_ Jun 23 '15 at 18:00
-
Sorry, the fractal options are in Musgrave texture type. For broader details, you could just use the Cloud texture. All of these are procedural textures which tile infinitely. – Todd McIntosh Jun 23 '15 at 18:55
-
@ToddMcIntosh I am afraid procedural textures does not tile. So they don't tile infinitely but rather go infinitely. – Jaroslav Jerryno Novotny Jul 26 '15 at 11:09
-
Okay but normally the infinite pattern of the procedural texture is a good thing. You want the same pattern on every tile then? – Todd McIntosh Jul 26 '15 at 18:28
2 Answers
Rather than dynamically load and unload chunks of terrain just move displacement mapping of a fixed static subdivided plane.
The displacement should be made from mix of blender procedural textures (if you mix multiple clouds and musgrave textures you can get mountains, rivers, etc.)
The plane should be big enough so you can't see its borders.
And the character, camera and ground will be obviously static except of some local animations. The movement would be done with rotating and offsetting (the order is important) the displacement and texture of ground.
The resolution of the ground plane should be detailed around character and less divided to the borders. If the ground will be too low res you will see the geometry "float" over the displacement. You can see how that looks here.
If you know how normal mapping works you can generate procedural normal maps to accompany the procedural displacement and procedural textures of the terrain. This would minimize the floating.
So the ground is sorted.
Any objects the character would encounter on it's journey must be instanced and moved around. The height of such objects (to sit on terrain properly) can be rigged the similar way as a box floats on an ocean.
You could also make the displacement mapping use world coordinates and move the plane under a character, but if you will walk huge distances I would rather keep everything close to the scene origin.
Here is done dynamic loading and unloading of terrain tiles, but it uses heavy scripting and is totally out of scope of this site.
You might want to use a different engine than BGE for this kind of application. I would use BGE only for some basic arcade platformer, not for an open world project..
- 39,634
- 9
- 103
- 186
- 51,077
- 7
- 129
- 218
Do the sections once added need to be the same if they get re-entered again. That is, if an entity goes from chunk a to chunk c, then to chunk f, then to e, then to b, and back to c, does c need to be the same when the character re-enters as it was the first time?
If I were going to generate the terrain, I'd determine the chunk size, and create the chunks by adding plane primitives of that size, and subdividing them to an extent which gives a reasonable vertex density. Then I'd apply a displace modifier to the mesh choosing a suitable noise texture with the parameters you wish. The part up to here seems simple. The difficult part would seem to me to be if you want to have the mesh of chunk c be the same if you re-enter it again from the same direction, or different ones from the previous time. Then you'll need to keep track of the parameters for each chunk so they can be used to regenerate that chunk of terrain if needed.
- 5,446
- 7
- 23
- 44