This is getting to be almost a daily thing! The previous post is here.
First, a small note. The images I have in the previous post showed what a 4-to-1 grid-to-heightmap resolution looked like. However, it turns out that when we use weighted sample points from the heightmap, a 2-to-1 grid ends up giving nearly identical results.
So my task turned to how to implement the quad re-orientation on the GPU. While drawing some diagrams, wondering if I should implement the re-orientation at the grid level (in each 1×1 quad) or heightmap level (2×2 quad), I noticed that if I triangulate the quad as fixed alternating orientations:
then it actually contains all the triangle edges of any per-quad re-orientation at the coarse (1×1) level:
So perhaps I don’t really need any quad re-orientation – all the triangle edges are there.
However, using this triangulation, we end up with something like this:
You can see we still get the “wiggles”. This is because the “center point” of our group of 8 triangles (which cover a texel of the heightmap) is based on the average of the four nearby heightmap texels. If instead we detect the center point and “align” it along just the two texels which correspond to the terrain shape, we approach what we had before. This is basically the quad re-orientation done in the shader, except we don’t need to actually rotate anything. The result is blow:
It’s close, but it’s not perfect. One problem is that we’re doing this for height, but not normals (in my current implementation the normals are offset by a half texel). So there are still some artifacts (though they aren’t visible in this example).
Here’s another example of the difference when we “fix” the vertex so that it is aligned with the terrain (bottom image):
Remember the snow scene from last time? Now the comparison looks like this:
There is much less of a grid pattern now that I am aligning vertices to the terrain (there’s definitely some visible though, and that’s due to the interpolation of the normals). The difference in the amount of snow is due to the difference in my normal calculations.
Finally, another comparison showing a really bad case of texture projection artifacts with the original, followed by the “dumb” 2-to-1 grid resolution, followed by the “smart” 2-to-1 grid resolution with aligned vertices.
You can still see jaggies in the bottom image. Again, this is due to the normals. I could probably hide this a bit by introducing some per-position noise on the flat/steep texture projection transition.