Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package/Shaders/DistantTree.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
50 changes: 19 additions & 31 deletions src/Features/Upscaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<ID3D11DeviceContext4> d3d11Context4;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Upscaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ struct Upscaling : Feature
winrt::com_ptr<ID3D11BlendState> upscaleBlendState;
winrt::com_ptr<ID3D11RasterizerState> upscaleRasterizerState;

void ConfigureTAA();
void ConfigureUpscaling(RE::BSGraphics::State* a_state);
void Upscale();
void ApplyNISSharpening();

// D3D11 textures
Texture2D* reactiveMaskTexture = nullptr;
Expand Down
18 changes: 11 additions & 7 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BSImageSpace_Init_IBLF>(REL::RelocationID(100480, 107198));
Expand Down Expand Up @@ -978,4 +971,15 @@ namespace Hooks

stl::write_thunk_call<BSLightingShader_SetupGeometry_GeometrySetupConstantPointLights>(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");
}
Comment thread
doodlum marked this conversation as resolved.
}
1 change: 1 addition & 0 deletions src/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ namespace Hooks
};

void Install();
void InstallEarlyHooks();
}
1 change: 1 addition & 0 deletions src/XSEPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down