Fix normal tangent

Some tangents did not get calculate, this cause some uncolored triangles show in the rendered model, this commit fixed it.
master
Jeremy Hu 2018-11-17 23:42:46 +08:00
parent 1853e45ea4
commit 538528d103
2 changed files with 5 additions and 3 deletions

View File

@ -218,7 +218,7 @@ void TextureGenerator::generate()
m_resultTextureBorderImage->fill(Qt::transparent); m_resultTextureBorderImage->fill(Qt::transparent);
m_resultTextureNormalImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32); 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 = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(QColor(255, 255, 0)); m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(QColor(255, 255, 0));

View File

@ -1,3 +1,4 @@
#include <QDebug>
#include "triangletangentresolve.h" #include "triangletangentresolve.h"
void triangleTangentResolve(const Outcome &outcome, std::vector<QVector3D> &tangents) void triangleTangentResolve(const Outcome &outcome, std::vector<QVector3D> &tangents)
@ -24,8 +25,9 @@ void triangleTangentResolve(const Outcome &outcome, std::vector<QVector3D> &tang
QVector2D deltaUv1 = uv2 - uv1; QVector2D deltaUv1 = uv2 - uv1;
QVector2D deltaUv2 = uv3 - uv1; QVector2D deltaUv2 = uv3 - uv1;
auto bottom = deltaUv1.x() * deltaUv2.y() - deltaUv2.x() * deltaUv1.y(); auto bottom = deltaUv1.x() * deltaUv2.y() - deltaUv2.x() * deltaUv1.y();
if (qFuzzyIsNull(bottom)) if (qFuzzyIsNull(bottom)) {
continue; bottom = 0.000001;
}
float f = 1.0 / bottom; float f = 1.0 / bottom;
QVector3D tangent = { QVector3D tangent = {
f * (deltaUv2.y() * edge1.x() - deltaUv1.y() * edge2.x()), f * (deltaUv2.y() * edge1.x() - deltaUv1.y() * edge2.x()),