diff --git a/include/nbl/ext/MitsubaLoader/SContext.h b/include/nbl/ext/MitsubaLoader/SContext.h index 4380d9ddf1..334f9bca52 100644 --- a/include/nbl/ext/MitsubaLoader/SContext.h +++ b/include/nbl/ext/MitsubaLoader/SContext.h @@ -61,7 +61,7 @@ namespace MitsubaLoader return imageCacheKey + "?view"; } - static std::string derivMapCacheKey(const CElementBSDF::BumpMap& _bump) + static std::string derivMapCacheKey(const CElementTexture* bitmap, bool wasNormal) { using namespace std::string_literals; static const char* wrap[5] @@ -73,18 +73,17 @@ namespace MitsubaLoader "?one" }; - const auto* bitmap = _bump.texture; std::string key = bitmap->bitmap.filename.svalue + "?deriv"s; - key += _bump.wasNormal ? "n"s:"h"s; + key += wasNormal ? "?n"s:"?h"s; key += wrap[bitmap->bitmap.wrapModeU]; key += wrap[bitmap->bitmap.wrapModeV]; return key; } - static std::string derivMapViewCacheKey(const CElementBSDF::BumpMap& _bump) + static std::string derivMapViewCacheKey(const CElementTexture* bitmap, bool wasNormal) { - return imageViewCacheKey(derivMapCacheKey(_bump)); + return imageViewCacheKey(derivMapCacheKey(bitmap,wasNormal)); } static std::string blendWeightViewCacheKey(const CElementTexture* bitmap) diff --git a/src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp b/src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp index cb2a078fa6..942e6e4278 100644 --- a/src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp +++ b/src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp @@ -1271,12 +1271,13 @@ auto CMitsubaLoader::genBSDFtreeTraversal(SContext& ctx, const CElementBSDF* _bs // TODO check and restore if dummy (image and sampler) auto bumpmap = std::get<0>(bm)->getCreationParameters().image; auto sampler = std::get<1>(bm); - const std::string key = ctx.derivMapCacheKey(bsdf->bumpmap); + const bool wasNormal = bsdf->bumpmap.wasNormal; + const std::string key = ctx.derivMapCacheKey(bumpmap_element,wasNormal); if (!getBuiltinAsset(key.c_str(), m_assetMgr)) { // TODO: @Crisspl retrieve the normalization factor from the deriv map filter, then adjust the scale accordingly! - auto derivmap = createDerivMap(bumpmap.get(),sampler.get(),bsdf->bumpmap.wasNormal); + auto derivmap = createDerivMap(bumpmap.get(),sampler.get(),wasNormal); asset::SAssetBundle imgBundle(nullptr,{ derivmap }); ctx.override_->insertAssetIntoCache(std::move(imgBundle), key, ctx.inner, 0u); auto derivmap_view = createImageView(std::move(derivmap)); diff --git a/src/nbl/ext/MitsubaLoader/CMitsubaMaterialCompilerFrontend.cpp b/src/nbl/ext/MitsubaLoader/CMitsubaMaterialCompilerFrontend.cpp index 06e207e366..0a9adbfb64 100644 --- a/src/nbl/ext/MitsubaLoader/CMitsubaMaterialCompilerFrontend.cpp +++ b/src/nbl/ext/MitsubaLoader/CMitsubaMaterialCompilerFrontend.cpp @@ -18,7 +18,7 @@ namespace MitsubaLoader const CElementTexture* texture = nullptr; float scale = 1.f; std::tie(texture, scale) = getTexture_common(_bump.texture); - std::string key = m_loaderContext->derivMapCacheKey(_bump); + std::string key = m_loaderContext->derivMapCacheKey(texture,_bump.wasNormal); if (texture->type != CElementTexture::BITMAP) return { nullptr, nullptr, 0.f };