fix potential overflow in fog density calculation
This commit is contained in:
parent
a1401e724c
commit
04172f47de
|
@ -1545,15 +1545,19 @@ void ScanlineFinalPass(s32 y)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
z = (z - fogoffset) << fogshift;
|
// technically: Z difference is shifted left by fog shift
|
||||||
densityid = z >> 19;
|
// 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)
|
if (densityid >= 32)
|
||||||
{
|
{
|
||||||
densityid = 32;
|
densityid = 32;
|
||||||
densityfrac = 0;
|
densityfrac = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
densityfrac = z & 0x7FFFF;
|
densityfrac = (z << fogshift) & 0x7FFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkme
|
// checkme
|
||||||
|
|
Loading…
Reference in New Issue