diff --git a/package/Shaders/DistantTree.hlsl b/package/Shaders/DistantTree.hlsl index 21640deac2..afa7354306 100644 --- a/package/Shaders/DistantTree.hlsl +++ b/package/Shaders/DistantTree.hlsl @@ -200,7 +200,7 @@ PS_OUTPUT main(PS_INPUT input) discard; } - float alpha = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy).w; + float alpha = TexDiffuse.SampleBias(SampDiffuse, input.TexCoord.xy, SharedData::MipBias).w; if ((alpha - AlphaTestRefRS) < 0) { discard; @@ -209,7 +209,7 @@ PS_OUTPUT main(PS_INPUT input) psout.Diffuse.xyz = input.Depth.xxx / input.Depth.yyy; psout.Diffuse.w = 0; # else - float4 baseColor = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy); + float4 baseColor = TexDiffuse.SampleBias(SampDiffuse, input.TexCoord.xy, SharedData::MipBias); if ((baseColor.w - AlphaTestRefRS) < 0) { discard; diff --git a/src/Features/Upscaling.cpp b/src/Features/Upscaling.cpp index 97fffc4f71..7cceffec8d 100644 --- a/src/Features/Upscaling.cpp +++ b/src/Features/Upscaling.cpp @@ -646,19 +646,10 @@ void GetJitterOffset(float* outX, float* outY, int32_t index, int32_t phaseCount *outY = y; } -void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) +void Upscaling::ConfigureTAA() { auto upscaleMethod = GetUpscaleMethod(); - // Delete or create resources as necessary - CheckResources(upscaleMethod); - - // The game defaults this to a non-zero value - if (!globals::game::isVR) { - auto fDRClampOffset = RE::GetINISetting("fDRClampOffset:Display"); - fDRClampOffset->data.f = 0.0f; - } - auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton(); GET_INSTANCE_MEMBER(BSImagespaceShaderISTemporalAA, imageSpaceManager); @@ -668,6 +659,20 @@ void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) // Force enable TAA if needed BSImagespaceShaderISTemporalAA->taaEnabled = upscaleMethod != UpscaleMethod::kNONE; +} + +void Upscaling::ConfigureUpscaling(RE::BSGraphics::State* a_viewport) +{ + auto upscaleMethod = GetUpscaleMethod(); + + // Delete or create resources as necessary + CheckResources(upscaleMethod); + + // The game defaults this to a non-zero value + if (!globals::game::isVR) { + auto fDRClampOffset = RE::GetINISetting("fDRClampOffset:Display"); + fDRClampOffset->data.f = 0.0f; + } // Cache original TAA values for UI projectionPosScaleX = a_viewport->projectionPosScaleX; @@ -1037,18 +1042,7 @@ void Upscaling::CopySharedD3D12Resources() // Not required by XeSS if (upscaleMethod == UpscaleMethod::kFSR || (d3d12SwapChainActive && settings.frameGenerationMode && upscaleMethod != UpscaleMethod::kXESS)) { auto& motionVector = renderer->GetRuntimeData().renderTargets[RE::RENDER_TARGETS::kMOTION_VECTOR]; - - // Copy only the dynamic resolution area - auto renderSize = Util::ConvertToDynamic(globals::state->screenSize); - D3D11_BOX srcBox = {}; - srcBox.left = 0; - srcBox.top = 0; - srcBox.front = 0; - srcBox.right = (UINT)renderSize.x; - srcBox.bottom = (UINT)renderSize.y; - srcBox.back = 1; - - context->CopySubresourceRegion(motionVectorBufferShared12->resource11, 0, 0, 0, 0, motionVector.texture, 0, &srcBox); + context->CopyResource(motionVectorBufferShared12->resource11, motionVector.texture); } if (upscaleMethod == UpscaleMethod::kFSR || upscaleMethod == UpscaleMethod::kXESS || d3d12SwapChainActive && settings.frameGenerationMode) { @@ -1428,17 +1422,10 @@ void Upscaling::Upscale() if (upscaleMethod == UpscaleMethod::kDLSS) streamline.Upscale(main.texture, reactiveMaskTexture->resource.get(), transparencyCompositionMaskTexture->resource.get(), motionVectorCopyTexture->resource.get(), sl::DLSSPreset::ePresetK); else { - // Copy input color texture to shared D3D12 resource (only dynamic resolution area) auto renderSize = Util::ConvertToDynamic(globals::state->screenSize); - D3D11_BOX srcBox = {}; - srcBox.left = 0; - srcBox.top = 0; - srcBox.front = 0; - srcBox.right = (UINT)renderSize.x; - srcBox.bottom = (UINT)renderSize.y; - srcBox.back = 1; - context->CopySubresourceRegion(inputColorBufferShared12->resource11, 0, 0, 0, 0, main.texture, 0, &srcBox); + // Copy input color texture to shared D3D12 resource + context->CopyResource(inputColorBufferShared12->resource11, main.texture); // Wait for D3D11 to finish winrt::com_ptr d3d11Context4; @@ -1622,6 +1609,7 @@ void Upscaling::UpscaleDepth() void Upscaling::Main_UpdateJitter::thunk(RE::BSGraphics::State* a_state) { + globals::features::upscaling.ConfigureTAA(); func(a_state); globals::features::upscaling.ConfigureUpscaling(a_state); } diff --git a/src/Features/Upscaling.h b/src/Features/Upscaling.h index 22fb4914e1..975f91df3f 100644 --- a/src/Features/Upscaling.h +++ b/src/Features/Upscaling.h @@ -128,9 +128,9 @@ struct Upscaling : Feature winrt::com_ptr upscaleBlendState; winrt::com_ptr upscaleRasterizerState; + void ConfigureTAA(); void ConfigureUpscaling(RE::BSGraphics::State* a_state); void Upscale(); - void ApplyNISSharpening(); // D3D11 textures Texture2D* reactiveMaskTexture = nullptr; diff --git a/src/Hooks.cpp b/src/Hooks.cpp index c881728e97..72bd0858ea 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -868,13 +868,6 @@ namespace Hooks */ void Install() { - if (!globals::features::upscaling.loaded) { - logger::info("Hooking D3D11CreateDeviceAndSwapChain"); - *(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain"); - } - - *(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1"); - if (!REL::Module::IsVR()) { logger::info("Hooking BSImageSpace::Init::IBLF"); stl::detour_thunk(REL::RelocationID(100480, 107198)); @@ -978,4 +971,15 @@ namespace Hooks stl::write_thunk_call(REL::RelocationID(100565, 107300).address() + REL::Relocate(0x523, 0xB0E, 0x5FE)); } + + void InstallEarlyHooks() + { + if (!globals::features::upscaling.loaded) { + logger::info("Hooking D3D11CreateDeviceAndSwapChain"); + *(uintptr_t*)&ptrD3D11CreateDeviceAndSwapChain = SKSE::PatchIAT(hk_D3D11CreateDeviceAndSwapChain, "d3d11.dll", "D3D11CreateDeviceAndSwapChain"); + } + + logger::info("Hooking CreateDXGIFactory"); + *(uintptr_t*)&ptrCreateDXGIFactory = SKSE::PatchIAT(hk_CreateDXGIFactory, "dxgi.dll", !REL::Module::IsVR() ? "CreateDXGIFactory" : "CreateDXGIFactory1"); + } } \ No newline at end of file diff --git a/src/Hooks.h b/src/Hooks.h index f22fd880b6..335a7df7d8 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -20,4 +20,5 @@ namespace Hooks }; void Install(); + void InstallEarlyHooks(); } diff --git a/src/XSEPlugin.cpp b/src/XSEPlugin.cpp index 6ade711af4..522c58a167 100644 --- a/src/XSEPlugin.cpp +++ b/src/XSEPlugin.cpp @@ -196,6 +196,7 @@ bool Load() } if (errors.empty()) { + Hooks::InstallEarlyHooks(); logger::info("Calling feature Load methods"); for (auto* feature : Feature::GetFeatureList()) { if (feature->loaded) {