From a7bdd1e3a95fb4ccfbb8ad21efcab320447f8f30 Mon Sep 17 00:00:00 2001 From: rogerman Date: Fri, 24 Feb 2023 16:01:14 -0800 Subject: [PATCH] GFX3D: Remove the mistaken addition of color clamping when converting fixed-point vertex colors into floating-point. Fixes the proper coloring of Princess Peach in the opening sequence of Super Mario 64 DS. (Regression from commit 7751b59.) --- desmume/src/gfx3d.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index ffbd7038a..d48af0b71 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -3381,20 +3381,16 @@ size_t gfx3d_PerformClipping(const GFX3D_GeometryList &gList, CPoly *outCPolyUns vtx.texCoord.v = (vtx.texCoord.v << 12) / vtx.position.w; // Vertex color - s32 r_32 = ((s32)vtx.color.r << 24) / vtx.position.w; - s32 g_32 = ((s32)vtx.color.g << 24) / vtx.position.w; - s32 b_32 = ((s32)vtx.color.b << 24) / vtx.position.w; + s32 r_32 = ((s32)vtx.color.r << 23) / vtx.position.w; + s32 g_32 = ((s32)vtx.color.g << 23) / vtx.position.w; + s32 b_32 = ((s32)vtx.color.b << 23) / vtx.position.w; - r_32 = min(max(r_32, 0x00), 0x0003FFFF); - g_32 = min(max(g_32, 0x00), 0x0003FFFF); - b_32 = min(max(b_32, 0x00), 0x0003FFFF); - - vert.rf = (float)r_32 / 4096.0f; - vert.gf = (float)g_32 / 4096.0f; - vert.bf = (float)b_32 / 4096.0f; - vtx.color.r = (u8)vert.rf; - vtx.color.g = (u8)vert.gf; - vtx.color.b = (u8)vert.bf; + vert.rf = (float)r_32 / 2048.0f; + vert.gf = (float)g_32 / 2048.0f; + vert.bf = (float)b_32 / 2048.0f; + vtx.color.r = (u8)(vert.rf + 0.5f); + vtx.color.g = (u8)(vert.gf + 0.5f); + vtx.color.b = (u8)(vert.bf + 0.5f); } else {