Skip to content

Commit

Permalink
chore: VR upscaling screen sizes (#623)
Browse files Browse the repository at this point in the history
* chore: VR upscaling screen sizes

* style: 🎨 apply clang-format changes

---------

Co-authored-by: doodlum <doodlum@users.noreply.github.com>
  • Loading branch information
doodlum and doodlum authored Oct 10, 2024
1 parent 228e5de commit 7ac4fa9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/FidelityFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void FidelityFX::Upscale(Texture2D* a_color, Texture2D* a_alphaMask, float2 a_ji
static auto gameViewport = RE::BSGraphics::State::GetSingleton();
static auto context = reinterpret_cast<ID3D11DeviceContext*>(renderer->GetRuntimeData().context);

auto state = State::GetSingleton();

{
FfxFsr3DispatchUpscaleDescription dispatchParameters{};

Expand All @@ -80,10 +82,10 @@ void FidelityFX::Upscale(Texture2D* a_color, Texture2D* a_alphaMask, float2 a_ji
dispatchParameters.reactive = ffxGetResource(a_alphaMask->resource.get(), L"FSR3_InputReactiveMap", FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ);
dispatchParameters.transparencyAndComposition = ffxGetResource(nullptr, L"FSR3_TransparencyAndCompositionMap", FFX_RESOURCE_STATE_PIXEL_COMPUTE_READ);

dispatchParameters.motionVectorScale.x = (float)gameViewport->screenWidth;
dispatchParameters.motionVectorScale.y = (float)gameViewport->screenHeight;
dispatchParameters.renderSize.width = gameViewport->screenWidth;
dispatchParameters.renderSize.height = gameViewport->screenHeight;
dispatchParameters.motionVectorScale.x = state->isVR ? state->screenSize.x / 2 : state->screenSize.x;
dispatchParameters.motionVectorScale.y = state->screenSize.y;
dispatchParameters.renderSize.width = (uint)state->screenSize.x;
dispatchParameters.renderSize.height = (uint)state->screenSize.y;
dispatchParameters.jitterOffset.x = -a_jitter.x;
dispatchParameters.jitterOffset.y = -a_jitter.y;

Expand Down
7 changes: 6 additions & 1 deletion src/Streamline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ void Streamline::UpdateConstants()
prevCameraToCamera.Invert();

sl::Constants slConstants = {};
slConstants.cameraAspectRatio = state->screenSize.x / state->screenSize.y;

if (state->isVR) {
slConstants.cameraAspectRatio = (state->screenSize.x * 0.5f) / state->screenSize.y;
} else {
slConstants.cameraAspectRatio = state->screenSize.x / state->screenSize.y;
}
slConstants.cameraFOV = Util::GetVerticalFOVRad();

static auto& cameraNear = (*(float*)(REL::RelocationID(517032, 403540).address() + 0x40));
Expand Down
9 changes: 7 additions & 2 deletions src/Upscaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ void Upscaling::UpdateJitter()
auto upscaleMethod = GetUpscaleMethod();
if (upscaleMethod != UpscaleMethod::kTAA) {
static auto gameViewport = RE::BSGraphics::State::GetSingleton();
auto state = State::GetSingleton();

ffxFsr3UpscalerGetJitterOffset(&jitter.x, &jitter.y, gameViewport->frameCount, 8);

gameViewport->projectionPosScaleX = -2.0f * jitter.x / (float)gameViewport->screenWidth;
gameViewport->projectionPosScaleY = 2.0f * jitter.y / (float)gameViewport->screenHeight;
if (state->isVR)
gameViewport->projectionPosScaleX = -jitter.x / state->screenSize.x;
else
gameViewport->projectionPosScaleX = -2.0f * jitter.x / state->screenSize.x;

gameViewport->projectionPosScaleY = 2.0f * jitter.y / state->screenSize.y;
}
}

Expand Down

0 comments on commit 7ac4fa9

Please sign in to comment.