gl_model.c (CalcSurfaceExtents): fix a lighting glitch due to floating point precision. patch from Eric Wasylishen.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@908 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2014-04-28 06:10:12 +00:00
parent 908ecf84a0
commit 5e6683608d

View file

@ -943,10 +943,26 @@ void CalcSurfaceExtents (msurface_t *s)
for (j=0 ; j<2 ; j++)
{
val = v->position[0] * tex->vecs[j][0] +
v->position[1] * tex->vecs[j][1] +
v->position[2] * tex->vecs[j][2] +
tex->vecs[j][3];
/* The following calculation is sensitive to floating-point
* precision. It needs to produce the same result that the
* light compiler does, because R_BuildLightMap uses surf->
* extents to know the width/height of a surface's lightmap,
* and incorrect rounding here manifests itself as patches
* of "corrupted" looking lightmaps.
* Most light compilers are win32 executables, so they use
* x87 floating point. This means the multiplies and adds
* are done at 80-bit precision, and the result is rounded
* down to 32-bits and stored in val.
* Adding the casts to double seems to be good enough to fix
* lighting glitches when Quakespasm is compiled as x86_64
* and using SSE2 floating-point. A potential trouble spot
* is the hallway at the beginning of mfxsp17. -- ericw
*/
val = ((double)v->position[0] * (double)tex->vecs[j][0]) +
((double)v->position[1] * (double)tex->vecs[j][1]) +
((double)v->position[2] * (double)tex->vecs[j][2]) +
(double)tex->vecs[j][3];
if (val < mins[j])
mins[j] = val;
if (val > maxs[j])