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.
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 🙂
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.