Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _codeql_detected_source_root
37 changes: 32 additions & 5 deletions src/Features/Upscaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
#include <directx/d3dx12.h>
#include <format>

// Extended structure definition for BSImagespaceShaderISTemporalAA
// TODO: Contribute this structure extension to alandtse/CommonLibVR
// This extends RE::ImageSpaceManager::UNK_BSImagespaceShaderISTemporalAA with additional members
namespace
{
struct ExtendedTemporalAAStruct
{
RE::BSImagespaceShaderISTemporalAA* shader; // 00 - Main TAA shader
RE::BSImagespaceShader* BSImagespaceShaderISTemporalAA_UI; // 08 - TAA for UI elements
RE::BSImagespaceShader* BSImagespaceShaderISTemporalAA_Water; // 10 - TAA for water
bool taaEnabled; // 18 - Global TAA enable flag
std::uint8_t pad19[7]; // 19 - Padding for alignment
std::uint64_t unk20; // 20 - Unknown (needs further RE)
std::uint64_t unk28; // 28 - Unknown (needs further RE)
std::uint64_t unk30; // 30 - Unknown (needs further RE)
bool enableWaterTAA; // 38 - Water TAA enable flag
std::uint8_t pad39[7]; // 39 - Padding to 0x40
};
static_assert(sizeof(ExtendedTemporalAAStruct) == 0x40, "ExtendedTemporalAAStruct must be 0x40 bytes");
}

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
Upscaling::Settings,
upscaleMethod,
Expand Down Expand Up @@ -701,12 +722,15 @@ void Upscaling::ConfigureTAA()
auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton();
GET_INSTANCE_MEMBER(BSImagespaceShaderISTemporalAA, imageSpaceManager);

// Cast to extended structure to access enableWaterTAA
// This structure extension should be contributed to CommonLibVR upstream
auto* extendedStruct = reinterpret_cast<ExtendedTemporalAAStruct*>(BSImagespaceShaderISTemporalAA);

// Disable water TAA when upscaling is enabled
bool* enableWaterTAA = reinterpret_cast<bool*>(reinterpret_cast<uintptr_t>(BSImagespaceShaderISTemporalAA) + 0x38LL);
*enableWaterTAA = upscaleMethod == UpscaleMethod::kNONE || upscaleMethod == UpscaleMethod::kTAA;
extendedStruct->enableWaterTAA = upscaleMethod == UpscaleMethod::kNONE || upscaleMethod == UpscaleMethod::kTAA;

// Force enable TAA if needed
BSImagespaceShaderISTemporalAA->taaEnabled = upscaleMethod != UpscaleMethod::kNONE;
extendedStruct->taaEnabled = upscaleMethod != UpscaleMethod::kNONE;
}

void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport)
Expand Down Expand Up @@ -1474,11 +1498,14 @@ void Upscaling::Main_PostProcessing::thunk(RE::ImageSpaceManager* a_this, uint32
auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton();
GET_INSTANCE_MEMBER(BSImagespaceShaderISTemporalAA, imageSpaceManager);

BSImagespaceShaderISTemporalAA->taaEnabled = upscaleMethod == UpscaleMethod::kTAA;
// Cast to extended structure for consistent access pattern
auto* extendedStruct = reinterpret_cast<ExtendedTemporalAAStruct*>(BSImagespaceShaderISTemporalAA);

extendedStruct->taaEnabled = upscaleMethod == UpscaleMethod::kTAA;

func(a_this, a3, a_target, a_4, a_5);

BSImagespaceShaderISTemporalAA->taaEnabled = false;
extendedStruct->taaEnabled = false;
}

void Upscaling::SetScissorRect::thunk(RE::BSGraphics::Renderer* This, int a_left, int a_top, int a_right, int a_bottom)
Expand Down