From 538528d1037200e7e4268956dd23877564ad2d1f Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sat, 17 Nov 2018 23:42:46 +0800 Subject: [PATCH] Fix normal tangent Some tangents did not get calculate, this cause some uncolored triangles show in the rendered model, this commit fixed it. --- src/texturegenerator.cpp | 2 +- src/triangletangentresolve.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/texturegenerator.cpp b/src/texturegenerator.cpp index e057a0e7..aa2e6a03 100644 --- a/src/texturegenerator.cpp +++ b/src/texturegenerator.cpp @@ -218,7 +218,7 @@ void TextureGenerator::generate() m_resultTextureBorderImage->fill(Qt::transparent); m_resultTextureNormalImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32); - m_resultTextureNormalImage->fill(Qt::transparent); + m_resultTextureNormalImage->fill(QColor(127, 127, 127)); m_resultTextureMetalnessRoughnessAmbientOcclusionImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32); m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(QColor(255, 255, 0)); diff --git a/src/triangletangentresolve.cpp b/src/triangletangentresolve.cpp index 037c7f69..157b4073 100644 --- a/src/triangletangentresolve.cpp +++ b/src/triangletangentresolve.cpp @@ -1,3 +1,4 @@ +#include #include "triangletangentresolve.h" void triangleTangentResolve(const Outcome &outcome, std::vector &tangents) @@ -24,8 +25,9 @@ void triangleTangentResolve(const Outcome &outcome, std::vector &tang QVector2D deltaUv1 = uv2 - uv1; QVector2D deltaUv2 = uv3 - uv1; auto bottom = deltaUv1.x() * deltaUv2.y() - deltaUv2.x() * deltaUv1.y(); - if (qFuzzyIsNull(bottom)) - continue; + if (qFuzzyIsNull(bottom)) { + bottom = 0.000001; + } float f = 1.0 / bottom; QVector3D tangent = { f * (deltaUv2.y() * edge1.x() - deltaUv1.y() * edge2.x()),