Tuesday 16 July 2013

Tuesday Terrain Tastic

Let There Be Ground

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.

Signing Off

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:

564
backers
£20,927
pledged of £5,000 goal

23
days to go


4 comments:

  1. So great to see you back Lee
    and that terrain looks really promising

    keep up the great work!

    ReplyDelete
  2. Hi Lee,

    I hope you had a great Holiday and are enjoying and coping well with the Sunny weather in North Wales.

    Looks like a well deserved supper and movie break.

    Thank you for the screen shots and the obvious hard work involved.

    Personally I have always comment relative to FPSC classic comparison and this time I have to say "stunning" progress. Enough said. Thank you again.

    :-)

    ReplyDelete
  3. Hi Lee,
    Reloaded's looking very promising so far, but I'd like to ask, will we be able to create something as fast paced as the new Rise of the Triad remake?
    Trailer: http://www.youtube.com/watch?v=pGOr3PTLKM4
    E3 Gameplay: www.youtube.com/watch?v=VqhHXmiCwNo

    It'd be pretty damn awesome to create something like this

    -TZK

    ReplyDelete