Post news RSS Terrain Overhaul

Streaming world now uses Unity's own terrain system for maximum features.

Posted by on

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.


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.


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.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.