From 3a38aa8deb2647777783cb949549758ac554414a Mon Sep 17 00:00:00 2001 From: Ilya Perapechka Date: Fri, 30 Aug 2024 21:10:50 +0300 Subject: [PATCH] feat: pbr replacement for default land texture. --- src/TruePBR.cpp | 19 +++++++++++++++++++ src/TruePBR.h | 2 ++ src/XSEPlugin.cpp | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/TruePBR.cpp b/src/TruePBR.cpp index 4c923efa3..1e4f28168 100644 --- a/src/TruePBR.cpp +++ b/src/TruePBR.cpp @@ -1197,6 +1197,12 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T } } +RE::TESLandTexture* GetDefaultLandTexture() +{ + static RE::TESLandTexture* const defaultLandTexture = *REL::Relocation(RELOCATION_ID(514783, 400936)); + return defaultLandTexture; +} + bool hk_TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land); decltype(&hk_TESObjectLAND_SetupMaterial) ptr_TESObjectLAND_SetupMaterial; @@ -1212,6 +1218,8 @@ bool hk_TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) isPbr = true; break; } + } else if (singleton->defaultPbrLandTextureSet != nullptr) { + isPbr = true; } for (uint32_t textureIndex = 0; textureIndex < 6; ++textureIndex) { if (land->loadedData->quadTextures[quadIndex][textureIndex] != nullptr) { @@ -1257,6 +1265,8 @@ bool hk_TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land) if (auto defTexture = land->loadedData->defQuadTextures[quadIndex]) { SetupLandscapeTexture(*material, *defTexture, 0, textureSets); + } else { + SetupLandscapeTexture(*material, *GetDefaultLandTexture(), 0, textureSets); } for (uint32_t textureIndex = 0; textureIndex < BSLightingShaderMaterialPBRLandscape::NumTiles - 1; ++textureIndex) { if (auto landTexture = land->loadedData->quadTextures[quadIndex][textureIndex]) { @@ -1668,6 +1678,15 @@ void TruePBR::PostPostLoad() stl::write_vfunc<0x4A, TESBoundObject_Clone3D>(RE::VTABLE_TESObjectSTAT[0]); } +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; + } +} + void TruePBR::SetShaderResouces() { auto context = State::GetSingleton()->context; diff --git a/src/TruePBR.h b/src/TruePBR.h index 7fab0a608..6fbe84b4c 100644 --- a/src/TruePBR.h +++ b/src/TruePBR.h @@ -37,6 +37,7 @@ struct TruePBR void SaveSettings(json& o_json); void PrePass(); void PostPostLoad(); + void DataLoaded(); void SetShaderResouces(); void GenerateShaderPermutations(RE::BSShader* shader); @@ -97,6 +98,7 @@ struct TruePBR bool IsPBRTextureSet(const RE::TESForm* textureSet); std::unordered_map pbrTextureSets; + RE::BGSTextureSet* defaultPbrLandTextureSet = nullptr; std::string selectedPbrTextureSetName; PBRTextureSetData* selectedPbrTextureSet = nullptr; diff --git a/src/XSEPlugin.cpp b/src/XSEPlugin.cpp index 8fe0f495a..9eb34c0b6 100644 --- a/src/XSEPlugin.cpp +++ b/src/XSEPlugin.cpp @@ -4,6 +4,7 @@ #include "Menu.h" #include "ShaderCache.h" #include "State.h" +#include "TruePBR.h" #include "ENB/ENBSeriesAPI.h" #include "Features/ExtendedMaterials.h" @@ -129,6 +130,7 @@ void MessageHandler(SKSE::MessagingInterface::Message* message) shaderCache.WriteDiskCacheInfo(); } + TruePBR::GetSingleton()->DataLoaded(); for (auto* feature : Feature::GetFeatureList()) { if (feature->loaded) { feature->DataLoaded();