light: Increase precision of lightmap extents calculations

This bug is a counterpart to this bug in quakespasm:
   https://sourceforge.net/p/quakespasm/patches/15/

If the precision of the calculation in WorldToTexCoord done by ‘light’
is significantly different than the precision of the same calculation
in the engine, you can get corrupted lightmaps. The problem affects
light when it’s built as something other than vanilla 32-bit
x86. (e.g. x86_64 on a mac).

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Eric Wasylishen 2014-06-30 12:58:30 +09:30 committed by Kevin Shanahan
parent 90aa616866
commit 4df394f9fe
1 changed files with 19 additions and 3 deletions

View File

@ -310,11 +310,27 @@ WorldToTexCoord(const vec3_t world, const texinfo_t *tex, vec_t coord[2])
{
int i;
/*
* The (long double) casts below are important: The original code
* was written for x87 floating-point which uses 80-bit floats for
* intermediate calculations. But if you compile it without the
* casts for modern x86_64, the compiler will round each
* intermediate result to a 32-bit float, which introduces extra
* rounding error.
*
* This becomes a problem if the rounding error causes the light
* utilities and the engine to disagree about the lightmap size
* for some surfaces.
*
* Casting to (long double) keeps the intermediate values at at
* least 64 bits of precision, probably 128.
*/
for (i = 0; i < 2; i++)
coord[i] =
world[0] * tex->vecs[i][0] +
world[1] * tex->vecs[i][1] +
world[2] * tex->vecs[i][2] + tex->vecs[i][3];
(long double)world[0] * tex->vecs[i][0] +
(long double)world[1] * tex->vecs[i][1] +
(long double)world[2] * tex->vecs[i][2] +
tex->vecs[i][3];
}
#if 0