Tangent space generation updates

· by Steve · Read in about 3 min · (477 Words)

I’ve posted about this in the forum, but thought I’d cover my bases and mention it here too. If you write tools which export data to Ogre, you should know about some improvements in the tangent space calculation process in the next major version of OGRE (Shoggoth, CVS HEAD).

  1. You can now calculate tangents on any geometry, not just Mesh

    The TangentSpaceCalc class will generate tangents for any input geometry, so if you use custom geometry classes you can use the same functionality easily

  2. Tangent space is now weighted by face/vertex metrics

    By taking into account things like the triangle size and facet angle at a vertex, meshes which have variable tesselation areas sharing vertices may look better because the tangent space will be proportionately weighted

  3. Shared geometry seams are now respected

    You can add multiple sets of index data to the TangentSpaceCalc inputs referencing the same vertex data and all the data will be considered together, should that be necessary

  4. Splitting vertices due to mirroring and rotation in tangent space

    Optionally the tangent process can split vertices which border tangent space regions which are mirrored or excessively rotated. This allows 2 different tangent space bases to propagate separately rather than averaging wildly different tangent spaces at a single vertex. Look for the -tm and -tr options in our command-line tools to enable these features, and check the parameters to Mesh::buildTangent Vectors to enable it there.

  5. Including parity in tangent vectors

    To cope with mirrored UVs better, we now support including a parity component in tangents, making them a 4-component vector. When generating the binormal/bitangent in the vertex shader, you multiply the result by the ‘w’ component to correct for mirroring. Using 4-component vectors takes up an extra 4 bytes per vertex obviously, so this is optional (you only need it when you have mirrored UVs). Look  for the ‘-ts’ option in our command line tools and the parameter to Mesh::buildTangentVectors. You will also probably want to enable the ‘split mirrored’ option too, if you haven’t already resolved that at the mirror seams.

One of the nice things about this is that you can build new tools against the (unstable) Shoggoth repository, and then use the resulting .mesh files in (stable) Eihort projects if you like. That’s because Ogre’s .mesh format is self-describing and fully flexible in the vertex format, so Eihort code already allows 4-component tangents in an existing mesh even though the code couldn’t generate them before. You just have to use Shoggoth code if you ever decide to regenerate the tangents, convert to/from XML etc.

I’ll be updating the Maya, XSI and Milkshape exporters soon and I hope maintainers of other exporters / tools will take advantage in due course - if your tool isn’t updated yet you can use the OgreMeshUpgrade command-line tool built from Shoggoth to massage your meshes in the meantime.