Terrain Overhaul

Happy New Year everyone! I hope you’re all looking forward to another great year in 2015.

Over the break, I’ve been tinkering with my streaming world terrain system. Up until recently, terrains were created as mesh data with mesh colliders. This worked fairly well, but had some real disadvantages.

  1. Creating and updating mesh colliders is fairly slow (much less so in Unity 5, but that isn’t officially released yet).
  2. Lots of extra code to handle meshing of terrain chunks and lots more code to write for LOD support.
  3. System was based on the earlier requirement of UV tiling, which is no longer required thanks to the awesome tiling atlas shader discussed in previous post.
  4. Could be used for streaming world only, no editor design-time support.
  5. Code became bloated and unclear due to handling everything myself. This runs contrary to the spirit of using a commercial game engine in the first place.

I decided that everything should be clearer and run with as little code as possible. That means using Unity’s own terrain system, but how will a splat-based terrain operate with my tile-based shader? Well, turns out it works perfectly with a few tweaks and a custom terrain shader. Below is a standard Unity Terrain object with a random tilemap assigned from custom shader.

UnityTerrainTilemap

Awesome! Now I can throw out around 90% of my clunky terrain system and start fresh using Unity’s terrain. This comes with a bunch of other benefits as well.

  1. Smaller, clearer code when using Unity’s documented terrain system.
  2. Efficient TerrainCollider with complete physics integration.
  3. All meshing and LOD handled by Unity.
  4. Any lighting model and setup handled by surface shader.
  5. Full editor support for painting terrain heights for custom scenes (i.e. not streaming).
  6. Everything can be serialized normally into scene.
  7. Fast preview of streaming world in editor, not just at runtime.
  8. Set your own heightmaps using standard Unity workflow.
  9. Can potentially combine my tilemap shader with splat painting for higher detail.
  10. Can add details like grass and rocks using the standard detail settings.
  11. Can use Unity’s own tree system (or SpeedTree with Unity5) for truly amazing forest scenes.

Those last two items just rock my socks. This really is the best of all worlds. Daggerfall’s terrain is merged seamlessly with Unity and all the extra power it provides. This was the entire reason I chose Unity in the first place, and I’m kicking myself for wasting so much time on my own terrain system beforehand. Oh well, live and learn.

Below is a screenshot where I’ve quickly painted heights around the outside of a custom town using the standard terrain tools. The town ground tiles are seamlessly painted on terrain where required. Note how the continuous LOD does not impact the tilemap, which is totally decoupled from mesh vertices.

CustomTerrain

My next job is to get everything working in the streaming world once again. It’s been a much longer journey than expected, but I’m much happier with the direction things are going now.

Posted in Daggerfall Tools for Unity.

2 Comments

  1. Happy new year mate!

    Your first update of 2015. That was quick!
    You should be proud of you, I really like where this is heading and its a good choice to use the Unity’s terrain,its easy to manipulate it (Still not quite sure how your steaming process will work now though, but heh you’ll make it happen,I’m sure).

    Also its great to see that your reddit page got some neat activity in there. The great power of open-source. Hope this motivate you 🙂

  2. Cheers mate, happy new year to you as well. 🙂

    There’s basically two parts to the terrain system now.

    * StreamingWorld. Fully procedural terrain created around player at runtime. Developer controls terrain generation via parameters, templates, etc. I’m still working on the details and workflow for this. This will be very basic in 1.2 and get fleshed out over time.

    * CustomWorld. Semi-procedural terrain inserted into editor and serialized with scene. Developer has full control like any other Unity scene.

    (BTW, both systems use the exact same DaggerfallTerrain system. It’s just a matter of how and when that terrain is instantiated and whether it is saved to scene or not).

    I’m also working on ideas for hybrid world development, where you can insert custom terrains into the streaming world. This is a bit more advanced though and won’t show up for a good while.

    Anyway, I should have a broad range of people covered. Less experienced developers will get a “one-button” styled Daggerfall Terrain, and those with more experience can get stuck in and hack around with the procedural generation.

Comments are closed.