Terrain Toolkit: GameDev.Net Interview

5 11 2009

GameDev.Net have published an interview about the Unity Summer of Code Terrain Toolkit project where I discuss some of the aspects of the project as well as my experiences in developing it and being part of the Summer of Code programme.

Thanks to Oli Wilkinson at GameDev.Net for the opportunity to do this interview.

Read the article here:
http://www.gamedev.net/reference/business/features/spotlightSoc2/

You can also discuss the article and the project in the GameDev.Net forums here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=552354

I will endeavor to answer any questions asked. :)

I am hoping that the release of the Terrain Toolkit will follow closely behind.





Unity 3D: Desaturate image effect (Pro only)

27 10 2009

Here’s a simple modified version of the greyscale image effect that allows you to change the level of desaturation. Positive values desaturate the image, up to 1.0 which is totally greyscale. Negative values down to -1.0 increase the level of saturation. Note that values above 1.0 or below -1.0 create strange results.

It uses a texture ramp and the same per-channel ramp offset controls as the colour correction image effect.

As this is an image effect it requires Unity Pro.

Enjoy. :)

Download Unity Package





Terrain Toolkit: Project Status

21 10 2009

I know I haven’t posted much on this project recently – but things are definitely still moving ahead. I have received feedback and comments from the Summer of Code reviewers at Unity – and I’m currently working through the implementation of some of their ideas and amendments. Their feedback has been really useful and the toolkit is definitely benefitting from the added improvements. Most notable will be the addition of ‘presets’ for some of the filters, which should make the toolkit a lot quicker and easier to get up and running.

So hold on, the release shouldn’t be too far away now. :)





Terrain Toolkit – List of API functions

8 09 2009

For those interested in how the Terrain Toolkit can be used to generate procedural terrains on the fly, here is a list of all the API functions that are exposed in the component. There will be full documentation provided, along with code examples.

Generators:

  • VoronoiGenerator – Generates a series of mountain peaks on the terrain object.
  • FractalGenerator – Generates a random heightmap on the terrain object.
  • PerlinGenerator – Generates a random heightmap on the terrain object.

Filters:

  • SmoothTerrain – Smooths the terrain object.
  • NormaliseTerrain – Normalises the terrain object.

Erosion:

  • FastThermalErosion – Performs fast thermal erosion on the terrain object.
  • FastHydraulicErosion – Performs fast hydraulic erosion on the terrain object.
  • FullHydraulicErosion – Performs full hydraulic erosion on the terrain object.
  • VelocityHydraulicErosion – Performs velocity hydraulic erosion on the terrain object.
  • TidalErosion – Performs tidal erosion on the terrain object.
  • WindErosion – Performs wind erosion on the terrain object.

Texturing:

  • TextureTerrain – Procedurally textures the terrain object by height and slope.




USoC – Unity Terrain Toolkit complete!

3 09 2009

My Unity Summer of Code project is now complete and was submitted (late) on Monday night. For now, the Unity team will be reviewing the submissions from myself and the other participants and hopefully the results of the 4 projects will be available to download in the not-too-distant future.

As for me, I’m catching up on sleep and going snowboarding this weekend. :P

Maybe when I get back I’ll start thinking about what comes next. Destructible terrain anyone? :D

Meanwhile, here’s a few screenshots from the Unity Terrain Toolkit:

mountains

desert

final_terrain_ui





Trippy velocity map thingy

25 08 2009

So, I’ve been working on ways to simulate water flow over terrain objects. This is a generated velocity map showing the drainage system of a terrain object, the red areas show regions of higher velocity. I haven’t quite figured out how to actually implement this as hydraulic or glacial erosion yet. I just thought I’d post it ‘cos it looked cool. :)

velocityMap





One week to go…

25 08 2009

With one week remaining before the end of the Unity Summer of Code, all participants were asked to write a post for the Unity Blog. The post covers where the project is up to, what still needs to be completed, and a bit of an early postmortem of how well the project has gone and what challenges were faced.

The post can be read here on the Unity blog and I’ve included it below as well…

A better solution to terrain generation in Unity

The objective of my 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.

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_UI_Screenshot

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.





Terrain Erosion UI

15 08 2009

As a quick follow up to the last post, here you can see the user interface for some of the erosion tools.

Note that these may change prior to the final release.

01_erosion_tools

Erosion tools in the component inspector

02_texturing_tools

Procedural texturing tools in the component inspector (these will be made more intuitive by release)

03_brush_tool

The erosion brush tool in action





Terrain Erosion Examples 1

15 08 2009

Here are a few work-in-progress examples of the terrain erosion filters. Each image is shown with numbers of iterations and calculation times. All of the images have been re-textured (using the texturing tools that form part of this project) and re-lightmapped after erosion, though times for these addtional actions have not been included in the calculation times. As a reference, the texturing tool has a calculation time of approximately 14 seconds for a 512 x 512 grid.

1. Fast Thermal Erosion

Using height maps only.

terrain_base

Base terrain (512 x 512 grid)

terrain_thermal_50

Fast Thermal Erosion, 50 iterations, 6.19 seconds

terrain_thermal_100

Fast Thermal Erosion, 100 iterations, 12.35 seconds

2. Fast Hydraulic Erosion

Using height maps only.

terrain_base

Base terrain (512 x 512 grid)

terrain_fast-hydro_100

Fast Hydraulic Erosion, 100 iterations, 12.86 seconds

terrain_fast-hydro_200

Fast Hydraulic Erosion, 200 iterations, 25.52 seconds

2. Multi-layer Hydraulic Erosion

Using height, water and sediment maps, no velocity field.

terrain_base_2

Base terrain (1024 x 1024 grid)

terrain_full-hydro-2_50

Multi-layer Hydraulic Erosion, 50 iterations, 1 minute and 02.36 seconds





USoC – Terrain Erosion Tools Update

6 08 2009

So, I’m now two weeks into my Unity Summer of Code project.

We’ve all been asked to submit weekly logs detailing what we’ve done in the past week, and what we plan to do in the week ahead. I’ve been a little slack on posting updates here on the blog (being busy with the project and all…) so I figured I’d just post the logs here in the meantime, while I think of something more exciting to post. :P

Week 1

  • Migrated all previously developed code into a new project and set up Asset Server project.
  • Started work on a custom component editor for terrain erosion tools.
  • Rewrote fast erosion scripts (thermal erosion, faked hydraulic erosion, tidal erosion) and the custom component editor in C#.
  • Incorporated basic erosion brushes into the editor, with options to change brush size and opacity. Found that the existing Terrain component is capturing all mouse events preventing their use in the Terrain Erosion component. Currently using the ’shift’ key instead of the mouse button until I can find a better solution.
  • Made some optimisations to the fast erosion scripts (mostly involving accessing arrays less often) which results in better performance of the erosion script and increases the usability of brushes.

Week 2

  • Started working on a multi layered approach to hydraulic erosion using cellular automata which uses separate 2-dimensional arrays for terrain height, water, water flow velocity and transported sediment.
  • Created a script which uses ray casts to generate an occlusion map for wind erosion which defines which areas of the terrain should be affected by wind erosion (similar to a lightmap) using wind direction and wind strength as inputs.
  • Added an option to choose between Moore (8 nearest cells) and Von Neumann (4 nearest cells) neighbourhoods for both fast and multi-layered erosion scripts. This allows the user to choose between better quality or better speed.
  • Added difference maps to fast erosion scripts – i.e. Changes to each cell in the height map are cached in a separate array and then applied to the height map at the end of the iteration rather than immediately.
  • Rewrote the procedural terrain texturing script in C#.
  • Created a simple interface for procedural terrain texturing and incorporated it into the terrain tools component inspector.
  • Continued work and made improvements to the custom component editor for terrain erosion tools.
  • Exposed controls for tidal erosion in the component inspector, but found that it no longer functions correctly. (Possibly due to the addition of difference maps?)

The plan for week 3…

  • Continue work on, and optimise the multi layered approach to hydraulic erosion.
  • Fix the broken tidal erosion script!
  • Fix blending options for fast erosion scripts.
  • Move thermal, faked hydraulic and tidal erosion into separate scripts to improve speed (they will have less ‘switch’ and ‘if’ statements).
  • Allow the user to switch off difference maps for brushes to speed up performance if desired.
  • Start work on documentation.