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.
- Creating and updating mesh colliders is fairly slow (much less so in Unity 5, but that isn't officially released yet).
- Lots of extra code to handle meshing of terrain chunks and lots more code to write for LOD support.
- 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.
- Could be used for streaming world only, no editor design-time support.
- 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.
- Smaller, clearer code when using Unity's documented terrain system.
- Efficient TerrainCollider with complete physics integration.
- All meshing and LOD handled by Unity.
- Any lighting model and setup handled by surface shader.
- Full editor support for painting terrain heights for custom scenes (i.e. not streaming).
- Everything can be serialized normally into scene.
- Fast preview of streaming world in editor, not just at runtime.
- Set your own heightmaps using standard Unity workflow.
- Can potentially combine my tilemap shader with splat painting for higher detail.
- Can add details like grass and rocks using the standard detail settings.
- 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.