mirror of
https://github.com/yquake2/ref_vk.git
synced 2024-11-10 06:41:45 +00:00
LIGHTMAPS: Add support for LMSHIFT.
Could be extended to support the LMSHIFT BSPX blob. Currently mostly a cleanup to make DECOUPLEDLM changes more readable.
This commit is contained in:
parent
831b29b8c5
commit
366c0efc0f
4 changed files with 32 additions and 28 deletions
|
@ -43,6 +43,7 @@ BRUSH MODELS
|
|||
//
|
||||
|
||||
#define VERTEXSIZE 7
|
||||
#define DEFAULT_LMSHIFT 4
|
||||
|
||||
typedef struct vkpoly_s
|
||||
{
|
||||
|
@ -66,6 +67,8 @@ typedef struct msurface_s
|
|||
short texturemins[2];
|
||||
short extents[2];
|
||||
|
||||
short lmshift;
|
||||
|
||||
int light_s, light_t; // gl lightmap coordinates
|
||||
int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
|
||||
|
||||
|
@ -75,7 +78,7 @@ typedef struct msurface_s
|
|||
|
||||
mtexinfo_t *texinfo;
|
||||
|
||||
// lighting info
|
||||
/* lighting info */
|
||||
int dlightframe;
|
||||
int dlightbits;
|
||||
|
||||
|
|
|
@ -215,9 +215,9 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor)
|
|||
}
|
||||
|
||||
frac = front / (front-back);
|
||||
mid[0] = start[0] + (end[0] - start[0])*frac;
|
||||
mid[1] = start[1] + (end[1] - start[1])*frac;
|
||||
mid[2] = start[2] + (end[2] - start[2])*frac;
|
||||
mid[0] = start[0] + (end[0] - start[0]) * frac;
|
||||
mid[1] = start[1] + (end[1] - start[1]) * frac;
|
||||
mid[2] = start[2] + (end[2] - start[2]) * frac;
|
||||
|
||||
/* go down front side */
|
||||
r = RecursiveLightPoint(node->children[side], start, mid, pointcolor);
|
||||
|
@ -262,13 +262,13 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ds >>= 4;
|
||||
dt >>= 4;
|
||||
ds >>= surf->lmshift;
|
||||
dt >>= surf->lmshift;
|
||||
|
||||
lightmap = surf->samples;
|
||||
VectorCopy(vec3_origin, pointcolor);
|
||||
|
||||
lightmap += 3 * (dt * ((surf->extents[0] >> 4) + 1) + ds);
|
||||
lightmap += 3 * (dt * ((surf->extents[0] >> surf->lmshift) + 1) + ds);
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
|
@ -276,14 +276,14 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor)
|
|||
|
||||
for (j = 0; j < 3; j++)
|
||||
{
|
||||
scale[j] = r_modulate->value*r_newrefdef.lightstyles[surf->styles[maps]].rgb[j];
|
||||
scale[j] = r_modulate->value * r_newrefdef.lightstyles[surf->styles[maps]].rgb[j];
|
||||
}
|
||||
|
||||
pointcolor[0] += lightmap[0] * scale[0] * (1.0/255);
|
||||
pointcolor[1] += lightmap[1] * scale[1] * (1.0/255);
|
||||
pointcolor[2] += lightmap[2] * scale[2] * (1.0/255);
|
||||
lightmap += 3 * ((surf->extents[0] >> 4) + 1) *
|
||||
((surf->extents[1] >> 4) + 1);
|
||||
lightmap += 3 * ((surf->extents[0] >> surf->lmshift) + 1) *
|
||||
((surf->extents[1] >> surf->lmshift) + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -372,8 +372,8 @@ R_AddDynamicLights(msurface_t *surf)
|
|||
float *plightdest;
|
||||
float fsacc, ftacc;
|
||||
|
||||
smax = (surf->extents[0] >> 4) + 1;
|
||||
tmax = (surf->extents[1] >> 4) + 1;
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
tex = surf->texinfo;
|
||||
|
||||
for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
|
||||
|
@ -408,13 +408,13 @@ R_AddDynamicLights(msurface_t *surf)
|
|||
local[1] = DotProduct(impact, tex->vecs[1]) + tex->vecs[1][3] - surf->texturemins[1];
|
||||
|
||||
plightdest = s_blocklights;
|
||||
for (t = 0, ftacc = 0 ; t<tmax ; t++, ftacc += 16)
|
||||
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
||||
{
|
||||
td = local[1] - ftacc;
|
||||
if ( td < 0 )
|
||||
td = -td;
|
||||
|
||||
for ( s=0, fsacc = 0 ; s<smax ; s++, fsacc += 16, plightdest += 3)
|
||||
for ( s=0, fsacc = 0 ; s<smax ; s++, fsacc += (1 << surf->lmshift), plightdest += 3)
|
||||
{
|
||||
sd = Q_ftol( local[0] - fsacc );
|
||||
|
||||
|
@ -479,8 +479,8 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
|||
ri.Sys_Error (ERR_DROP, "R_BuildLightMap called for non-lit surface");
|
||||
}
|
||||
|
||||
smax = (surf->extents[0] >> 4) + 1;
|
||||
tmax = (surf->extents[1] >> 4) + 1;
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
|
||||
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
|
||||
|
|
|
@ -443,6 +443,7 @@ Mod_LoadFaces (model_t *loadmodel, const byte *mod_base, const lump_t *l)
|
|||
}
|
||||
|
||||
out->texinfo = loadmodel->texinfo + ti;
|
||||
out->lmshift = DEFAULT_LMSHIFT;
|
||||
|
||||
CalcSurfaceExtents(loadmodel, out);
|
||||
|
||||
|
|
|
@ -303,8 +303,8 @@ static void R_RenderBrushPoly (msurface_t *fa, float *modelMatrix, float alpha,
|
|||
unsigned temp[34 * 34];
|
||||
int smax, tmax;
|
||||
|
||||
smax = (fa->extents[0] >> 4) + 1;
|
||||
tmax = (fa->extents[1] >> 4) + 1;
|
||||
smax = (fa->extents[0] >> fa->lmshift) + 1;
|
||||
tmax = (fa->extents[1] >> fa->lmshift) + 1;
|
||||
|
||||
R_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
R_SetCacheState(fa);
|
||||
|
@ -477,8 +477,8 @@ static void Vk_RenderLightmappedPoly( msurface_t *surf, float *modelMatrix, floa
|
|||
unsigned temp[128 * 128];
|
||||
int smax, tmax;
|
||||
|
||||
smax = (surf->extents[0] >> 4) + 1;
|
||||
tmax = (surf->extents[1] >> 4) + 1;
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
R_BuildLightMap(surf, (void *)temp, smax * 4);
|
||||
|
||||
|
@ -1174,15 +1174,15 @@ void Vk_BuildPolygonFromSurface(msurface_t *fa, model_t *currentmodel)
|
|||
//
|
||||
s = DotProduct(vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
|
||||
s -= fa->texturemins[0];
|
||||
s += fa->light_s*16;
|
||||
s += 8;
|
||||
s /= BLOCK_WIDTH*16; //fa->texinfo->texture->width;
|
||||
s += fa->light_s * (1 << fa->lmshift);
|
||||
s += (1 << fa->lmshift) * 0.5;
|
||||
s /= BLOCK_WIDTH * (1 << fa->lmshift);
|
||||
|
||||
t = DotProduct(vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
|
||||
t -= fa->texturemins[1];
|
||||
t += fa->light_t*16;
|
||||
t += 8;
|
||||
t /= BLOCK_HEIGHT*16; //fa->texinfo->texture->height;
|
||||
t += fa->light_t * (1 << fa->lmshift);
|
||||
t += (1 << fa->lmshift) * 0.5;
|
||||
t /= BLOCK_HEIGHT * (1 << fa->lmshift);
|
||||
|
||||
poly->verts[i][5] = s;
|
||||
poly->verts[i][6] = t;
|
||||
|
@ -1205,8 +1205,8 @@ void Vk_CreateSurfaceLightmap (msurface_t *surf)
|
|||
if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB))
|
||||
return;
|
||||
|
||||
smax = (surf->extents[0] >> 4) + 1;
|
||||
tmax = (surf->extents[1] >> 4) + 1;
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
if ( !LM_AllocBlock( smax, tmax, &surf->light_s, &surf->light_t ) )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue