I've been trying to integrate both GLTF 2.0 and blender into my asset pipeline for my custom renderer. I noticed some strange normal artifacts when normal mapping. So I go to look at my tinygltf code, low and behold for some reason the tangent vector from my blender export is a vec4 array instead of a vec3... Once I account for this, my normal mapping is fixed, and rendering looks correct.
What is going on? Is that extra value actually needed? Why does blender output vec4, and not vec3 for tangents, but vec3 for normals?
bitangent = cross(normal, tangent.xyz) * tangent.w
. See the spec. $\endgroup$tangent.w
is specified to only ever be1.0
or-1.0
. It's needed when the UV winding order is flipped. If you ignore it, some geometry (especially mirrored geometry) might appear with the normal map flipped inside out. $\endgroup$