Sunday, September 25, 2011

LL3DLGLD – 7 – Grass LOD

I am very close to getting the floors to that point where I can easily integrate the new engine with DwarvesH and the entire floor system with all the possible actions and events will work. And since walls can be considered higher floors, adding full wall support should be a technicality.

What I need is to take the floor layer, and make it support different materials in different cells. This covers grass levels, stones and sand. Up to this moment everything was implemented without cheating, but to achieve this we’ll have to dig deep in the trick basket and there is a chance that we’ll have to change the floor model to handle the requirements and limitations of 3D.

We’ll try and create a texture that is made up out of multiple small textures: 

This is similar to mipmapping, and thus this approach will result in visual artifacts at sub-texture borders, but compensating for this is a subject for a different post. I tried to add numbers in each cell in that texture, but I grew bored of it by the time I reached number two, so I added squiggly lines so I can distinguish the cells when applied to a floor mesh:

The big texture has 8x8 tiles, 64, applied to a surface of 30x30, 900, in order. So on the third row, the first 4 tiles are the last tiles from the texture. Now we use the same texture I used in the 2D isometric engine for grass levels:

Grass levels grow in intensity from zero to 100% in wrapping strips and then start from zero again. This pattern is not a natural one, so let’s randomize it:

This is more like it! The same system I had in the 2D engine, but with the added benefits of camera rotation:

And this is where we encounter our first real obstacle: right now I am only aware of a method for creating these cells by increasing polygon count. When we go with a full map, the large number of polygons reduces the performance a lot:

Not only do we have a low FPS, but camera movevement is now severely lagging. Before I address the FPS issue, it is time to optimize everything! We start with the LOD calculation, making it only rebuild sections if really needed. We also assign a new color coded LOD system:

Normal shading is for full detail, red is level one, green is level two, blue is level three, orange is level 4 and muted/grey is the final level, the lowest quality. Here are two shots where we see the system in action from a pseudo-top town slightly tilted view point which could be one of the default camera angles:

We have the center full detail sections, but as we get farther away from the camera the sections switch fast to low detail. With this LOD calculation and optimization method, camera movement is as smooth as could be. The FPS did not change, because we are not doing anything with the LOD info right now. Time to change that! Let’s try something simple first: we’ll assign full grass texture to the lowest LOD level, ignoring the actual grass levels:

Nice!!! If we try extending this to two more low levels, FPS no longer takes a huge leap, but it is still something you can notice.

The system works wonderfully in both the FPS mode, when you are very close to the action, and in the top down tilted mode. And I guess this is as much as you can ask. Once you start removing the restrictions on the camera, we get a small problem that had a life as long as 3D graphics: pop in! I think it is best to illustrate this with a video:

1 comment:

  1. Great stuff!

    I have to admit I was a little dissapointed when you had to abandon all that hard work, as I've been waiting for this for some time.

    It's definitely beginning to look like it was all worth it now though!

    can wait to see how well it works with the extra polygons for displaying the "walls" in a comlicated scene :)

    keep going!