From f7ce4f179a7eeb6159d8e179e6ebbc6a191b1e05 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:59:43 +0300 Subject: [PATCH] Fix rope renderable material parameters during rendering. (#214) --- 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 39a9e48..d3ccb58 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); +}