So back in third year we were tasked with creating a terrain mesh and advised to make a diamond pattern as it creates better looking terrain without the jagged sawtooth you could get otherwise. When I made it I was really pleased, it made the pattern, didn't have repeated vertices and I could change the dimensions.
Now I've been set the same task. This time around I wanted to improve it further. My first steps were to replicate what I had which didn't take long. However, I made some alterations to my method. This time I could set the dimensions of the terrain but this would be independent of how many triangles would make up the mesh. Instead, I added more variables which control how many triangles to place along the width and height. I also made it so that the vertices are assigned the correct UV coordinates so that it's easy to texture. I then realised that as the mesh was indexed, I could simply use a different index buffer to render a lower detail mesh and so I went about implementing this. To simplify the problem, I make sure that the density of triangles is of a power of 2, so that it can be broken down without an odd number of columns or rows appearing.
It wasn't quite as straight forward as I had in my head but I managed it as the video demonstrates.
First I show a square terrain with a square density (equal width and height) and show how the levels of detail render correctly. Then I show that the dimensions are independent of the density by having a square density on a rectangular terrain mesh. Finally I show how the algorithm adjusts to calculate the smalls level of detail achievable when the density is rectangular. Unlike the previous two instances, the mesh can only break down to a certain level of detail.