From 9f4f3ecf95e3fc8714d4af166a994df0719a830f Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 9 Sep 2021 13:59:25 -0700 Subject: [PATCH] GFX3D: Oops, I misread GBATEK. It actually meant that the Fog Step (not the Fog Shift) would become zero if Fog Shift was greater than 10. So set Fog Shift to 11 in this case. - This also discovers an existing issue with the fog weight calculation code in both OpenGL and SoftRasterizer, since Fog Shift could be zero and thereby cause the calculations to divide by zero. This issue will have to be dealt with at a later time. --- desmume/src/gfx3d.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index d6166372b..019b41063 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -3093,7 +3093,10 @@ void gfx3d_parseCurrentDISP3DCNT() gfx3d.state.enableEdgeMarking = (DISP3DCNT.EnableEdgeMarking != 0); gfx3d.state.enableFogAlphaOnly = (DISP3DCNT.FogOnlyAlpha != 0); gfx3d.state.enableFog = (DISP3DCNT.EnableFog != 0); - gfx3d.state.fogShift = (DISP3DCNT.FogShiftSHR <= 10) ? DISP3DCNT.FogShiftSHR : 0; // According to GBATEK, values higher than 10 are reset to 0. + gfx3d.state.fogShift = (DISP3DCNT.FogShiftSHR <= 10) ? DISP3DCNT.FogShiftSHR : 11; // According to GBATEK, values higher than 10 force FogStep (0x400 >> FogShiftSHR) to become 0. So set FogShiftSHR to 11 in this case. + // TODO: Handle divide-by-zero cases of FogShiftSHR in SoftRasterizer and OpenGL. + // The fog weight is calculated using FogShiftSHR. However, if FogShiftSHR == 0, then this calculation can become a problem. + // We'll need to deal with the zero case at some point in the future. gfx3d.state.enableClearImage = (DISP3DCNT.RearPlaneMode != 0); }