Now that painting and deformation are working well I decided to play around with some aesthetic stuff. I put some actual texture sheets together so the terrain looks like a terrain and not just a huge grid of numbered squares. I also set up some lighting. Ultimately – I’d like for the light settings to be user controlled and on a per map basis but this is ok for right now.
Well – that certainly doesn’t look very convincing. This is because Unity makes some assumptions about how your mesh should be lit and sets up the normals in such a manner that it creates hard edges. Terrains in Fractured State store their data in mesh chunks (as described in previous, wonderfully written blog entries). Those chunks store vertex data per face. This means that while the terrain appears seamless there are actually up to 4 vertices with identical positions overlapping each other. The out-of-the-box normals calculation is based, roughly, on the direction the triangle is facing. You can see the side effect more clearly in this shot. The faces to the left are oriented more towards the sun light and are creating a hard edge despite the fact that they visually share points with faces on the right side of the hill.
What I did to resolve this was write my own algorithm for calculating normals. Basically it takes the average of the existing normal data for all vertices with shared positions and assigns the result back to those vertices. Here’s the resulting smoothed mesh.
I think I’m going to take a break from doing the terrain stuff for a bit and work on a cleaner implementation for switching between mods and loading mods in addition to the base Fractured State code.
Have any feedback on the terrain features thus far? Have an idea or something you're dying to see included in an RTS map editor? Leave a comment!