From 15e809d65b7dc5c10f15f31d0738dc6d35618c49 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:14:56 +0300 Subject: [PATCH] Interpolate to original 4:3 scale. --- UnleashedRecomp/patches/csd_patches.cpp | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/UnleashedRecomp/patches/csd_patches.cpp b/UnleashedRecomp/patches/csd_patches.cpp index c8db64d5..b56c4a1a 100644 --- a/UnleashedRecomp/patches/csd_patches.cpp +++ b/UnleashedRecomp/patches/csd_patches.cpp @@ -175,8 +175,8 @@ PPC_FUNC(sub_825E2E60) static constexpr float NARROW_ASPECT_RATIO = 4.0f / 3.0f; static constexpr float WIDE_ASPECT_RATIO = 16.0f / 9.0f; static constexpr float STEAM_DECK_ASPECT_RATIO = 16.0f / 10.0f; -static constexpr float INV_WIDE_ASPECT_RATIO = 1.0f / WIDE_ASPECT_RATIO; -static constexpr float INV_WIDE_SCALE = 1280.0f / 960.0f; +static constexpr float TALL_ASPECT_RATIO = 1.0f / WIDE_ASPECT_RATIO; +static constexpr float TALL_SCALE = 1280.0f / 960.0f; static float g_offsetX; static float g_offsetY; @@ -184,6 +184,11 @@ static float g_scale; static float g_worldMapOffset; +static float ComputeScale(float aspectRatio) +{ + return ((aspectRatio * 720.0f) / 1280.0f) / sqrt((aspectRatio * 720.0f) / 1280.0f); +} + static void ComputeOffsets(float width, float height) { float aspectRatio = width / height; @@ -195,12 +200,15 @@ static void ComputeOffsets(float width, float height) g_offsetX = 0.5f * (aspectRatio * 720.0f - 1280.0f); g_offsetY = 0.0f; - // narrow resolutions will zoom the UI in, but we want the gameplay - // UI to retain the same scale at Steam Deck's aspect ratio + // keep same scale above Steam Deck aspect ratio if (aspectRatio < WIDE_ASPECT_RATIO) { - float factor = std::clamp((aspectRatio - NARROW_ASPECT_RATIO) / (STEAM_DECK_ASPECT_RATIO - NARROW_ASPECT_RATIO), 0.0f, 1.0f); - g_scale = 1.0f + factor * (aspectRatio / WIDE_ASPECT_RATIO - 1.0f); + // interpolate to original 4:3 scale + float steamDeckScale = aspectRatio / WIDE_ASPECT_RATIO; + float narrowScale = ComputeScale(NARROW_ASPECT_RATIO); + + float lerpFactor = std::clamp((aspectRatio - NARROW_ASPECT_RATIO) / (STEAM_DECK_ASPECT_RATIO - NARROW_ASPECT_RATIO), 0.0f, 1.0f); + g_scale = narrowScale + (steamDeckScale - narrowScale) * lerpFactor; } } else @@ -210,17 +218,10 @@ static void ComputeOffsets(float width, float height) g_offsetY = 0.5f * (960.0f / aspectRatio - 720.0f); // scale to 16:9 as the aspect ratio becomes 9:16 - float factor = std::clamp((aspectRatio - INV_WIDE_ASPECT_RATIO) / (NARROW_ASPECT_RATIO - INV_WIDE_ASPECT_RATIO), 0.0f, 1.0f); - g_scale = INV_WIDE_SCALE + factor * (1.0f - INV_WIDE_SCALE); + float factor = std::clamp((aspectRatio - TALL_ASPECT_RATIO) / (NARROW_ASPECT_RATIO - TALL_ASPECT_RATIO), 0.0f, 1.0f); + g_scale = TALL_SCALE + factor * (ComputeScale(NARROW_ASPECT_RATIO) - TALL_SCALE); } - // use original 4:3 scaling if requested - if (Config::AspectRatio == EAspectRatio::OriginalNarrow) - { - aspectRatio = std::clamp(aspectRatio, NARROW_ASPECT_RATIO, WIDE_ASPECT_RATIO); - g_scale = ((aspectRatio * 720.0f) / 1280.0f) / sqrt((aspectRatio * 720.0f) / 1280.0f); - } - g_worldMapOffset = std::clamp((aspectRatio - NARROW_ASPECT_RATIO) / (WIDE_ASPECT_RATIO - NARROW_ASPECT_RATIO), 0.0f, 1.0f); }