Apart from a bit of distraction from some legacy support work (I still get dragged back when I cannot avoid it) the whole day was a Reloaded terrain day and it was great fun.
What you see above is the current state of my terrain prototype, which attempts to do three things. First represent some terrain height reference data 500x500 in size which is the maximum size of a Reloaded level. The second thing is that the terrain employs LOD for polygon creation so that distant terrain features are not given hundreds of thousands of polygons. The third is the whole thing is super fast and using as few polygons as possible and we'll add a forth feature which is that the terrain is completely dynamic, centered on the player and can be scrolled in all directions.
The only thing I have not done yet, and planning to do it after writing the blog is to stitch the LOD polygons together so they create a perfectly seamless wireframe from highest LOD to lowest LOD in the far far distance. I've already done this successfully with the first two LOD levels, and it works nicely, so I just need to crack on and add more code.
A nice benefit of this technique is that once you reach the end of the defined terrain reference data, the terrain renderer just uses a height of zero for non-reference areas but continues to render the terrain to the distance. Effectively, the terrain does not end from the players perspective, you just run out of meaningful 'designed' terrain heights.
A Higher Perspective
I noticed when I finished the initial prototype coding that the terrain layout looks remarkably like the shadow cascade approach to LOD levels. The player stands in the centre, just above the terrain, and looking outwards. Given this perspective, the detail in the subsequent LOD levels does not have to be that pretty and in fact the stitching only really needs to happen on the edges you can see from the players perspective. Not sure if that observation converts to an optimisation yet.
I did a few quick optimisations already, including only updating the terrain segments when an actual scroll-event takes place. This rescued huge amounts of processing and made things very slick. Currently the prototype takes only 8000 polygons and runs at 2300 fps when idle and 850 fps when scrolling super fast. The vast majority of this is the writing of the terrain to the dynamic vertex buffer so in terms of CPU performance it's pretty good.
Legacy Fixes and Groundwork
As tempting it was to start terrain coding right away, I had to finish off the bits I left to create the 'Decent Demo' for the meeting a few weeks ago. This involved solving the shadow artefact in the map editor and also solving the issue of shadow Z clash when the light was perpendicular to a surface. I solved it by ensuring the regular lighting calculation modulated the shadow strength so that when the light is behind or 'at dot zero' I don't add any illumination so the shadow Z clash could be seen. The result is a shadow that looks 'just normal' which is exactly what I wanted to see.
As you can see above, by adding the latest shadow work to the instance stamp engine and map editor, as you add segment walls the lighting is applied instantly. Given the satisfaction of editing in this way, I am strongly considering leaving the 'real time light map baker' on standby and go for 100% real-time dynamic everything :)
Anyhoo, with those fixes dealt with, when the time comes to integrate the terrain stuff into the map editor, we should be able to see instance stamps and shadows as well without too much fuss. I also need to re-enable things like entities and other markers to the map editor, but that will come soon enough. Right now terrains are the only thing my brain is allowed to imagine.
A great day all told. A little more coding to stitch up the terrain mesh segments and then I think it's early enough for a nice supper and watch a Netflix movie. That's my developer tip for the day, and probably a good life tip too, always treat yourself from time to time for a job well done, it will encourage a productive life and re-enforce positive action!
AGK V2 Kickstarter
I'm on the edge of my seat waiting for the total to push past £21K. It's great logging on every day and seeing it creep up :) Here are the stats at midnight: