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.
This commit is contained in:
rogerman 2021-09-09 13:59:25 -07:00
parent d9fabf6347
commit 9f4f3ecf95
1 changed files with 4 additions and 1 deletions

View File

@ -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);
}