Skip to content

Commit

Permalink
fixed up my screwup, the material compiler IR construction now can un…
Browse files Browse the repository at this point in the history
…roll texture scale chains again.
  • Loading branch information
devshgraphicsprogramming committed Jul 2, 2021
1 parent 39cb993 commit 8ae65e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions include/nbl/ext/MitsubaLoader/SContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<asset::ICPUImage, asset::IAsset::ET_IMAGE>(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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down

0 comments on commit 8ae65e5

Please sign in to comment.