Fix PBR material preview

The metallic and roughness texture not show up before, now should be ok if material is been set properly, however, export not done yet.
master
Jeremy Hu 2018-11-11 17:13:46 +08:00
parent b224b959ac
commit dff8e40ef8
3 changed files with 13 additions and 6 deletions

View File

@ -330,17 +330,17 @@ void main()
float metalness = vertMetalness;
if (metalnessMapEnabled == 1) {
metalness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).b / 255.0;
metalness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).b;
}
float roughness = vertRoughness;
if (roughnessMapEnabled == 1) {
roughness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).r / 255.0;
roughness = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).r;
}
float ambientOcclusion = 1.0;
if (ambientOcclusionMapEnabled == 1) {
ambientOcclusion = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).g / 255.0;
ambientOcclusion = texture2D(metalnessRoughnessAmbientOcclusionMapId, vertTexCoord).g;
}
roughness = min(0.99, roughness);

View File

@ -218,6 +218,12 @@ MeshLoader::MeshLoader(const MeshLoader &mesh) :
if (nullptr != mesh.m_normalMapImage) {
this->m_normalMapImage = new QImage(*mesh.m_normalMapImage);
}
if (nullptr != mesh.m_metalnessRoughnessAmbientOcclusionImage) {
this->m_metalnessRoughnessAmbientOcclusionImage = new QImage(*mesh.m_metalnessRoughnessAmbientOcclusionImage);
this->m_hasMetalnessInImage = mesh.m_hasMetalnessInImage;
this->m_hasRoughnessInImage = mesh.m_hasRoughnessInImage;
this->m_hasAmbientOcclusionInImage = mesh.m_hasAmbientOcclusionInImage;
}
this->m_vertices = mesh.m_vertices;
this->m_faces = mesh.m_faces;
this->m_triangulatedVertices = mesh.m_triangulatedVertices;
@ -301,6 +307,7 @@ MeshLoader::~MeshLoader()
m_edgeVertexCount = 0;
delete m_textureImage;
delete m_normalMapImage;
delete m_metalnessRoughnessAmbientOcclusionImage;
}
const std::vector<QVector3D> &MeshLoader::vertices()

View File

@ -216,13 +216,13 @@ void TextureGenerator::generate()
m_resultTextureMetalnessRoughnessAmbientOcclusionImage->fill(Qt::transparent);
m_resultTextureMetalnessImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureMetalnessImage->fill(Qt::transparent);
m_resultTextureMetalnessImage->fill(Qt::black);
m_resultTextureRoughnessImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureRoughnessImage->fill(Qt::transparent);
m_resultTextureRoughnessImage->fill(Qt::white);
m_resultTextureAmbientOcclusionImage = new QImage(TextureGenerator::m_textureSize, TextureGenerator::m_textureSize, QImage::Format_ARGB32);
m_resultTextureAmbientOcclusionImage->fill(Qt::transparent);
m_resultTextureAmbientOcclusionImage->fill(Qt::white);
auto createImageEndTime = countTimeConsumed.elapsed();