• Register
Post news Report RSS Starting with trees and rocks

Monochrome deserts and grasslands are no fun to look at so I started implementing an algorithm to scatter decoration objects such as rocks and trees on the map. It turns out that procedural landscape generation can be quite an interesting challenge even for a low-poly game.

Posted by on

The landscapes for my game need to be really large because the player will fly fast and at high altitudes around the map. When the player reaches the edge of the playable area (or to enable virtually unlimited maps), the landscape must continue even farther out to the horizon. As a starting point, I implemented a simple procedural algorithm that populated the map with large terrain assets such as hills and mountains that can be seen from afar. The algorithm uses a grid and a set of rules to add new assets and remove already placed ones that are too far from the current position of the player. When the player returns to a previously unloaded area of the landscape, the affected assets will be placed again. This way, the map looks slightly different for each run and also remains coherent in itself during a run.

So, now I have large landscapes to fly around in but the ground remains mostly empty and monochrome. There need to be some rocks and trees down there!

art2trees


I started with a similar algorithm on a grid-cell basis. This first iteration was supposed to scatter decorations (rocks and trees for now) on grid cells close to the player. The result killed the framerate right away by performing far too many squared-distance-checks, object allocations and (de)serializations. That approach was no good, so I shifted to a player-following decoration scattering algorithm.

This second iteration was more efficient because it did not need to care about the current state of the larger landscape. Decoration objects are spawned and unloaded within a certain radius around the player utilizing the concept of object pooling. New decoration objects are only instantiated when the object pool has capacity left. They are then added to the object pool and disabled (but not destroyed) when out of sight. When new decoration objects are required because the player has travelled a defined distance from the last “scatter position” they can be taken from the object pool instead of instantiating a new one. This allowed me to scatter thousands of objects but re-evaluation of the next “scatter position” still caused a clear drop in performance. I was able to resolve this issue thanks to Unitys Coroutines system.

Instead of re-evaluation all relevant decoration objects when a new “scatter position” is reached, the algorithm only executes a subset of the total workload during a single update interval, effectively distributing the load on multiple frames. You can actually see this in action when a map has just been loaded and the landscape gets populated with rocks and trees for the first few seconds.

runway with trees


After the initial scattering completed, the process is barely noticeable because new objects will (dis)appear far away from the camera.

I think this is a good approach worth extending. In the future, I plan to add distinct rulesets for different kinds of decoration objects. The algorithm is currently just checking for steep slope angles and no-spawn areas (such as the runway). In the future, it could evaluate terrain elevation as well to allow for different types of vegetation depending on the altitude.

Let’s see where this goes.

Post comment Comments
oscarfabianleites
oscarfabianleites - - 82 comments

fantastic work! If you need music for the gameplay or to promote the game (trailer), let me know.🤗👌🏻😁🎮🤗🎶
Youtube.com

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: