If you haven't already, check out Part I.
Things have been quiet on the blog the last couple of weeks but there has been lots of exciting progress behind the scenes. I purchased World Machine and modified my terrain import tool to read the beautiful World Machine height maps as well as its flow, deposition and wear maps.
I've increased the terrain heightmap resolution from 10 metres to 2.5 metres, and the improvement is startling. There is now lots of fine detail on the heightmap which makes it much more realistic and interesting. The rolling hills are officially retired.
Along the way, I also modified the terrain import tool to be completely progressive, so when importing terrain it now only uses about 500MB of RAM, a huge reduction from the 33GB it used originally. That was not easy. Algorithms are much simpler when you can just have one big array and go from there.
Next on the list was improving the texturing by adding biomes and better procedural texturing. The new texturing looks beautiful. I'm using Wang tiles for my textures to avoid distracting repetition on the terrain textures, but with the increased heightmap resolution, I was able to quarter the texture memory used while still getting better resolution.
Each biome has a number of possible textures which it applies to the terrain based on steepness, and the wear, flow and deposition maps from World Machine. The trickiest part of the texturing was figuring out what to do where two biomes were adjacent. In order for the blocks to blend into each other, they needed to share textures with the adjacent blocks. The first step was to increase the number of layers supported by the terrain shader from 4 to 8. Once I had a few more texture slots to work with, I was able to use an overly-complicated algorithm to select the best textures to use to blend adjacent blocks.
With 8 terrain layers all doing normal mapping, I was a little worried about performance of the pixel shader. That concern has proven to be right, as I have noticeably lower framerates with the new terrain. The first thing I did to improve things was to add a conditional compilation feature to my shader materials so that the shader would be faster if it needed to blend fewer terrain layers, but even with that optimization, my framerate is not what it was (although it still breaks 60.)
Its kind of funny, but today's computers are so fast I haven't needed to bother with any culling up until this point. I think that time is coming to an end soon. I was running the app with AMD's GPU PerfStudio 2 to try to figure out why it was mysteriously crashing. Seeing the number of big render calls that don't end up affecting the rendered image kind of offended my sensibilities.
I'm still struggling with an approach for better looking rock faces. I bought RAGE and Skyrim this week to check out their environments. Both of them are gorgeous but they don't help me much. Both appear to use artist generated and placed static geometry for cliff faces. I also looked into tileable cliff face geometry, but that is too much art as well. I'm not sure what I'm going to do about this yet.
Something I noticed with the more hilly terrain is that sometimes it is difficult to tell which way is up with just the lighting cues on the heightmap as indicators, so next on my to do list is adding static geometry props to the terrain: trees, rocks, majestic spires, etc. There was a sale at 3DRT.com on Black Friday so I was able to buy a whole bunch of nice props.
The other good news this week was that I've worked out a process for building my terrain wang textures. I'm using this tool to generate the basic tiles. The problem with the tiles the tool produces is that there is obvious repetition. This is sort of inherent to the algorithm that it uses to generate the tiles, but in any case, it doesn't look good enough. To fix up the tiles, I let it do the blends, then I'm using Gimp's clone tool along with the original source texture to eliminate the repetition in the centre of the tiles while keeping the nice tile blends that the tool produces. The first one looks beautiful, and I took some texture photos today so I should be able to crank out the rest of the textures I need in short order.