diff --git a/src/TruePBR.cpp b/src/TruePBR.cpp index fc0b946363..ec1bcce6b1 100644 --- a/src/TruePBR.cpp +++ b/src/TruePBR.cpp @@ -365,6 +365,7 @@ void TruePBR::SetupGlintsTexture() void TruePBR::SetupFrame() { + SetupDefaultPBRLandTextureSet(); } void TruePBR::SetupTextureSetData() @@ -1089,8 +1090,8 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T RE::TESLandTexture* GetDefaultLandTexture() { - static RE::TESLandTexture* const defaultLandTexture = *REL::Relocation(RELOCATION_ID(514783, 400936)); - return defaultLandTexture; + static const auto defaultLandTextureAddress = REL::Relocation(RELOCATION_ID(514783, 400936)); + return *defaultLandTextureAddress; } struct TESObjectLAND_SetupMaterial @@ -1132,7 +1133,7 @@ struct TESObjectLAND_SetupMaterial if (land->loadedData != nullptr && land->loadedData->mesh[0] != nullptr) { land->data.flags.set(static_cast(8)); for (uint32_t quadIndex = 0; quadIndex < 4; ++quadIndex) { - auto shaderProperty = static_cast(RE::MemoryManager::GetSingleton()->Allocate(sizeof(RE::BSLightingShaderProperty), 0, false)); + auto shaderProperty = static_cast(RE::MemoryManager::GetSingleton()->Allocate(REL::Module::IsVR() ? 0x178 : sizeof(RE::BSLightingShaderProperty), 0, false)); shaderProperty->Ctor(); { @@ -1601,9 +1602,17 @@ void TruePBR::PostPostLoad() void TruePBR::DataLoaded() { defaultPbrLandTextureSet = RE::TESForm::LookupByEditorID("DefaultPBRLand"); - if (defaultPbrLandTextureSet != nullptr) { - logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID()); - GetDefaultLandTexture()->textureSet = defaultPbrLandTextureSet; + SetupDefaultPBRLandTextureSet(); +} + +void TruePBR::SetupDefaultPBRLandTextureSet() +{ + if (!defaultLandTextureSetReplaced && defaultPbrLandTextureSet != nullptr) { + if (auto* defaultLandTexture = GetDefaultLandTexture()) { + logger::info("[TruePBR] replacing default land texture set record with {}", defaultPbrLandTextureSet->GetFormEditorID()); + defaultLandTexture->textureSet = defaultPbrLandTextureSet; + defaultLandTextureSetReplaced = true; + } } } diff --git a/src/TruePBR.h b/src/TruePBR.h index b309906c87..64bd6ecd9e 100644 --- a/src/TruePBR.h +++ b/src/TruePBR.h @@ -74,8 +74,11 @@ struct TruePBR PBRTextureSetData* GetPBRTextureSetData(const RE::TESForm* textureSet); bool IsPBRTextureSet(const RE::TESForm* textureSet); + void SetupDefaultPBRLandTextureSet(); + std::unordered_map pbrTextureSets; RE::BGSTextureSet* defaultPbrLandTextureSet = nullptr; + bool defaultLandTextureSetReplaced = false; std::string selectedPbrTextureSetName; PBRTextureSetData* selectedPbrTextureSet = nullptr;