Search Unity

This blog post is written by Sándor Moldán who is working on a set of Terrain Erosion tools for Unity. The project is one of four selected projects that were selected for the Unity Summer of Code.

The objective of this Unity Summer of Code project was to develop a toolset for the Unity Editor which would streamline and improve the workflow involved in creating terrains for games.
Terrain Erosion Tools screenshot

While there are currently a number of third party tools that can already produce high quality terrains, I felt that they lacked two vital qualities. Besides the impact of the additional cost of these tools – particularly to indie developers, when using these tools it is left to the artist to develop an effective workflow for getting height and texture maps out of their proprietary software and into Unity. This can be a somewhat painful process. Secondly and more importantly, it is impossible to leverage the power of the tools to procedurally generate landscapes at runtime. My aim was to overcome these constraints by integrating terrain generation tools directly into the Unity engine and editor.

The toolset I am developing is divided into three areas – terrain generation, erosion and texturing. So far there are 5 different erosion filters – thermal, tidal, wind and two types of hydraulic erosion, 2 ‘generators’ that use Voronoi and cloud fractal algorithms to create base terrain, a couple of useful tools that allow the user to smooth or normalise the terrain and finally a procedural terrain texturing tool.

All ten of these features will be provided both as filters which can be applied in the Unity Editor and as fully documented API functions which will allow users to generate terrain and apply filters at runtime through their own scripts. Additionally, thermal, fast-hydraulic and tidal erosion filters can also be applied directly to the terrain object using brushes in the editor.
Terrain Erosion Tools UI

Where it’s up to, what still needs to be done

I feel that the project has progressed well over the last five or so weeks. There have certainly been some obstacles and not everything has gone my way, but with just over a week remaining I am on track towards delivering at least 16 of the 19 features that I originally scoped for the project, plus two completely new ones. Given that my aim was to deliver a minimum of 12 of the scoped features within the Unity Summer of Code timeline, I’m quite happy with the result.

Over the next week my main aim is to tidy up the documentation for this project, which I believe is vital in allowing Unity artists and developers to get the most out of these tools. I will also focus on cleaning up my code and optimising it where possible and finally I will continue working away on the remaining features – namely a few UI tweaks, yet a third different approach to hydraulic erosion, and glacial erosion.

What went well

I started the project with a fairly limited knowledge about creating properly integrated custom tools for the Unity Editor and had only given the Editor GUI documentation a cursory glance. I found that despite a few minor hurdles, I was able to quite easily create a useful and intuitive interface for my tools. I was also pretty happy with some of the optimisations I was able made to my erosion code. Being able to run 50 thermal erosion iterations on a 512 x 512 terrain object in barely more than 6 seconds totally exceeded my wildest expectations.

Also, after many unsuccessful attempts to get Unity’s undo feature to work with my code, one of the Unity guys, Rune, was kind enough to explain it to us – and in typical Unity style, it turned out to be much simpler that I had thought it would be.

Even though I had originally considered undo as a ‘nice to have’ feature, I quickly realised that it was really an imperative. Getting the best results from these tools can require a bit of trial and error, and allowing users to run a filter, undo it, tweak a few settings and run it again without completely ruining their terrain object in the process is vital in making this project a practical solution for Unity artists and developers.

What didn’t go so well

While I consider my scripting skills in JavaScript and C# to be reasonably good, I have to admit that mathematics is not really my strong point. Some of the equations I used in my tools, such as Voronoi diagrams and the Diamond-Square algorithm were fairly easy to implement in code – but for the vast majority of my tools I initially approached the algorithms logically rather than algorithmically.

For the most part this worked well and produced good results. However, when I started looking for a more physically correct approach to erosion caused by fluid mediums – namely water and ice – I realised that the complexity of the mathematics involved in computational fluid dynamics, such as Shallow Water Models, Navier-Stokes equations and so on, was far beyond my level of understanding and well beyond my capacity to learn in such a short period. This was rather disappointing, as it has meant that I have not yet found an effective solution for glacial erosion.

That said, there is still a lot more that I want to achieve with this toolset. After I deliver my project at the end of the Unity Summer of Code, I fully intend to revisit some of these prohibitively complex features once I have the time to do all the learning and research that will be required to get them to work the way that I want them to.

7 replies on “Summer of Code: Progress of Terrain Erosion Tools”

Great work! This is looking really exciting. Deep yet simple. Applying erosion via a brush is interesting. From the image above it seems as though brushes aren’t an option for applying textures or creating the base heightmap. These would be really practical and would fill a gap in the current tools. Perhaps features that could be visited in the future?

That will be very cool once you get it out there! Even though some people I know might not know it, you really want that kind of thing when creating a realistic terrain. :-)

Comments are closed.