fix potential overflow in fog density calculation

This commit is contained in:
StapleButter 2017-07-14 00:12:35 +02:00
parent a1401e724c
commit 04172f47de
1 changed files with 7 additions and 3 deletions

View File

@ -1545,15 +1545,19 @@ void ScanlineFinalPass(s32 y)
}
else
{
z = (z - fogoffset) << fogshift;
densityid = z >> 19;
// technically: Z difference is shifted left by fog shift
// then bit 0-18 are the fractional part and bit 19-23 are the density index
// things are a little different here to avoid overflow in 32-bit range
z -= fogoffset;
densityid = z >> (19-fogshift);
if (densityid >= 32)
{
densityid = 32;
densityfrac = 0;
}
else
densityfrac = z & 0x7FFFF;
densityfrac = (z << fogshift) & 0x7FFFF;
}
// checkme