From f29fc5e593f3498051187f922b29ab1203fee613 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 6 Jan 2025 00:47:58 +0300 Subject: [PATCH] Keep UI scale same only above Steam Deck aspect ratio. --- UnleashedRecomp/locale/config_locale.cpp | 3 +- UnleashedRecomp/patches/camera_patches.cpp | 2 +- UnleashedRecomp/patches/csd_patches.cpp | 33 ++++++++++++---------- UnleashedRecomp/user/config.h | 12 ++++---- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/UnleashedRecomp/locale/config_locale.cpp b/UnleashedRecomp/locale/config_locale.cpp index 2815443d..03a3699b 100644 --- a/UnleashedRecomp/locale/config_locale.cpp +++ b/UnleashedRecomp/locale/config_locale.cpp @@ -188,7 +188,8 @@ CONFIG_DEFINE_ENUM_LOCALE(EAspectRatio) { ELanguage::English, { - { EAspectRatio::Auto, { "AUTO", "Auto: the aspect ratio will dynamically adjust to the window size." } } + { EAspectRatio::Auto, { "AUTO", "Auto: the aspect ratio will dynamically adjust to the window size." } }, + { EAspectRatio::OriginalNarrow, { "ORIGINAL 4:3", "" } } } } }; diff --git a/UnleashedRecomp/patches/camera_patches.cpp b/UnleashedRecomp/patches/camera_patches.cpp index 2351fe66..a88b5037 100644 --- a/UnleashedRecomp/patches/camera_patches.cpp +++ b/UnleashedRecomp/patches/camera_patches.cpp @@ -20,7 +20,7 @@ void CameraFieldOfViewMidAsmHook(PPCRegister& r31, PPCRegister& f31) auto camera = (SWA::CCamera*)g_memory.Translate(r31.u32); // Replicate the original incorrect field of view formula if requested. - if (Config::AspectRatio == EAspectRatio::OriginalSquare) + if (Config::AspectRatio == EAspectRatio::OriginalNarrow) { if (abs(camera->m_HorzAspectRatio - ORIGINAL_ASPECT_RATIO) < 0.001f) { diff --git a/UnleashedRecomp/patches/csd_patches.cpp b/UnleashedRecomp/patches/csd_patches.cpp index dc15b584..1aca5f1e 100644 --- a/UnleashedRecomp/patches/csd_patches.cpp +++ b/UnleashedRecomp/patches/csd_patches.cpp @@ -152,11 +152,11 @@ void MakeCsdProjectMidAsmHook(PPCRegister& r3, PPCRegister& r29) TraverseSceneNode(csdProject->m_pResource->pRootNode, name); } -static constexpr float ORIGINAL_ASPECT_RATIO = 4.0f / 3.0f; -static constexpr float ORIGINAL_WIDESCREEN_ASPECT_RATIO = 16.0f / 9.0f; -static constexpr float INV_WIDESCREEN_ASPECT_RATIO = 1.0f / ORIGINAL_WIDESCREEN_ASPECT_RATIO; -static constexpr float INV_WIDESCREEN_SCALE = 1280.0f / 960.0f; -static constexpr float SQUARE_SCALE = 960.0f / 1280.0f; +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 float g_offsetX; static float g_offsetY; @@ -169,16 +169,19 @@ static void ComputeOffsets(float width, float height) float aspectRatio = width / height; g_scale = 1.0f; - if (aspectRatio >= ORIGINAL_ASPECT_RATIO) + if (aspectRatio >= NARROW_ASPECT_RATIO) { // height is locked to 720 in this case 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 - if (aspectRatio < ORIGINAL_WIDESCREEN_ASPECT_RATIO) - g_scale = aspectRatio / ORIGINAL_WIDESCREEN_ASPECT_RATIO; + // narrow resolutions will zoom the UI in, but we want the gameplay + // UI to retain the same scale at Steam Deck's 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); + } } else { @@ -187,18 +190,18 @@ 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_WIDESCREEN_ASPECT_RATIO) / (ORIGINAL_ASPECT_RATIO - INV_WIDESCREEN_ASPECT_RATIO), 0.0f, 1.0f); - g_scale = INV_WIDESCREEN_SCALE + factor * (SQUARE_SCALE - INV_WIDESCREEN_SCALE); + 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); } // use original 4:3 scaling if requested - if (Config::AspectRatio == EAspectRatio::OriginalSquare) + if (Config::AspectRatio == EAspectRatio::OriginalNarrow) { - aspectRatio = std::clamp(aspectRatio, ORIGINAL_ASPECT_RATIO, ORIGINAL_WIDESCREEN_ASPECT_RATIO); + 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 - ORIGINAL_ASPECT_RATIO) / (ORIGINAL_WIDESCREEN_ASPECT_RATIO - ORIGINAL_ASPECT_RATIO), 0.0f, 1.0f); + g_worldMapOffset = std::clamp((aspectRatio - NARROW_ASPECT_RATIO) / (WIDE_ASPECT_RATIO - NARROW_ASPECT_RATIO), 0.0f, 1.0f); } static class SDLEventListenerForCSD : public SDLEventListener diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index f3785112..873f3d42 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -148,17 +148,17 @@ CONFIG_DEFINE_ENUM_TEMPLATE(EWindowState) enum class EAspectRatio : uint32_t { Auto, - Widescreen, - Square, - OriginalSquare + Wide, + Narrow, + OriginalNarrow }; CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio) { { "Auto", EAspectRatio::Auto }, - { "16:9", EAspectRatio::Widescreen }, - { "4:3", EAspectRatio::Square }, - { "Original 4:3", EAspectRatio::OriginalSquare }, + { "16:9", EAspectRatio::Wide }, + { "4:3", EAspectRatio::Narrow }, + { "Original 4:3", EAspectRatio::OriginalNarrow }, }; enum class ETripleBuffering : uint32_t