Fixing tangents for accurate normal maps
By: Bastiaan Olij Nov 21, 2018
While normal maps have been a staple of the Godot render engine for years, new capabilities of the render engine introduced in Godot 3.1 also require the generation of tangents and bi-tangents (often refered to as binormals in engines' documentation) to function correctly.
Tangents and bi-tangents are two vectors that together with the normal vector give enough orientation detail of a face to provide correct lighting. To save on space Godot uses the approach where only the tangents are store and bi-tangents are calculated by combining them with the normal vector. For this a direction flag is also included with each tangent.
Support for these so far has been spotty. The new CSG nodes lacked support for generating the tangents, there were orientation issues when importing Collada or glTF files, and the new primitive meshes reversed the direction of these.
We spent a great deal of time over the last week going through all these issues and correcting them. All primitive meshes now generate correct tangents, all CSG nodes now support tangents, Sprite3D now supports tangents and the importers have been fixed.
This does mean that if you've worked around the existing issues by inverting your normal maps on one or both axes, or by using the "flip tangent" or "flip binormal" settings within materials, you may need to undo these changes when you upgrade to the current master build or the upcoming 3.1 alpha 3.