From 36def1e4559bea38ae2b29ac0f7d5849b0135989 Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:56:54 +0300 Subject: [PATCH] Fix rope renderable material parameters during rendering. --- UnleashedRecomp/patches/video_patches.cpp | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/UnleashedRecomp/patches/video_patches.cpp b/UnleashedRecomp/patches/video_patches.cpp index 39a9e48d..d3ccb582 100644 --- a/UnleashedRecomp/patches/video_patches.cpp +++ b/UnleashedRecomp/patches/video_patches.cpp @@ -81,3 +81,35 @@ PPC_FUNC(sub_830D25D8) __imp__sub_830D25D8(ctx, base); } + +// Rope renderables sometimes get bogus colors due to the material parameters of whatever +// was rendered last leaking into their render state. We can reset them to fix it. + +static void SetDefaultMaterialParameters(GuestDevice* device) +{ + const be diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; + const be ambient[] = { 1.0f, 1.0f, 1.0f, 0.0f }; + const be specular[] = { 0.9f, 0.9f, 0.9f, 0.0f }; + + memcpy(&device->pixelShaderFloatConstants[64], diffuse, sizeof(diffuse)); // g_Diffuse + memcpy(&device->pixelShaderFloatConstants[68], ambient, sizeof(ambient)); // g_Ambient + memcpy(&device->pixelShaderFloatConstants[72], specular, sizeof(specular)); // g_Specular + + device->dirtyFlags[1] = ~0ull; +} + +// SWA::CRopeRenderable::Render +PPC_FUNC_IMPL(__imp__sub_827CBF68); +PPC_FUNC(sub_827CBF68) +{ + SetDefaultMaterialParameters(reinterpret_cast(base + PPC_LOAD_U32(PPC_LOAD_U32(ctx.r4.u32)))); + __imp__sub_827CBF68(ctx, base); +} + +// SWA::CObjUpReel::CPrimitiveReel::Render +PPC_FUNC_IMPL(__imp__sub_8260BBF8); +PPC_FUNC(sub_8260BBF8) +{ + SetDefaultMaterialParameters(reinterpret_cast(base + PPC_LOAD_U32(PPC_LOAD_U32(ctx.r4.u32)))); + __imp__sub_8260BBF8(ctx, base); +}