mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
Quicky hack at DECOUPLED_LM support.
This commit is contained in:
parent
ecf20de618
commit
528824e507
6 changed files with 126 additions and 85 deletions
|
@ -287,6 +287,13 @@ typedef struct
|
|||
int lightofs; // start of [numstyles*surfsize] samples
|
||||
} dlface_t;
|
||||
|
||||
struct decoupled_lm_info_s
|
||||
{
|
||||
unsigned short lmsize[2]; //made explicit. beware MAX_
|
||||
unsigned int lmoffset; //replacement offset for vanilla compat.
|
||||
vec4_t lmvecs[2]; //lmcoord[] = dotproduct3(vertexcoord, lmvecs[])+lmvecs[][3]
|
||||
};
|
||||
|
||||
#define AMBIENT_WATER 0
|
||||
#define AMBIENT_SKY 1
|
||||
#define AMBIENT_SLIME 2
|
||||
|
|
|
@ -43,6 +43,7 @@ static void Mod_Print (void);
|
|||
static cvar_t external_ents = {"external_ents", "1", CVAR_ARCHIVE};
|
||||
cvar_t gl_load24bit = {"gl_load24bit", "1", CVAR_ARCHIVE};
|
||||
static cvar_t mod_ignorelmscale = {"mod_ignorelmscale", "0"};
|
||||
static cvar_t mod_lightscale_broken = {"mod_lightscale_broken", "1"}; //match vanilla's brokenness bug with dlights and scaled textures. decoupled_lm bypasses this obviously buggy setting because zomgletmefixstuffffs
|
||||
cvar_t r_replacemodels = {"r_replacemodels", "", CVAR_ARCHIVE};
|
||||
static cvar_t external_vis = {"external_vis", "1", CVAR_ARCHIVE};
|
||||
|
||||
|
@ -72,6 +73,7 @@ void Mod_Init (void)
|
|||
Cvar_RegisterVariable (&gl_load24bit);
|
||||
Cvar_RegisterVariable (&r_replacemodels);
|
||||
Cvar_RegisterVariable (&mod_ignorelmscale);
|
||||
Cvar_RegisterVariable (&mod_lightscale_broken);
|
||||
|
||||
Cmd_AddCommand ("mcache", Mod_Print);
|
||||
|
||||
|
@ -1433,14 +1435,14 @@ CalcSurfaceExtents
|
|||
Fills in s->texturemins[] and s->extents[]
|
||||
================
|
||||
*/
|
||||
static void CalcSurfaceExtents (msurface_t *s)
|
||||
static void CalcSurfaceExtents (msurface_t *s, int lmshift)
|
||||
{
|
||||
float mins[2], maxs[2], val;
|
||||
int i,j, e;
|
||||
mvertex_t *v;
|
||||
mtexinfo_t *tex;
|
||||
int bmins[2], bmaxs[2];
|
||||
int maxextent, lmscale;
|
||||
int lmscale;
|
||||
|
||||
mins[0] = mins[1] = FLT_MAX;
|
||||
maxs[0] = maxs[1] = -FLT_MAX;
|
||||
|
@ -1484,18 +1486,24 @@ static void CalcSurfaceExtents (msurface_t *s)
|
|||
}
|
||||
}
|
||||
|
||||
lmscale = 1<<s->lmshift;
|
||||
maxextent = q_max(LMBLOCK_WIDTH,LMBLOCK_HEIGHT)*lmscale;
|
||||
lmscale = 1<<lmshift;
|
||||
|
||||
for (i=0 ; i<2 ; i++)
|
||||
{
|
||||
bmins[i] = floor(mins[i]/lmscale);
|
||||
bmaxs[i] = ceil(maxs[i]/lmscale);
|
||||
|
||||
s->texturemins[i] = bmins[i] * lmscale;
|
||||
s->extents[i] = (bmaxs[i] - bmins[i]) * lmscale;
|
||||
s->lmvecs[i][0] = s->texinfo->vecs[i][0] / lmscale;
|
||||
s->lmvecs[i][1] = s->texinfo->vecs[i][1] / lmscale;
|
||||
s->lmvecs[i][2] = s->texinfo->vecs[i][2] / lmscale;
|
||||
s->lmvecs[i][3] = s->texinfo->vecs[i][3] / lmscale + 0.5/*sigh*/ - bmins[i];
|
||||
if (mod_lightscale_broken.value)
|
||||
s->lmvecscale[i] = 16; //luxels->qu... except buggy so dlights have the wrong spread on large surfaces (blame shib7)
|
||||
else
|
||||
s->lmvecscale[i] = 1.0f/VectorLength(s->lmvecs[i]); //luxels->qu
|
||||
s->extents[i] = bmaxs[i] - bmins[i];
|
||||
|
||||
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > maxextent) //johnfitz -- was 512 in glquake, 256 in winquake
|
||||
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] >= (i?LMBLOCK_HEIGHT:LMBLOCK_WIDTH)) //johnfitz -- was 512 in glquake, 256 in winquake
|
||||
{
|
||||
s->extents[i] = 1;
|
||||
// Sys_Error ("Bad surface extents");
|
||||
|
@ -1560,6 +1568,7 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
|
|||
int lumpsize;
|
||||
char scalebuf[16];
|
||||
int facestyles;
|
||||
struct decoupled_lm_info_s *decoupledlm = NULL;
|
||||
|
||||
if (bsp2)
|
||||
{
|
||||
|
@ -1586,12 +1595,38 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
|
|||
|
||||
if (!mod_ignorelmscale.value)
|
||||
{
|
||||
decoupledlm = Q1BSPX_FindLump("DECOUPLED_LM", &lumpsize); //RGB packed data
|
||||
if (decoupledlm && lumpsize == count*sizeof(*decoupledlm))
|
||||
{ //basically stomps over the lmshift+lmoffset stuff above. lmstyle/lmstyle16+lit/hdr+lux info is still needed
|
||||
lmshift = NULL;
|
||||
lmoffset = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
decoupledlm = NULL;
|
||||
|
||||
lmshift = Q1BSPX_FindLump("LMSHIFT", &lumpsize);
|
||||
if (lumpsize != sizeof(*lmshift)*count)
|
||||
lmshift = NULL;
|
||||
lmoffset = Q1BSPX_FindLump("LMOFFSET", &lumpsize);
|
||||
if (lumpsize != sizeof(*lmoffset)*count)
|
||||
lmoffset = NULL;
|
||||
|
||||
if (Mod_ParseWorldspawnKey(loadmodel, "lightmap_scale", scalebuf, sizeof(scalebuf)))
|
||||
{
|
||||
char *e;
|
||||
i = strtol(scalebuf, &e, 10);
|
||||
if (i < 0 || *e)
|
||||
Con_Warning("Incorrect value for lightmap_scale field - %s - should be texels-per-luxel (and power-of-two), use 16 (or omit) to match vanilla quake.\n", scalebuf);
|
||||
else if (i == 0)
|
||||
; //silently use default when its explicitly set to 0 or empty. a bogus value but oh well.
|
||||
else
|
||||
{
|
||||
for(defaultshift = 0; i > 1; defaultshift++)
|
||||
i >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
lmstyle16 = Q1BSPX_FindLump("LMSTYLE16", &lumpsize);
|
||||
stylesperface = lumpsize/(sizeof(*lmstyle16)*count);
|
||||
if (lumpsize != sizeof(*lmstyle16)*stylesperface*count)
|
||||
|
@ -1603,21 +1638,6 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
|
|||
if (lumpsize != sizeof(*lmstyle8)*stylesperface*count)
|
||||
lmstyle8 = NULL;
|
||||
}
|
||||
|
||||
if (Mod_ParseWorldspawnKey(loadmodel, "lightmap_scale", scalebuf, sizeof(scalebuf)))
|
||||
{
|
||||
char *e;
|
||||
i = strtol(scalebuf, &e, 10);
|
||||
if (i < 0 || *e)
|
||||
Con_Warning("Incorrect value for lightmap_scale field - %s - should be texels-per-luxel (and power-of-two), use 16 to match vanilla quake.\n", scalebuf);
|
||||
else if (i == 0)
|
||||
; //silently use default when its explicitly set to 0 or empty. a bogus value but oh well.
|
||||
else
|
||||
{
|
||||
for(defaultshift = 0; i > 1; defaultshift++)
|
||||
i >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadmodel->surfaces = out;
|
||||
|
@ -1675,9 +1695,33 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
|
|||
|
||||
out->plane = loadmodel->planes + planenum;
|
||||
out->texinfo = loadmodel->texinfo + texinfon;
|
||||
out->lmshift = shift;
|
||||
|
||||
CalcSurfaceExtents (out);
|
||||
if (decoupledlm)
|
||||
{
|
||||
lofs = LittleLong(decoupledlm->lmoffset);
|
||||
out->extents[0] = (unsigned short)LittleShort(decoupledlm->lmsize[0]) - 1;
|
||||
out->extents[1] = (unsigned short)LittleShort(decoupledlm->lmsize[1]) - 1;
|
||||
out->lmvecs[0][0] = LittleFloat(decoupledlm->lmvecs[0][0]);
|
||||
out->lmvecs[0][1] = LittleFloat(decoupledlm->lmvecs[0][1]);
|
||||
out->lmvecs[0][2] = LittleFloat(decoupledlm->lmvecs[0][2]);
|
||||
out->lmvecs[0][3] = LittleFloat(decoupledlm->lmvecs[0][3]) + 0.5f; //sigh
|
||||
out->lmvecs[1][0] = LittleFloat(decoupledlm->lmvecs[1][0]);
|
||||
out->lmvecs[1][1] = LittleFloat(decoupledlm->lmvecs[1][1]);
|
||||
out->lmvecs[1][2] = LittleFloat(decoupledlm->lmvecs[1][2]);
|
||||
out->lmvecs[1][3] = LittleFloat(decoupledlm->lmvecs[1][3]) + 0.5f; //sigh
|
||||
out->lmvecscale[0] = 1.0f/VectorLength(out->lmvecs[0]); //luxels->qu
|
||||
out->lmvecscale[1] = 1.0f/VectorLength(out->lmvecs[1]);
|
||||
decoupledlm++;
|
||||
|
||||
//make sure we don't segfault even if the texture coords get crappified.
|
||||
if (out->extents[0] >= LMBLOCK_WIDTH || out->extents[1] >= LMBLOCK_HEIGHT)
|
||||
{
|
||||
Con_Warning("%s: Bad surface extents (%i*%i, max %i*%u).\n", scalebuf, out->extents[0], out->extents[1], LMBLOCK_WIDTH, LMBLOCK_HEIGHT);
|
||||
out->extents[0] = out->extents[1] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
CalcSurfaceExtents (out, shift);
|
||||
|
||||
Mod_CalcSurfaceBounds (out); //johnfitz -- for per-surface frustum culling
|
||||
|
||||
|
@ -1689,7 +1733,7 @@ static void Mod_LoadFaces (lump_t *l, qboolean bsp2)
|
|||
; //count the styles so we can bound-check properly.
|
||||
if (lofs == -1)
|
||||
out->samples = NULL;
|
||||
else if (lofs+facestyles*((out->extents[0]>>out->lmshift)+1)*((out->extents[1]>>out->lmshift)+1) > loadmodel->lightdatasamples)
|
||||
else if (lofs+facestyles*((out->extents[0])+1)*((out->extents[1])+1) > loadmodel->lightdatasamples)
|
||||
out->samples = NULL; //corrupt...
|
||||
else if (loadmodel->flags & MOD_HDRLIGHTING)
|
||||
out->samples = loadmodel->lightdata + (lofs * 4); //spike -- hdr lighting data is 4-aligned
|
||||
|
|
|
@ -139,11 +139,12 @@ typedef struct msurface_s
|
|||
int firstedge; // look up in model->surfedges[], negative numbers
|
||||
int numedges; // are backwards edges
|
||||
|
||||
short texturemins[2];
|
||||
short extents[2];
|
||||
|
||||
vec4_t lmvecs[2];
|
||||
float lmvecscale[2]; //so dlights spread the correct distance despite texture scaling.
|
||||
|
||||
int light_s, light_t; // gl lightmap coordinates
|
||||
unsigned char lmshift;
|
||||
|
||||
glpoly_t *polys; // multiple if warped
|
||||
struct msurface_s *texturechain;
|
||||
|
|
|
@ -238,11 +238,11 @@ start:
|
|||
for (j=0 ; j<3 ; j++)
|
||||
impact[j] = lightorg[j] - surf->plane->normal[j]*dist;
|
||||
// clamp center of light to corner and check brightness
|
||||
l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
|
||||
s = l+0.5;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0];
|
||||
l = DotProduct (impact, surf->lmvecs[0]) + surf->lmvecs[0][3];
|
||||
s = l;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0];
|
||||
s = l - s;
|
||||
l = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
|
||||
t = l+0.5;if (t < 0) t = 0;else if (t > surf->extents[1]) t = surf->extents[1];
|
||||
l = DotProduct (impact, surf->lmvecs[1]) + surf->lmvecs[1][3];
|
||||
t = l;if (t < 0) t = 0;else if (t > surf->extents[1]) t = surf->extents[1];
|
||||
t = l - t;
|
||||
// compare to minimum light
|
||||
if ((s*s+t*t+dist*dist) < maxdist)
|
||||
|
@ -359,6 +359,7 @@ loc0:
|
|||
{
|
||||
float sfront, sback, dist;
|
||||
vec3_t raydelta;
|
||||
double dsfrac, dtfrac;
|
||||
|
||||
if (surf->flags & SURF_DRAWTILED)
|
||||
continue; // no lightmaps
|
||||
|
@ -366,17 +367,17 @@ loc0:
|
|||
// ericw -- added double casts to force 64-bit precision.
|
||||
// Without them the zombie at the start of jam3_ericw.bsp was
|
||||
// incorrectly being lit up in SSE builds.
|
||||
ds = (int) ((double) DoublePrecisionDotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
|
||||
dt = (int) ((double) DoublePrecisionDotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
|
||||
|
||||
if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
|
||||
dsfrac = DoublePrecisionDotProduct (mid, surf->lmvecs[0]) + surf->lmvecs[0][3];
|
||||
dtfrac = DoublePrecisionDotProduct (mid, surf->lmvecs[1]) + surf->lmvecs[1][3];
|
||||
if (dsfrac < 0 || dtfrac < 0)
|
||||
continue;
|
||||
|
||||
ds -= surf->texturemins[0];
|
||||
dt -= surf->texturemins[1];
|
||||
|
||||
if (ds > surf->extents[0] || dt > surf->extents[1])
|
||||
if (dsfrac > surf->extents[0] || dtfrac > surf->extents[1])
|
||||
continue;
|
||||
ds = dsfrac;
|
||||
dt = dtfrac;
|
||||
dsfrac -= ds;
|
||||
dtfrac -= dt;
|
||||
|
||||
if (surf->plane->type < 3)
|
||||
{
|
||||
|
@ -406,7 +407,7 @@ loc0:
|
|||
if (dist < *maxdist)
|
||||
{
|
||||
// LordHavoc: enhanced to interpolate lighting
|
||||
int maps, line3, dsfrac = ds & 15, dtfrac = dt & 15, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
|
||||
int maps, line3, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
|
||||
float scale, e;
|
||||
|
||||
if (cl.worldmodel->flags & MOD_HDRLIGHTING)
|
||||
|
@ -418,8 +419,8 @@ loc0:
|
|||
1.0/(1<<8), 1.0/(1<<7), 1.0/(1<<6), 1.0/(1<<5), 1.0/(1<<4), 1.0/(1<<3), 1.0/(1<<2), 1.0/(1<<1),
|
||||
1.0, 1.0*(1<<1), 1.0*(1<<2), 1.0*(1<<3), 1.0*(1<<4), 1.0*(1<<5), 1.0*(1<<6), 1.0*(1<<7),
|
||||
};
|
||||
uint32_t *lightmap = (uint32_t*)surf->samples + ((dt>>surf->lmshift) * ((surf->extents[0]>>surf->lmshift)+1) + (ds>>surf->lmshift));
|
||||
line3 = ((surf->extents[0]>>surf->lmshift)+1);
|
||||
uint32_t *lightmap = (uint32_t*)surf->samples + (dt * (surf->extents[0]+1) + ds);
|
||||
line3 = (surf->extents[0]+1);
|
||||
for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != INVALID_LIGHTSTYLE;maps++)
|
||||
{
|
||||
scale = (1<<7) * (float) d_lightstylevalue[surf->styles[maps]] * 1.0f / 256.0f;
|
||||
|
@ -427,13 +428,13 @@ loc0:
|
|||
e = rgb9e5tab[lightmap[ 1]>>27] * scale;r01 += ((lightmap[ 1]>> 0)&0x1ff) * e;g01 += ((lightmap[ 1]>> 9)&0x1ff) * e;b01 += ((lightmap[ 1]>> 9)&0x1ff) * e;
|
||||
e = rgb9e5tab[lightmap[line3+0]>>27] * scale;r10 += ((lightmap[line3+0]>> 0)&0x1ff) * e;g10 += ((lightmap[line3+0]>> 9)&0x1ff) * e;b10 += ((lightmap[line3+0]>> 9)&0x1ff) * e;
|
||||
e = rgb9e5tab[lightmap[line3+1]>>27] * scale;r11 += ((lightmap[line3+1]>> 0)&0x1ff) * e;g11 += ((lightmap[line3+1]>> 9)&0x1ff) * e;b11 += ((lightmap[line3+1]>> 9)&0x1ff) * e;
|
||||
lightmap += ((surf->extents[0]>>surf->lmshift)+1) * ((surf->extents[1]>>surf->lmshift)+1);
|
||||
lightmap += (surf->extents[0]+1) * (surf->extents[1]+1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
byte *lightmap = (byte*)surf->samples + ((dt>>surf->lmshift) * ((surf->extents[0]>>surf->lmshift)+1) + (ds>>surf->lmshift))*3; // LordHavoc: *3 for color
|
||||
line3 = ((surf->extents[0]>>surf->lmshift)+1)*3;
|
||||
byte *lightmap = (byte*)surf->samples + (dt * (surf->extents[0]+1) + ds)*3; // LordHavoc: *3 for color
|
||||
line3 = (surf->extents[0]+1)*3;
|
||||
for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != INVALID_LIGHTSTYLE;maps++)
|
||||
{
|
||||
scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0f / 256.0f;
|
||||
|
@ -441,13 +442,13 @@ loc0:
|
|||
r01 += (float) lightmap[ 3] * scale;g01 += (float) lightmap[ 4] * scale;b01 += (float) lightmap[5] * scale;
|
||||
r10 += (float) lightmap[line3+0] * scale;g10 += (float) lightmap[line3+1] * scale;b10 += (float) lightmap[line3+2] * scale;
|
||||
r11 += (float) lightmap[line3+3] * scale;g11 += (float) lightmap[line3+4] * scale;b11 += (float) lightmap[line3+5] * scale;
|
||||
lightmap += ((surf->extents[0]>>surf->lmshift)+1) * ((surf->extents[1]>>surf->lmshift)+1)*3; // LordHavoc: *3 for colored lighting
|
||||
lightmap += (surf->extents[0]+1) * (surf->extents[1]+1)*3; // LordHavoc: *3 for colored lighting
|
||||
}
|
||||
}
|
||||
|
||||
color[0] += (float) ((int) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)));
|
||||
color[1] += (float) ((int) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)));
|
||||
color[2] += (float) ((int) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)));
|
||||
color[0] += (float) ((int) ((((((r11-r10) * dsfrac) + r10)-(((r01-r00) * dsfrac) + r00)) * dtfrac) + (((r01-r00) * dsfrac) + r00)));
|
||||
color[1] += (float) ((int) ((((((g11-g10) * dsfrac) + g10)-(((g01-g00) * dsfrac) + g00)) * dtfrac) + (((g01-g00) * dsfrac) + g00)));
|
||||
color[2] += (float) ((int) ((((((b11-b10) * dsfrac) + b10)-(((b01-b00) * dsfrac) + b00)) * dtfrac) + (((b01-b00) * dsfrac) + b00)));
|
||||
}
|
||||
return true; // success
|
||||
}
|
||||
|
|
|
@ -2547,8 +2547,8 @@ static void PF_getsurfacepointattribute(void)
|
|||
G_FLOAT(OFS_RETURN+2) = 0;
|
||||
break;
|
||||
case SPA_LIGHTMAP0_TEXCOORDS: //lmst coord, not actually very useful
|
||||
G_FLOAT(OFS_RETURN+0) = (DotProduct(v->position, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3] - fa->texturemins[0] + (fa->light_s+.5)*(1<<fa->lmshift)) / (LMBLOCK_WIDTH*(1<<fa->lmshift));
|
||||
G_FLOAT(OFS_RETURN+1) = (DotProduct(v->position, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3] - fa->texturemins[1] + (fa->light_t+.5)*(1<<fa->lmshift)) / (LMBLOCK_HEIGHT*(1<<fa->lmshift));
|
||||
G_FLOAT(OFS_RETURN+0) = (DotProduct(v->position, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3] + fa->light_s) / LMBLOCK_WIDTH;
|
||||
G_FLOAT(OFS_RETURN+1) = (DotProduct(v->position, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3] + fa->light_t) / LMBLOCK_HEIGHT;
|
||||
G_FLOAT(OFS_RETURN+2) = 0;
|
||||
break;
|
||||
case SPA_LIGHTMAP0_COLOR: //colour
|
||||
|
|
|
@ -698,8 +698,8 @@ dynamic:
|
|||
theRect->w += theRect->l - fa->light_s;
|
||||
theRect->l = fa->light_s;
|
||||
}
|
||||
smax = (fa->extents[0]>>fa->lmshift)+1;
|
||||
tmax = (fa->extents[1]>>fa->lmshift)+1;
|
||||
smax = fa->extents[0]+1;
|
||||
tmax = fa->extents[1]+1;
|
||||
if ((theRect->w + theRect->l) < (fa->light_s + smax))
|
||||
theRect->w = (fa->light_s-theRect->l)+smax;
|
||||
if ((theRect->h + theRect->t) < (fa->light_t + tmax))
|
||||
|
@ -800,8 +800,8 @@ void GL_CreateSurfaceLightmap (qmodel_t *model, msurface_t *surf)
|
|||
return;
|
||||
}
|
||||
|
||||
smax = (surf->extents[0]>>surf->lmshift)+1;
|
||||
tmax = (surf->extents[1]>>surf->lmshift)+1;
|
||||
smax = surf->extents[0]+1;
|
||||
tmax = surf->extents[1]+1;
|
||||
|
||||
surf->lightmaptexturenum = AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
|
||||
base = lightmaps[surf->lightmaptexturenum].data;
|
||||
|
@ -821,7 +821,6 @@ static void BuildSurfaceDisplayList (msurface_t *fa)
|
|||
float *vec;
|
||||
float s, t, s0, t0;
|
||||
glpoly_t *poly;
|
||||
int lmscale = (1<<fa->lmshift);
|
||||
|
||||
// reconstruct the polygon
|
||||
pedges = currentmodel->edges;
|
||||
|
@ -880,17 +879,13 @@ static void BuildSurfaceDisplayList (msurface_t *fa)
|
|||
//
|
||||
// lightmap texture coordinates
|
||||
//
|
||||
s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
|
||||
s -= fa->texturemins[0];
|
||||
s += fa->light_s*lmscale;
|
||||
s += lmscale/2.0;
|
||||
s /= LMBLOCK_WIDTH*lmscale; //fa->texinfo->texture->width;
|
||||
s = DotProduct (vec, fa->lmvecs[0]) + fa->lmvecs[0][3];
|
||||
s += fa->light_s;
|
||||
s /= LMBLOCK_WIDTH;
|
||||
|
||||
t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
|
||||
t -= fa->texturemins[1];
|
||||
t += fa->light_t*lmscale;
|
||||
t += lmscale/2.0;
|
||||
t /= LMBLOCK_HEIGHT*lmscale; //fa->texinfo->texture->height;
|
||||
t = DotProduct (vec, fa->lmvecs[1]) + fa->lmvecs[1][3];
|
||||
t += fa->light_t;
|
||||
t /= LMBLOCK_HEIGHT;
|
||||
|
||||
poly->verts[i][5] = s;
|
||||
poly->verts[i][6] = t;
|
||||
|
@ -1143,18 +1138,14 @@ void R_AddDynamicLights (msurface_t *surf)
|
|||
int s, t;
|
||||
int i;
|
||||
int smax, tmax;
|
||||
mtexinfo_t *tex;
|
||||
//johnfitz -- lit support via lordhavoc
|
||||
float cred, cgreen, cblue, brightness;
|
||||
unsigned *bl;
|
||||
//johnfitz
|
||||
vec3_t lightofs; //Spike: light surfaces based upon where they are now instead of their default position.
|
||||
int lmscale;
|
||||
|
||||
smax = (surf->extents[0]>>surf->lmshift)+1;
|
||||
tmax = (surf->extents[1]>>surf->lmshift)+1;
|
||||
tex = surf->texinfo;
|
||||
lmscale = 1<<surf->lmshift;
|
||||
smax = surf->extents[0]+1;
|
||||
tmax = surf->extents[1]+1;
|
||||
|
||||
for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
|
||||
{
|
||||
|
@ -1176,11 +1167,8 @@ void R_AddDynamicLights (msurface_t *surf)
|
|||
surf->plane->normal[i]*dist;
|
||||
}
|
||||
|
||||
local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3];
|
||||
local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3];
|
||||
|
||||
local[0] -= surf->texturemins[0];
|
||||
local[1] -= surf->texturemins[1];
|
||||
local[0] = DotProduct (impact, surf->lmvecs[0]) + surf->lmvecs[0][3];
|
||||
local[1] = DotProduct (impact, surf->lmvecs[1]) + surf->lmvecs[1][3];
|
||||
|
||||
//johnfitz -- lit support via lordhavoc
|
||||
bl = blocklights;
|
||||
|
@ -1190,12 +1178,12 @@ void R_AddDynamicLights (msurface_t *surf)
|
|||
//johnfitz
|
||||
for (t = 0 ; t<tmax ; t++)
|
||||
{
|
||||
td = local[1] - t*lmscale;
|
||||
td = (local[1] - t)*surf->lmvecscale[1];
|
||||
if (td < 0)
|
||||
td = -td;
|
||||
for (s=0 ; s<smax ; s++)
|
||||
{
|
||||
sd = local[0] - s*lmscale;
|
||||
sd = (local[0] - s)*surf->lmvecscale[0];
|
||||
if (sd < 0)
|
||||
sd = -sd;
|
||||
if (sd > td)
|
||||
|
@ -1236,8 +1224,8 @@ void R_BuildLightMap (qmodel_t *model, msurface_t *surf, byte *dest, int stride)
|
|||
|
||||
surf->cached_dlight = (surf->dlightframe == r_framecount);
|
||||
|
||||
smax = (surf->extents[0]>>surf->lmshift)+1;
|
||||
tmax = (surf->extents[1]>>surf->lmshift)+1;
|
||||
smax = surf->extents[0]+1;
|
||||
tmax = surf->extents[1]+1;
|
||||
size = smax*tmax;
|
||||
|
||||
if (model->lightdata)
|
||||
|
|
Loading…
Reference in a new issue