The spec says that if you don't have tangents, you need to compute them, and it recommends MikkTSpace.
However, it is very unclear if NormalTangentTest's normal maps are actually correct, because if you run the geometry through MikkTSpace or any other tangent computation code, I always get w = -1.0. When I render that, I get the same "wrong Y-flip" image mentioned here: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/NormalTangentTest. If I flip the w sign to 1.0, it works. Is it expected that you have to flip W to make engine-computed tangents work? The spec does not say anything about that.
For reference, here's how I computed tangents before trying MikkTSpace. Looking at MikkTSpace, it's doing the same thing, I get the same W sign results.
vec3 p1 = pos[1] - pos[0];
vec3 p2 = pos[2] - pos[0];
vec2 uv1 = uvs[1] - uvs[0];
vec2 uv2 = uvs[2] - uvs[0];
float det = 1.0f / (uv1.x * uv2.y - uv1.y * uv2.x);
vec3 t = det * (p1 * uv2.y - p2 * uv1.y);
vec3 b = det * (p2 * uv1.x - p1 * uv2.x);
t = normalize(t);
b = normalize(b);
I have seen three.js do incomprehensible things like just flipping Y (before that it was flipping X ?!?!?), probably to work around issues like this, but I call into question the correctness of these models.
My renderer works fine for NormalTangentMirrorTest (which has TANGENT included), so the shading side of it is correct, i.e. bitangent = cross(normal, tangent.xyz) * tangent.w
The spec says that if you don't have tangents, you need to compute them, and it recommends MikkTSpace.
However, it is very unclear if NormalTangentTest's normal maps are actually correct, because if you run the geometry through MikkTSpace or any other tangent computation code, I always get w = -1.0. When I render that, I get the same "wrong Y-flip" image mentioned here: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/NormalTangentTest. If I flip the w sign to 1.0, it works. Is it expected that you have to flip W to make engine-computed tangents work? The spec does not say anything about that.
For reference, here's how I computed tangents before trying MikkTSpace. Looking at MikkTSpace, it's doing the same thing, I get the same W sign results.
I have seen three.js do incomprehensible things like just flipping Y (before that it was flipping X ?!?!?), probably to work around issues like this, but I call into question the correctness of these models.
My renderer works fine for NormalTangentMirrorTest (which has TANGENT included), so the shading side of it is correct, i.e.
bitangent = cross(normal, tangent.xyz) * tangent.w