Skip to content
Merged
8 changes: 4 additions & 4 deletions src/Features/TerrainHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ bool TerrainHelper::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land)
std::array<RE::BGSTextureSet*, 6> textureSets;
auto defTexture = land->loadedData->defQuadTextures[quadI];
if (defTexture != nullptr && defTexture->formID != 0) {
textureSets[0] = defTexture->textureSet;
textureSets[0] = Util::GetSeasonalSwap(defTexture->textureSet);
} else {
// this is a default texture
textureSets[0] = defaultLandTexture;
textureSets[0] = Util::GetSeasonalSwap(defaultLandTexture);
}
for (uint32_t textureI = 0; textureI < 5; ++textureI) {
auto curTexture = land->loadedData->quadTextures[quadI][textureI];
Expand All @@ -85,9 +85,9 @@ bool TerrainHelper::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land)

if (curTexture->formID == 0) {
// this is a default texture
textureSets[textureI + 1] = defaultLandTexture;
textureSets[textureI + 1] = Util::GetSeasonalSwap(defaultLandTexture);
} else {
textureSets[textureI + 1] = land->loadedData->quadTextures[quadI][textureI]->textureSet;
textureSets[textureI + 1] = Util::GetSeasonalSwap(land->loadedData->quadTextures[quadI][textureI]->textureSet);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,15 @@ namespace Hooks
{
static bool thunk(RE::TESObjectLAND* land)
{
bool vanillaResult = func(land);

// setup material for PBR
auto TruePBRSingleton = globals::truePBR;
if (TruePBRSingleton->TESObjectLAND_SetupMaterial(land)) {
// if PBR, we are done
return true;
}

bool vanillaResult = func(land);

// setup material for terrain helper
auto terrainHelper = globals::features::terrainHelper;
if (vanillaResult && terrainHelper->loaded) {
Expand Down
8 changes: 4 additions & 4 deletions src/TruePBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,13 +1059,13 @@ void SetupLandscapeTexture(BSLightingShaderMaterialPBRLandscape& material, RE::T
return;
}

auto textureSet = landTexture.textureSet;
auto textureSet = Util::GetSeasonalSwap(landTexture.textureSet);
if (textureSet == nullptr) {
return;
}

auto truePBR = globals::truePBR;
auto* textureSetData = truePBR->GetPBRTextureSetData(landTexture.textureSet);
auto* textureSetData = truePBR->GetPBRTextureSetData(textureSet);
const bool isPbr = textureSetData != nullptr;

textureSets[textureIndex] = textureSetData;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ bool TruePBR::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land)
if (land->loadedData != nullptr) {
for (uint32_t quadIndex = 0; quadIndex < 4; ++quadIndex) {
if (land->loadedData->defQuadTextures[quadIndex] != nullptr) {
if (singleton->IsPBRTextureSet(land->loadedData->defQuadTextures[quadIndex]->textureSet)) {
if (singleton->IsPBRTextureSet(Util::GetSeasonalSwap(land->loadedData->defQuadTextures[quadIndex]->textureSet))) {
isPbr = true;
break;
}
Expand All @@ -1108,7 +1108,7 @@ bool TruePBR::TESObjectLAND_SetupMaterial(RE::TESObjectLAND* land)
}
for (uint32_t textureIndex = 0; textureIndex < 6; ++textureIndex) {
if (land->loadedData->quadTextures[quadIndex][textureIndex] != nullptr) {
if (singleton->IsPBRTextureSet(land->loadedData->quadTextures[quadIndex][textureIndex]->textureSet)) {
if (singleton->IsPBRTextureSet(Util::GetSeasonalSwap(land->loadedData->quadTextures[quadIndex][textureIndex]->textureSet))) {
isPbr = true;
break;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Utils/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,19 @@ namespace Util
{
return IsNewFrame(globals::state->frameCount);
}

RE::BGSTextureSet* GetSeasonalSwap(RE::BGSTextureSet* textureSet)
{
if (textureSet == nullptr) {
return nullptr;
}

if (textureSet->pad12C > 0) {
Comment thread
alandtse marked this conversation as resolved.
if (auto* form = RE::TESForm::LookupByID<RE::BGSTextureSet>(textureSet->pad12C)) {
return form;
}
}

return textureSet;
}
} // namespace Util
15 changes: 15 additions & 0 deletions src/Utils/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,19 @@ namespace Util
}
bool IsNewFrame();
};

/**
* @brief Retrieves the seasonal texture swap for a given texture set, if available.
*
* This function checks if a given texture set has been swapped by Seasons of Skyrim.
* If swapped, pad12C will be > 0 and will be the formid of the swapped texture set.
*
* @param textureSet Pointer to the original BGSTextureSet to check for seasonal swaps.
* Can be nullptr.
*
* @return Pointer to the seasonal swap texture set if found and valid, otherwise
* returns the original textureSet parameter. Returns nullptr if the input
* textureSet is nullptr.
*/
[[nodiscard]] RE::BGSTextureSet* GetSeasonalSwap(RE::BGSTextureSet* textureSet);
} // namespace Util