diff --git a/parts/mdl/mdlpart.cpp b/parts/mdl/mdlpart.cpp index 94adce6..3c01767 100644 --- a/parts/mdl/mdlpart.cpp +++ b/parts/mdl/mdlpart.cpp @@ -307,29 +307,24 @@ RenderMaterial MDLPart::createMaterial(const physis_Material &material) qInfo() << "Loading" << t; - char type = t[t.length() - 5]; + const auto type = t.substr(t.find_last_of('_') + 1, t.find_last_of('.') - t.find_last_of('_') - 1); auto texture = physis_texture_parse(cache.lookupFile(QLatin1String(material.textures[i]))); if (texture.rgba != nullptr) { - switch (type) { - case 'm': { - newMaterial.multiTexture = renderer->addGameTexture(VK_FORMAT_R8G8B8A8_UNORM, texture); - renderer->device().nameTexture(*newMaterial.multiTexture, material.textures[i]); - } break; - case 'd': { - newMaterial.diffuseTexture = renderer->addGameTexture(VK_FORMAT_R8G8B8A8_UNORM, texture); - renderer->device().nameTexture(*newMaterial.diffuseTexture, material.textures[i]); - } break; - case 'n': { - newMaterial.normalTexture = renderer->addGameTexture(VK_FORMAT_R8G8B8A8_UNORM, texture); - renderer->device().nameTexture(*newMaterial.normalTexture, material.textures[i]); - } break; - case 's': { - newMaterial.specularTexture = renderer->addGameTexture(VK_FORMAT_R8G8B8A8_UNORM, texture); - renderer->device().nameTexture(*newMaterial.specularTexture, material.textures[i]); - } break; - default: - qDebug() << "unhandled type" << type; - break; + auto gameTexture = renderer->addGameTexture(VK_FORMAT_R8G8B8A8_UNORM, texture); + renderer->device().nameTexture(gameTexture, material.textures[i]); + + if (type == "m") { + newMaterial.multiTexture = gameTexture; + } else if (type == "d") { + newMaterial.diffuseTexture = gameTexture; + } else if (type == "n") { + newMaterial.normalTexture = gameTexture; + } else if (type == "s") { + newMaterial.specularTexture = gameTexture; + } else if (type == "id") { + newMaterial.indexTexture = gameTexture; + } else { + qWarning() << "Unknown texture type" << type; } } else { qInfo() << "Failed to load" << t; diff --git a/renderer/include/drawobject.h b/renderer/include/drawobject.h index f86f4f1..1099c2b 100644 --- a/renderer/include/drawobject.h +++ b/renderer/include/drawobject.h @@ -27,6 +27,7 @@ struct RenderMaterial { std::optional normalTexture; std::optional specularTexture; std::optional multiTexture; + std::optional indexTexture; std::optional tableTexture; diff --git a/renderer/src/gamerenderer.cpp b/renderer/src/gamerenderer.cpp index 60a734a..505757b 100644 --- a/renderer/src/gamerenderer.cpp +++ b/renderer/src/gamerenderer.cpp @@ -1302,9 +1302,12 @@ GameRenderer::createDescriptorFor(const DrawObject *object, const CachedPipeline info->imageView = m_viewPositionBuffer.imageView; } else if (strcmp(name, "g_SamplerDepth") == 0) { info->imageView = m_depthBuffer.imageView; - } else if ((strcmp(name, "g_SamplerNormal") == 0 || strcmp(name, "g_SamplerIndex") == 0) && material->normalTexture.has_value()) { + } else if (strcmp(name, "g_SamplerNormal") == 0 && material->normalTexture.has_value()) { Q_ASSERT(material); info->imageView = material->normalTexture->imageView; + } else if (strcmp(name, "g_SamplerIndex") == 0 && material->indexTexture.has_value()) { + Q_ASSERT(material); + info->imageView = material->indexTexture->imageView; } else if (strcmp(name, "g_SamplerLightDiffuse") == 0) { Q_ASSERT(material); info->imageView = m_lightBuffer.imageView;