Implement proper post process scaling based on aspect ratio. (#148)

* Fix post process scaling for narrow aspect ratios.

* Compare width to pick gaussian blur quality for narrow aspect ratios.

* Account for world map disabling VERT+ for post process scaling.
This commit is contained in:
Skyth (Asilkan) 2025-01-22 19:14:40 +03:00 committed by GitHub
parent 85b5ebf9a7
commit 4e149b0640
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4351,6 +4351,8 @@ static void ProcSetPixelShader(const RenderCommand& cmd)
break;
default:
{
if (g_aspectRatio >= WIDE_ASPECT_RATIO)
{
size_t height = round(Video::s_viewportHeight * Config::ResolutionScale);
@ -4362,6 +4364,21 @@ static void ProcSetPixelShader(const RenderCommand& cmd)
shaderIndex = GAUSSIAN_BLUR_5X5;
else
shaderIndex = GAUSSIAN_BLUR_3X3;
}
else
{
// Narrow aspect ratios should check for width to account for VERT+.
size_t width = round(Video::s_viewportWidth * Config::ResolutionScale);
if (width > 2560)
shaderIndex = GAUSSIAN_BLUR_9X9;
else if (width > 1920)
shaderIndex = GAUSSIAN_BLUR_7X7;
else if (width > 1280)
shaderIndex = GAUSSIAN_BLUR_5X5;
else
shaderIndex = GAUSSIAN_BLUR_3X3;
}
break;
}
@ -5089,23 +5106,40 @@ PPC_FUNC(sub_8258CAE0)
g_renderDirectorProfiler.End();
}
// World map disables VERT+, so scaling by width does not work for it.
static uint32_t g_forceCheckHeightForPostProcessFix;
// SWA::CWorldMapCamera::CWorldMapCamera
PPC_FUNC_IMPL(__imp__sub_824860E0);
PPC_FUNC(sub_824860E0)
{
++g_forceCheckHeightForPostProcessFix;
__imp__sub_824860E0(ctx, base);
}
// SWA::CCameraController::~CCameraController
PPC_FUNC_IMPL(__imp__sub_824831D0);
PPC_FUNC(sub_824831D0)
{
if (PPC_LOAD_U32(ctx.r3.u32) == 0x8202BF1C) // SWA::CWorldMapCamera
--g_forceCheckHeightForPostProcessFix;
__imp__sub_824831D0(ctx, base);
}
void PostProcessResolutionFix(PPCRegister& r4, PPCRegister& f1, PPCRegister& f2)
{
auto device = reinterpret_cast<be<uint32_t>*>(g_memory.Translate(r4.u32));
uint32_t width = device[46].get();
uint32_t height = device[47].get();
double aspectRatio = double(width) / double(height);
#if 0
// TODO: Figure out why this breaks for height > weight
double factor;
if (width > height)
if ((aspectRatio >= WIDE_ASPECT_RATIO) || (g_forceCheckHeightForPostProcessFix != 0))
factor = 720.0 / double(height);
else
factor = 1280.0 / double(width);
#else
double factor = 720.0 / double(height);
#endif
f1.f64 *= factor;
f2.f64 *= factor;