mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
fix potential overflow in fog density calculation
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user