Keep UI scale same only above Steam Deck aspect ratio.

This commit is contained in:
Skyth 2025-01-06 00:47:58 +03:00
parent 6a709a358d
commit f29fc5e593
4 changed files with 27 additions and 23 deletions

View file

@ -188,7 +188,8 @@ CONFIG_DEFINE_ENUM_LOCALE(EAspectRatio)
{ {
ELanguage::English, 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", "" } }
} }
} }
}; };

View file

@ -20,7 +20,7 @@ void CameraFieldOfViewMidAsmHook(PPCRegister& r31, PPCRegister& f31)
auto camera = (SWA::CCamera*)g_memory.Translate(r31.u32); auto camera = (SWA::CCamera*)g_memory.Translate(r31.u32);
// Replicate the original incorrect field of view formula if requested. // 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) if (abs(camera->m_HorzAspectRatio - ORIGINAL_ASPECT_RATIO) < 0.001f)
{ {

View file

@ -152,11 +152,11 @@ void MakeCsdProjectMidAsmHook(PPCRegister& r3, PPCRegister& r29)
TraverseSceneNode(csdProject->m_pResource->pRootNode, name); TraverseSceneNode(csdProject->m_pResource->pRootNode, name);
} }
static constexpr float ORIGINAL_ASPECT_RATIO = 4.0f / 3.0f; static constexpr float NARROW_ASPECT_RATIO = 4.0f / 3.0f;
static constexpr float ORIGINAL_WIDESCREEN_ASPECT_RATIO = 16.0f / 9.0f; static constexpr float WIDE_ASPECT_RATIO = 16.0f / 9.0f;
static constexpr float INV_WIDESCREEN_ASPECT_RATIO = 1.0f / ORIGINAL_WIDESCREEN_ASPECT_RATIO; static constexpr float STEAM_DECK_ASPECT_RATIO = 16.0f / 10.0f;
static constexpr float INV_WIDESCREEN_SCALE = 1280.0f / 960.0f; static constexpr float INV_WIDE_ASPECT_RATIO = 1.0f / WIDE_ASPECT_RATIO;
static constexpr float SQUARE_SCALE = 960.0f / 1280.0f; static constexpr float INV_WIDE_SCALE = 1280.0f / 960.0f;
static float g_offsetX; static float g_offsetX;
static float g_offsetY; static float g_offsetY;
@ -169,16 +169,19 @@ static void ComputeOffsets(float width, float height)
float aspectRatio = width / height; float aspectRatio = width / height;
g_scale = 1.0f; g_scale = 1.0f;
if (aspectRatio >= ORIGINAL_ASPECT_RATIO) if (aspectRatio >= NARROW_ASPECT_RATIO)
{ {
// height is locked to 720 in this case // height is locked to 720 in this case
g_offsetX = 0.5f * (aspectRatio * 720.0f - 1280.0f); g_offsetX = 0.5f * (aspectRatio * 720.0f - 1280.0f);
g_offsetY = 0.0f; g_offsetY = 0.0f;
// narrow resolutions will zoom the UI in, but we // narrow resolutions will zoom the UI in, but we want the gameplay
// want the gameplay UI to retain the same scale // UI to retain the same scale at Steam Deck's aspect ratio
if (aspectRatio < ORIGINAL_WIDESCREEN_ASPECT_RATIO) if (aspectRatio < WIDE_ASPECT_RATIO)
g_scale = aspectRatio / ORIGINAL_WIDESCREEN_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 else
{ {
@ -187,18 +190,18 @@ static void ComputeOffsets(float width, float height)
g_offsetY = 0.5f * (960.0f / aspectRatio - 720.0f); g_offsetY = 0.5f * (960.0f / aspectRatio - 720.0f);
// scale to 16:9 as the aspect ratio becomes 9:16 // 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); float factor = std::clamp((aspectRatio - INV_WIDE_ASPECT_RATIO) / (NARROW_ASPECT_RATIO - INV_WIDE_ASPECT_RATIO), 0.0f, 1.0f);
g_scale = INV_WIDESCREEN_SCALE + factor * (SQUARE_SCALE - INV_WIDESCREEN_SCALE); g_scale = INV_WIDE_SCALE + factor * (1.0f - INV_WIDE_SCALE);
} }
// use original 4:3 scaling if requested // 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_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 static class SDLEventListenerForCSD : public SDLEventListener

View file

@ -148,17 +148,17 @@ CONFIG_DEFINE_ENUM_TEMPLATE(EWindowState)
enum class EAspectRatio : uint32_t enum class EAspectRatio : uint32_t
{ {
Auto, Auto,
Widescreen, Wide,
Square, Narrow,
OriginalSquare OriginalNarrow
}; };
CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio) CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio)
{ {
{ "Auto", EAspectRatio::Auto }, { "Auto", EAspectRatio::Auto },
{ "16:9", EAspectRatio::Widescreen }, { "16:9", EAspectRatio::Wide },
{ "4:3", EAspectRatio::Square }, { "4:3", EAspectRatio::Narrow },
{ "Original 4:3", EAspectRatio::OriginalSquare }, { "Original 4:3", EAspectRatio::OriginalNarrow },
}; };
enum class ETripleBuffering : uint32_t enum class ETripleBuffering : uint32_t