From c8cbafff71a81bee5112aaafe6e21d6648ff8125 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sun, 3 May 2020 12:00:06 +0700 Subject: [PATCH] Use the second color section of the Light structure for vertices with odd index (1, 3, ...). Both color sections of the Light structure must store the same color, but it is not so for SM64. Fixed #2212 SM64 koopa's shorts are not correct in hle --- src/gSP.cpp | 27 +++++++++++++++++++++------ src/gSP.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gSP.cpp b/src/gSP.cpp index 150e73d6..263b9c05 100644 --- a/src/gSP.cpp +++ b/src/gSP.cpp @@ -318,6 +318,9 @@ void gSPLight( u32 l, s32 n ) gSP.lights.rgb[n][R] = _FIXED2FLOATCOLOR(light->r,8); gSP.lights.rgb[n][G] = _FIXED2FLOATCOLOR(light->g,8); gSP.lights.rgb[n][B] = _FIXED2FLOATCOLOR(light->b,8); + gSP.lights.rgb2[n][R] = _FIXED2FLOATCOLOR(light->r2, 8); + gSP.lights.rgb2[n][G] = _FIXED2FLOATCOLOR(light->g2, 8); + gSP.lights.rgb2[n][B] = _FIXED2FLOATCOLOR(light->b2, 8); gSP.lights.xyz[n][X] = light->x; gSP.lights.xyz[n][Y] = light->y; @@ -359,6 +362,9 @@ void gSPLightCBFD( u32 l, s32 n ) gSP.lights.rgb[n][R] = _FIXED2FLOATCOLOR(light->r, 8); gSP.lights.rgb[n][G] = _FIXED2FLOATCOLOR(light->g, 8); gSP.lights.rgb[n][B] = _FIXED2FLOATCOLOR(light->b, 8); + gSP.lights.rgb2[n][R] = _FIXED2FLOATCOLOR(light->r2, 8); + gSP.lights.rgb2[n][G] = _FIXED2FLOATCOLOR(light->g2, 8); + gSP.lights.rgb2[n][B] = _FIXED2FLOATCOLOR(light->b2, 8); gSP.lights.xyz[n][X] = light->x; gSP.lights.xyz[n][Y] = light->y; @@ -397,6 +403,9 @@ void gSPLightAcclaim(u32 l, s32 n) gSP.lights.rgb[n][R] = _FIXED2FLOATCOLOR((RDRAM[(addrByte + 6) ^ 3]), 8); gSP.lights.rgb[n][G] = _FIXED2FLOATCOLOR((RDRAM[(addrByte + 7) ^ 3]), 8); gSP.lights.rgb[n][B] = _FIXED2FLOATCOLOR((RDRAM[(addrByte + 8) ^ 3]), 8); + gSP.lights.rgb2[n][R] = gSP.lights.rgb[n][R]; + gSP.lights.rgb2[n][G] = gSP.lights.rgb[n][G]; + gSP.lights.rgb2[n][B] = gSP.lights.rgb[n][B]; } gSP.changed |= CHANGED_LIGHT; @@ -481,17 +490,20 @@ void gSPLightVertexStandard(u32 v, SPVertex * spVtx) if (!isHWLightingAllowed()) { for(int j = 0; j < VNUM; ++j) { SPVertex & vtx = spVtx[v+j]; - vtx.r = gSP.lights.rgb[gSP.numLights][R]; - vtx.g = gSP.lights.rgb[gSP.numLights][G]; - vtx.b = gSP.lights.rgb[gSP.numLights][B]; + const bool useFirstColor = ((v + j) & 1) == 0; + const float* pColor = useFirstColor ? gSP.lights.rgb[gSP.numLights] : gSP.lights.rgb2[gSP.numLights]; + vtx.r = pColor[R]; + vtx.g = pColor[G]; + vtx.b = pColor[B]; vtx.HWLight = 0; for (u32 i = 0; i < gSP.numLights; ++i) { const f32 intensity = DotProduct( &vtx.nx, gSP.lights.i_xyz[i] ); if (intensity > 0.0f) { - vtx.r += gSP.lights.rgb[i][R] * intensity; - vtx.g += gSP.lights.rgb[i][G] * intensity; - vtx.b += gSP.lights.rgb[i][B] * intensity; + pColor = useFirstColor ? gSP.lights.rgb[i] : gSP.lights.rgb2[i]; + vtx.r += pColor[R] * intensity; + vtx.g += pColor[G] * intensity; + vtx.b += pColor[B] * intensity; } } vtx.r = min(1.0f, vtx.r); @@ -1719,6 +1731,9 @@ void gSPLightColor( u32 lightNum, u32 packedColor ) gSP.lights.rgb[lightNum][R] = _FIXED2FLOATCOLOR(_SHIFTR( packedColor, 24, 8 ),8); gSP.lights.rgb[lightNum][G] = _FIXED2FLOATCOLOR(_SHIFTR( packedColor, 16, 8 ),8); gSP.lights.rgb[lightNum][B] = _FIXED2FLOATCOLOR(_SHIFTR( packedColor, 8, 8 ),8); + gSP.lights.rgb2[lightNum][R] = gSP.lights.rgb[lightNum][R]; + gSP.lights.rgb2[lightNum][G] = gSP.lights.rgb[lightNum][G]; + gSP.lights.rgb2[lightNum][B] = gSP.lights.rgb[lightNum][B]; gSP.changed |= CHANGED_HW_LIGHT; } DebugMsg(DEBUG_NORMAL, "gSPLightColor( %i, 0x%08X );\n", lightNum, packedColor ); diff --git a/src/gSP.h b/src/gSP.h index a6687849..5cd8ae48 100644 --- a/src/gSP.h +++ b/src/gSP.h @@ -66,6 +66,7 @@ struct gSPInfo struct { f32 rgb[12][3]; + f32 rgb2[12][3]; f32 xyz[12][3]; f32 i_xyz[12][3]; f32 pos_xyzw[12][4];