Biome based map generation?

Started by
26 comments, last by ApochPiQ 7 years, 7 months ago

I think I understand what an L-system is, but I don't really get how I can use one for this? I tried googling both for samples of L-systems and L-system based map generation but didn't really come up with anything useful. It seems easy to use to create tree shapes and presized islands, but arbitrarily sized maps? Got any tips or resources on how I can use L-systems for my purposes? Can I use an L-system to sample for a value at a point?


You need a tiny bit more abstraction/indirection. Your goal is not merely "sample an X/Y point and find out what biome it is." Your real goal is to generate regions of X/Y space that conform to biome patterns and exist near each other according to some (as yet unspecified) rules for the game.


Think of the L-system as generating a sort of tree-like structure. Each branch of the tree can turn left, go straight, or turn right. Your mission is to generate a tree (or, probably, several trees) that follow these rules:


- Pick a direction
- Expand in that direction until you hit either SOME_MAX_BIOME_SIZE or run into another biome's boundary
- Pick the midpoint of where you started and where you stopped
- Generate a node expanding left and a node expanding right from that midpoint
- Recurse arbitrarily



This is not a perfect algorithm and you will need to solve a few edge cases to make it do exactly what you want. But that's the idea here; you know what you want, we do not... so you're in the best position to solve this.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement

- Pick a direction - Expand in that direction until you hit either SOME_MAX_BIOME_SIZE or run into another biome's boundary - Pick the midpoint of where you started and where you stopped - Generate a node expanding left and a node expanding right from that midpoint - Recurse arbitrarily

It seems to me that if I do it that way, it would matter how I expand the map. Let's say I use chunks of 256x256 tiles. I start with one chunk, then the player explores to the north, then two chunks west from there, then south, ending up in a chunk two steps to the west of the starting chunk. How can I make sure that chunk generates to the same shape etc as if the player had explored straight to the west from the start? It seems to me that it would be difficult to predict how the "tree" would have expanded to a specific point without following it there all the way..? It feels like I'm missing something..

Caveman uses a location and radius to create a "circular" splat. a series of splats along a random path can create a splat chain - like a chain of mountains. it starts with ocean, and splats impassable mountain chains. it then "grows" (limited floodfill) mountains around the impassable mountains, and hills around the mountains, and flat land around the hills. so it literally raises the land out of the ocean. running water starts at a random location, and flows in a random non-uphill direction until it hits another body of water (usually the sea or salt marsh). vegetation is based on area (cold north etc) and also uses a splat + grow algo as i recall. i'll bet something like those are what you're looking for. its been along time since i wrote the code, but as i recall that's how it works. i can look it up if you need me to. the result of all this is a 2d array with elevation, vegetation, eater, and resources info. that "world map" is then used to generate terrain chunks and collision maps - the game is a randomly generated open world seamless FPSRPG.

This is extremely similar to what I'm doing right now, but it does not really support expansion and is extremely slow.

Perhaps I could use a regular grid of points, then use some form of noise to move those points around a bit (something like up to half the distance between two points). Using that, I should be able to figure out the closest point for a given X,Y pair and sample that point on another noise map to figure out a biome id..

Good procedural generation algorithms are deterministic. If you start from the same point and expand according to the same rules every time, you'll always get the same results.

The trick is to decouple generation of your terrain from the exploration of the terrain. If the generation method is independent of how players actually traverse the world, there is no problem.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

The trick is to decouple generation of your terrain from the exploration of the terrain. If the generation method is independent of how players actually traverse the world, there is no problem.

Can you elaborate a bit on this? A typical noise algorithm will always return specific value for a specific point, independent of if it's the first sample I ever make or if I've sampled everything around it beforehand. That syncs up perfectly with your comment. If I were to use an L-system, it would seem to me like I would have to always iterate out from a known point (ie origo) until I reach a specific point. I could probably come up with an L-system rule/whatever that expands in a circular path from a known point, but even then it would seem to like as if I need to iterate out in all directions until I reach a radius greater than the furthest distance from the center that the player has ever travelled. That would be extremely inefficient both computationally and with respect to memory usage. This is why I'm asking if there's a way to write a rule/whatever so that I can figure out the "state" at an arbitrary point and continue to iterate from there. Should I start from the point and try to move "back" in the L-system, that is figure out the path to that point?

There are entire PhD theses on how to use L-systems for generating various types of geometric state.

I don't have time or the inclination to distill them here, so if you want to know more, I'd recommend buying a good book (like this one) and chewing on the subject for a while.

There are also plenty of course materials and lecture notes available on the web with examples of how to do this stuff.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks for the recommendation! I'm interested in learning more, but at the same time, there's a lot of things that are interesting in this world and way too few hours in a day. I tried googling for "L-systems" and words like "terrain", "map generation" etc, but only found rather boring examples of city generation. I might read up on it a bit more, but first, let me ask you: which one of the following statements would you say is the better fit?

"L-systems are exactly what you are looking for and all problems you are currently seeing/anticipating can be easily solved with a basic/intermediate understanding of L-systems."

"L-systems are incredibly powerful and flexible, and with an advanced understanding you can most likely come up with something that suits your needs, but it's possibly on a PhD paper level."

Don't take it the wrong way, I'm genuinly curious and had never heard of L-systems before this thread. I've read 10 or so quick articles/tutorials/code samples, but none of them helped me figure out how to use them for my problem. It seems to me like the second statement is more accurate, that is "it's possible, but it's not necessarily the best tool for the job". I'd be very happy to be wrong though, if someone with better understanding thinks otherwise..?

[background=#fafbfc]Perhaps I could use a regular grid of points, then use some form of noise to move those points around a bit (something like up to half the distance between two points). Using that, I should be able to figure out the closest point for a given X,Y pair and sample that point on another noise map to figure out a biome id..[/background]

This approach seems rather promising at the moment. I just need to fix the borders, control the frequency of biomes and add some more data (ie. height multiplier, turbulence multiplier, ..) to the biome types so they become more interesting.

"L-systems are incredibly powerful and flexible, and with an advanced understanding you can most likely come up with something that suits your needs, but it's possibly on a PhD paper level."


I think this is closer to the situation.

I mentioned them because I find the techniques very powerful, but upon reflection I don't really have a good explanation on an introductory level for how to really tap into them.

Apologies for tossing you to the deep end :-)

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement