dynamic / random terrain generated at run-time

Rowan

15-05-2006 02:40:00

I'm fairly new to Ogre and even newer to PLSM2, but I've managed to begin my project and just now incorporated PLSM2 into it at the most basic of levels.

What I would like to achieve for my game is some sort of random map generation, and the problem at the moment is how do I incorporate this into Ogre?

The few posts I have managed to find have pointed to PLSM2, but now that I'm here, I can't seem to find any more information of the subject.

I have some vague references to using Splines, and I've found a reference in the 'template.default.cfg' file ::


#experimental spline terrain
#Data2DFormat=SplineField


I have also noted these references in the same file ::



#
#
#
# Especialized texture loader.
#
#(no pregenerated maps needed)
# Real-time (no pregenerated maps needed) splatting => splatting (needs DX9) and splatting5 (need shaders)
# Real-time (no pregenerated maps needed)Coloring => basetexture.
#



So I am assuming that it is somehow possible to dynamically generate terrain, possibly using Splines.

If so, how would this be implemented?

I'd just be happy using my own algorithm to generate a 2D array of heights and pass that into the scenemanager. But how can I actually pass this information to the manager and get it to update / add to the current scene.

It wouldn't need to be continually generated, I'd be happy for a sort of 'generated paging', where once the border of one existing generated page is approached, an entire new page is generated and added into the scheme.

I'd even settle just for a single randomly generated page at loading-time..

Is this possible? Is PLSM2 the correct choice for this, or do I need to consider some other option?

Thanks for any help.

Falagard

15-05-2006 02:54:33

You could dynamically generate the heightmap using Libnoise (a random noise generating library that can generate Perlin noise and other types that look good for terrain) and then mapslit it (like I'm doing in GOOF Editor) but it's not instantaneous, it takes time depending on size / number of terrain pages and takes a lot of memory.

If you were willing to put the time into it, you could also generate each page on the fly instead of generating them all at once, perhaps running in a background thread. Libnoise lets you request a certain position within an infinitely large randomly generated texture, so you could do that as the user moves around.

I believe one of the splatting modes also doesn't require preprocessing - determining the textures to splat in the shader based on height value, so that'd work for you, giving you grass at certain heights, rocks, etc. snow on high peaks.

Clay

Rowan

15-05-2006 03:23:27

That Libnoise looks excellent, thanks for pointing it out. That's pretty much what I'm after as far as the Terrain generation itself goes.

But the problem for me remains getting that information into the scenemanager. At the moment I am merely familiar with having my resource files pointing to a graphical heightmap, and adding it at Load-time.

How do I get another type of data format (eg: 2D array of heights, etc..) into the scene manager? You seem to imply this is possible with your 2nd point, but I'm still none the wiser as to how to actually implement this, ie: what API methods exist, or how to access / modify the stored height map data itself..

I've only skimmed the Libnoise site so far, but does it save it's data as a graphic file (you say you used Mapsplitter?), or is it stored in some sort of data structre? How would I load that into Ogre?

(BTW, I've read a lot of the posts to do with you GOOF Editor and it looks great.)

Thanks!

Falagard

15-05-2006 04:01:31

Libnoise gives you back an array of floats that you can use for the heightmap.

I'm not sure how you'd go about doing it this way, I'm just saying that it's probably possible. tuan kuranes would be able to provide more info.

I'm not sure if there's an API call in paging landscape manager for setting the height values of a page directly.

You could think about creating your own 2D data class (there are different classes for loading heightmap data from different sources in the PLM2 code) which actually generates the data on the fly when requested.

Rowan

15-05-2006 04:31:38

I was hoping that I wouldn't have to go down that road as I'm not the most expert of programmers. But it's worth a try, I might be able to piece together something useful for anyone else interested in this sort of thing.

(But then it seems not many are, which kind of surprises me..).

Thanks for your help.