Sign in to follow this  

Procedural generation w/time component

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's something I've been mulling over for a while, and just thought about getting feedback for. Below is an example of the concept, but it can apply in many different situations. Picture a procedurally generated forest. In a specific region of space, you pick a series of (X,Y) points to grow into trees. You could furthermore add in a (Z) coordinate to indicate the age of the tree you're generating, from little saplings up to mature trees. When the viewer leaves the area, the procedurally-generated trees are freed from memory. When they return to the area, the trees are generated again. By doing so, you could easily simulate a world in which there are trillions of trees; you simply don't keep track of all trees at once. Clearly, it is possible to generate the same forest each time the viewer returns. For example, the region in question could have a seed value associated with it. By using the same seed for the region, the exact same trees will be generated each time. The procedural tree generator can be passed the a randomly chosen seed for each tree each time, but they'll always be the same ones since you're seeding the random number generator by a fixed value for the region. But what if you wanted the forest to age over time? I.e., saplings to slowly mature into large trees, large trees to keel over and die, etc? Using a specific seed for the random number selection will get you the exact same forest each time. But using a random seed (say, time) for the random number selection will get you a forest completely unrelated to the previous one each time. A simple approach would work for small scales -- that is, you generate your trees once, then slowly age them and randomly add in new trees. But that would obviously become unwieldy after playing back larger and larger timescales. The problem doesn't seem as intractable as it might at first appear. Thinking about the situation, I realized that tree age could be simply viewed as a modulus. That is, picture a grid of random values from 0-100, with each location representing a possible tree location and each location with a seed to pass to a procedural tree generator. We'll declare that each point on the grid is a tree if it is between 0 and 10 -- so that one in 10 squares has a tree, where 0 is a new sapling and 10 is tree about to die. Now take each grid value Z and calculate a time-adjusted grid value as (Z + Time) % 100. As before, the results of the time-adjusted point are 0-10 for a tree, with 0 as a sapling and 10 as a dying tree. Now each tree ages over time and dies, and new saplings sprout up in their place. There are a couple weaknesses to this algorithm, however. One, your trees are bound to grid locations, and whenever a particular grid location grows a tree, it will always be the exact same tree there. Not exactly an ideal situation; ideal would be to have the trees be able to occur at any random location and not be the same tree in each place. Another weakness would be that all trees follow the exact same lifecycle -- they start out young, grow to the exact same age, and die. In the real world, you have a lot more younger trees than mature ones; not all trees make it to old age. Any thoughts on how to improve upon this algorithm?

Share this post


Link to post
Share on other sites
Never mind -- I think I came up with a solution. :)

If you use a random number generator that lets you "seek" ahead by an arbitrary number of random values, you can take the original non-gridded algorithm, start your random number generator at the seed value for the region, then seek ahead in time to one generation of trees before the current time, then only play back that single generation. Because obviously every tree that died before then is already dead and gone and doesn't need to be considered.

One possible complicating factor would be if you had constraints on new tree placement that take into account older trees (i.e., don't put things too close together). However, that could be worked around if your placement algorithm was convergent (i.e., you try to get as close to the randomly selected location as possible) and you played back a couple generations.

On this topic: anyone know of a random number generator that lets you seek ahead in constant time? I.e., instead of having to read 1 billion throwaway random numbers to see what the 1-billion-and-oneth random value will be, simply being able to seek 1 billion random numbers and getting the 1-billion-and-oneth random value. It wouldn't need to be true randomness, of course -- just close enough.

[Edited by - KarenRei on March 2, 2010 5:07:22 PM]

Share this post


Link to post
Share on other sites
Oh, heck, I just figured out how to do that, too! Instead of using your random numbers as you get them normally (one after another, each built on the last, with only a seed call at the beginning), you have your first random number be seeded with RegionSeed, your second random number be seeded with RegionSeed + 1, your third with RegionSeed + 2, and so forth. So if you want the billionth random number for the region, you seed it with RegionSeed + 1,000,000,000. That would work fine unless there was a lot of overhead on seeding.

I guess I just needed to talk this out. Thanks anyway, everyone!

[Edited by - KarenRei on March 2, 2010 5:19:33 PM]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this