1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-26 05:37:46 +00:00

Fix bitangents being slightly off when importing

This commit is contained in:
Joshua Goins 2023-12-31 10:31:51 -05:00
parent 3820b77ace
commit f747033aac

View file

@ -144,14 +144,14 @@ void importModel(physis_MDL &existingModel, const QString &filename)
// calculate binormal, because glTF won't give us those!!
const glm::vec3 normal = glm::vec3(vertex.normal[0], vertex.normal[1], vertex.normal[2]);
const glm::vec4 tangent = *tangent1Data;
const glm::vec3 bitangent = glm::cross(normal, glm::vec3(tangent)) * tangent.w;
const glm::vec3 bitangent = glm::normalize(glm::cross(normal, glm::vec3(tangent)) * tangent.w);
const float handedness = glm::dot(glm::cross(glm::vec3(tangent), bitangent), normal) > 0 ? 1 : -1;
// In a cruel twist of fate, Tangent1 is actually the **BINORMAL** and not the tangent data. Square Enix is AMAZING.
vertex.bitangent[0] = bitangent.x;
vertex.bitangent[1] = bitangent.y;
vertex.bitangent[2] = bitangent.z;
vertex.bitangent[0] = bitangent.x * handedness;
vertex.bitangent[1] = bitangent.y * handedness;
vertex.bitangent[2] = bitangent.z * handedness;
vertex.bitangent[3] = handedness;
if (colorAccessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT) {