Browse Source

engine: common: fixed lightmap shifting caused by insufficent precision in Mod_CalcSurfaceExtents

pull/2/head
SNMetamorph 3 years ago committed by a1batross
parent
commit
24ea8fba4b
  1. 8
      engine/common/mod_bmodel.c
  2. 1
      public/xash3d_mathlib.h

8
engine/common/mod_bmodel.c

@ -1020,8 +1020,8 @@ Fills in surf->texturemins[] and surf->extents[]
*/ */
static void Mod_CalcSurfaceExtents( msurface_t *surf ) static void Mod_CalcSurfaceExtents( msurface_t *surf )
{ {
float mins[2], maxs[2], val; double mins[2], maxs[2], val;
float lmmins[2], lmmaxs[2]; double lmmins[2], lmmaxs[2];
int bmins[2], bmaxs[2]; int bmins[2], bmaxs[2];
int i, j, e, sample_size; int i, j, e, sample_size;
mextrasurf_t *info = surf->info; mextrasurf_t *info = surf->info;
@ -1049,14 +1049,14 @@ static void Mod_CalcSurfaceExtents( msurface_t *surf )
for( j = 0; j < 2; j++ ) for( j = 0; j < 2; j++ )
{ {
val = DotProduct( v->position, surf->texinfo->vecs[j] ) + surf->texinfo->vecs[j][3]; val = DotProductPrecise( v->position, surf->texinfo->vecs[j] ) + surf->texinfo->vecs[j][3];
mins[j] = Q_min( val, mins[j] ); mins[j] = Q_min( val, mins[j] );
maxs[j] = Q_max( val, maxs[j] ); maxs[j] = Q_max( val, maxs[j] );
} }
for( j = 0; j < 2; j++ ) for( j = 0; j < 2; j++ )
{ {
val = DotProduct( v->position, info->lmvecs[j] ) + info->lmvecs[j][3]; val = DotProductPrecise( v->position, info->lmvecs[j] ) + info->lmvecs[j][3];
lmmins[j] = Q_min( val, lmmins[j] ); lmmins[j] = Q_min( val, lmmins[j] );
lmmaxs[j] = Q_max( val, lmmaxs[j] ); lmmaxs[j] = Q_max( val, lmmaxs[j] );
} }

1
public/xash3d_mathlib.h

@ -93,6 +93,7 @@ GNU General Public License for more details.
#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
#define DotProductAbs(x,y) (abs((x)[0]*(y)[0])+abs((x)[1]*(y)[1])+abs((x)[2]*(y)[2])) #define DotProductAbs(x,y) (abs((x)[0]*(y)[0])+abs((x)[1]*(y)[1])+abs((x)[2]*(y)[2]))
#define DotProductFabs(x,y) (fabs((x)[0]*(y)[0])+fabs((x)[1]*(y)[1])+fabs((x)[2]*(y)[2])) #define DotProductFabs(x,y) (fabs((x)[0]*(y)[0])+fabs((x)[1]*(y)[1])+fabs((x)[2]*(y)[2]))
#define DotProductPrecise(x,y) ((double)(x)[0]*(double)(y)[0]+(double)(x)[1]*(double)(y)[1]+(double)(x)[2]*(double)(y)[2])
#define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0]) #define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0])
#define Vector2Subtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1]) #define Vector2Subtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1])
#define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2]) #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])

Loading…
Cancel
Save