New tangent space tools

· by Steve · Read in about 4 min · (686 Words)

I’ve had ‘improve tangent space tools’ on my TODO for Shoggoth for some time, but I finally managed to find time to do it late last week and today. We’ve supported normal & parallax mapping for ages obviously , but there were a few things we could have done better in the tangents generation process which I’ve now addressed. That’s things like:

  1. Separated tangents generation into its own class (TangentSpaceCalc). This means the process is easier to re-use outside of Mesh
  2. Strip and fan support. Previously we only supported generation of tangents on triangle lists
  3. Slightly more balanced tangents by weighting the accumulation stage by uv area and triangle angle. This helps prevent small triangles and very thin triangles from biasing the results at a vertex too much
  4. Optional support for splitting vertices where the tangent space parity is inverted (mirrored UVs) or where the tangent space rotates too sharply across a vertex.

The last one might have you thinking ‘ah, that will fix all my normal mapping issues where I’ve used mirrored UVs across the middle of a character’s face’, but you’d be wrong. I’ve done a lot of reading / thinking about this and you will never completely eliminate those artefacts with tangent space normal mapping because it inherently introduces a discontinuity in the tangent space. Splitting the vertices when it happens means that discontinuity can be localised better, so that the place where the discontinuities meet is handled more discretely  and doesn’t result in adding two tangents which are fundamentally opposite signs, but the discontinuity will still be there. Good artists will therefore localise these discontinuities in places where they cannot be noticed, such as in folds or existing model seams, and the vertex splitting will ensure that either side the results are predictable. However it absolutely won’t allow you to use a half-face texture mirrored across an entire face without problems. Normalmap-aware artists don’t do this anymore - they unwrap the entire head and put the seams in the neck or something like that.

The vertex splitting options are disabled by default in both TangentSpaceCalc and Mesh::buildTangentVectors because when used on a poorly unwrapped model they can actually introduce new artefacts, since they make the discontinuities explicit instead of (inaccurately, but nonetheless less noticeably) smoothing them out. However if you have a well designed model you will want to enable the options since it will guarantee your artists can place seams / mirror UVs where they want have the tangent space behave predictably there, ie switching orientation cleanly.

This exercise made me realise just how few freely available, high quality models with normal map friendly texturing there are out there. The screenshot here is from one I found - Sylia by Ironbearxl (apologies to him, the material is hacked together fast as a tangents test and doesn’t cater for the ambient occlusion / specular maps so it doesn’t look as good as it can do), taken from the xNormal distribution, which I used to test whether my thoughts on artist set up were correct or not, becuase it follows what I understand to be ‘good practice’. Most of the test models I have are what I would now call poorly unwrapped so can actually look worse with all the new options enabled - which is why I chose to leave them disabled by default under the ‘principle of least surprise’ - people who have artists who know what they’re doing can choose to enable them (and indeed, Sylia looks fine with them).

I can’t include this model in the OGRE distro without permission, but I may ask him. I would however prefer to find an animated model from somewhere, although Turbo Squid hasn’t provided anything of any real interest yet, even the non-free stuff is pretty damn poor in the main. If you know any really talented artists who have created a really high quality animated character with normal & spec maps and who would like to get some publicity in an OGRE demo, please tell them to contact me. If it’s really good, I’d even be willing to pay for it.