Description
We use the mikktspace
crate to generate tangents when loading models in our engine. Recently, we introduced bloom and found out that we've had some very rare NaN outputs in our fragment shader. We traced back the issue and found out that the mikktspace
crate generates zero-length tangents occasionally, causing them to turn into NaN when normalized.
This model from the glTF Sample Model repository exhibits this issue: https://github.com/KhronosGroup/glTF-Sample-Models/blob/4ca06672ce15d6a27bfb5cf14459bc52fd9044d1/2.0/DamagedHelmet/glTF-Binary/DamagedHelmet.glb
On face 2923, vertex 2, a tangent of (0.0, 0.0, 0.0, -1.0)
is generated by this crate. The model appears to have nothing weird about it, and Blender generates correct tangents for all vertices if set during export.