What are we making?

The majority of things we make are little prototypes that make us smile to work on. This would be one of those things, we’re setting out to drop the player into the middle of a realistic-ish environment filled with different types of fauna and flora.

At the time of writing, we’ve created a system that uses multiple levels of noise generators to feed into the Unity terrain system, some of the noise generates the heights of the world, some generate the grass and some generate the trees. All of the parameters for the generator are exposed to the designers, allowing them to create varied landscapes without having to code anything.

The end goal would be to let a player press a “generate” button and be dropped into a landscape with its own little ecosystem.

Getting some models and textures to work with

As this is a prototype and we don’t have any in-house artists working with us yet, we decided to pick up an artwork pack on the Unity asset store to give us a nice spread of artwork to work with for our procedural tests. It turns out, there are some lovely looking packs out there, we went with the Nature Pack 2.0.

By using that as a base, we would then have the ability to be free to just code the environments and tweak the visuals to get the style we are looking for, without having to wait for an artist to be available to work with us. Not to mention it gives us a great springboard to work from.

Creating a height map

I didn’t actually take any screenshots when the world was just generating the height map, however I do have one just after we added the trees, so there’s that.

To generate the height map, we actually created a separate thread which has a worker process running on it. All that separate thread does is fill a 2D array (X,Z position) with a pass of perlin noise, once that process is completed it dispatches an event to the main thread saying its completed, where it is then picked up and processed into the terrain height map. Ideally we would be doing this completely on another thread, but given that anything that interacts with the Unity Engine needs to be on the main thread, this felt like a good idea to bypass the major lag that filling a giant array would incur.

Adding a few trees

Our first attempt at trying to create a generator only allowed us to drop trees into the world along with a little bit of grass, this was enough to create a forest environment, however it looked pretty once you had ran around it for a bit.

It looked lifeless, sure we had trees that sway in the wind, but it didn’t feel alive at all. We still hadn’t sorted out the colour toning, skybox or any of the effects at this point.

As above, we created a separate worker thread to generate an array and then fill it with several layers of perlin noise (per type of tree) and then dispatch that back to the main thread to process.

Grass! Flowers!

Getting them to generate in a random fashion without looking terrible was quite fun to balance out. We settled with a system that lets us define a maximum number of detail elements within a cell, that cell then grabs at random a flower or grass from a weighted list (which is populated via a biome type)

We accidently created the world to the right, each cell had been taken over by one specific type of flower and it refused to spread beyond that cell, leading to this patch work world.  At this point we had sorted out the fog for the world as well as the tree placement system.

The fog is tied to the time of day, so as time progresses the sun travels through the sky and causes the colour change. It’s fairly basic right now, however once we start adding in weather effects that will be further tweaked to give a better effect.

Night time

Atmospheric scattering looks awesome during the day, however at night it leaves the sky a bit empty. To resolve this, we wrote our own shader on-top of the scattering shader, all the shader had to do was show stars in the sky if the sun is below the horizon line. It turns out modifying the shader was very straight forward and only required a simple cube map to represent the stars in the evening which leaves us with a very nice effect.

In terms of the evening lighting, we use a separate directional light which rotates opposite to the sun and is only activated during the evenings, it adds a very slight light blue tint to the scene to mimic moonlight.

Adding a little bit of life

Now we have a nice base world to play with, now we are in the process of adding animals to the world. At the moment we have a nice flocking bird AI as well as some basic deers which wander the landscape towards no particular location.

The next step will be herding the deer together to make sure they wander together in search of food, whilst having predators tracking them down and eating them. More to come in the following blogs for that though.

Hope you enjoyed reading our little impromptu prototype dev-blog, be sure to follow us on Twitter for future blog updates or follow me if you’d like to see random screenshots over the course of the development process.

Thanks,

– Danny

Bitnami