mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
gl1,vk: share R_BuildLightMap
This commit is contained in:
parent
0dde2cc731
commit
a124953432
11 changed files with 230 additions and 402 deletions
|
@ -290,7 +290,7 @@ R_SetCacheState(msurface_t *surf, refdef_t *refdef)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
R_AddDynamicLights(msurface_t *surf, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max)
|
||||
{
|
||||
|
@ -390,3 +390,206 @@ R_AddDynamicLights(msurface_t *surf, refdef_t *r_newrefdef,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max, float modulate, int r_framecount)
|
||||
{
|
||||
int smax, tmax;
|
||||
int r, g, b, a, max;
|
||||
int i, j, size;
|
||||
byte *lightmap;
|
||||
float scale[4];
|
||||
int nummaps;
|
||||
float *bl;
|
||||
|
||||
if (surf->texinfo->flags &
|
||||
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
|
||||
{
|
||||
Com_Error(ERR_DROP, "RI_BuildLightMap called for non-lit surface");
|
||||
}
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
|
||||
/* set to full bright if no light data */
|
||||
if (!surf->samples)
|
||||
{
|
||||
for (i = 0; i < size * 3; i++)
|
||||
{
|
||||
s_blocklights[i] = 255;
|
||||
}
|
||||
|
||||
goto store;
|
||||
}
|
||||
|
||||
/* count the # of maps */
|
||||
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255;
|
||||
nummaps++)
|
||||
{
|
||||
}
|
||||
|
||||
lightmap = surf->samples;
|
||||
|
||||
/* add all the lightmaps */
|
||||
if (nummaps == 1)
|
||||
{
|
||||
int maps;
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = modulate *
|
||||
r_newrefdef->lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0];
|
||||
bl[1] = lightmap[i * 3 + 1];
|
||||
bl[2] = lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] = lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] = lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int maps;
|
||||
|
||||
memset(s_blocklights, 0, sizeof(s_blocklights[0]) * size * 3);
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = modulate *
|
||||
r_newrefdef->lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0];
|
||||
bl[1] += lightmap[i * 3 + 1];
|
||||
bl[2] += lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] += lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] += lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
|
||||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf, r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
}
|
||||
|
||||
store:
|
||||
/* put into texture format */
|
||||
stride -= (smax << 2);
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < tmax; i++, dest += stride)
|
||||
{
|
||||
for (j = 0; j < smax; j++)
|
||||
{
|
||||
r = Q_ftol(bl[0]);
|
||||
g = Q_ftol(bl[1]);
|
||||
b = Q_ftol(bl[2]);
|
||||
|
||||
/* catch negative lights */
|
||||
if (r < 0)
|
||||
{
|
||||
r = 0;
|
||||
}
|
||||
|
||||
if (g < 0)
|
||||
{
|
||||
g = 0;
|
||||
}
|
||||
|
||||
if (b < 0)
|
||||
{
|
||||
b = 0;
|
||||
}
|
||||
|
||||
/* determine the brightest of the three color components */
|
||||
if (r > g)
|
||||
{
|
||||
max = r;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = g;
|
||||
}
|
||||
|
||||
if (b > max)
|
||||
{
|
||||
max = b;
|
||||
}
|
||||
|
||||
/* alpha is ONLY used for the mono lightmap case. For this
|
||||
reason we set it to the brightest of the color components
|
||||
so that things don't get too dim. */
|
||||
a = max;
|
||||
|
||||
/* rescale all the color components if the
|
||||
intensity of the greatest channel exceeds
|
||||
1.0 */
|
||||
if (max > 255)
|
||||
{
|
||||
float t = 255.0F / max;
|
||||
|
||||
r = r * t;
|
||||
g = g * t;
|
||||
b = b * t;
|
||||
a = a * t;
|
||||
}
|
||||
|
||||
dest[0] = r;
|
||||
dest[1] = g;
|
||||
dest[2] = b;
|
||||
dest[3] = a;
|
||||
|
||||
bl += 3;
|
||||
dest += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,25 +184,11 @@ float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
|||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
{
|
||||
int smax, tmax;
|
||||
int r, g, b, a, max;
|
||||
int i, j, size;
|
||||
byte *lightmap;
|
||||
float scale[4];
|
||||
int nummaps;
|
||||
float *bl;
|
||||
int size;
|
||||
|
||||
if (surf->texinfo->flags &
|
||||
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
|
||||
{
|
||||
Com_Error(ERR_DROP, "R_BuildLightMap called for non-lit surface");
|
||||
}
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
size = surf->extents[0] * surf->extents[1];
|
||||
|
||||
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
|
||||
{
|
||||
|
@ -227,180 +213,6 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
|||
}
|
||||
}
|
||||
|
||||
/* set to full bright if no light data */
|
||||
if (!surf->samples)
|
||||
{
|
||||
for (i = 0; i < size * 3; i++)
|
||||
{
|
||||
s_blocklights[i] = 255;
|
||||
}
|
||||
|
||||
goto store;
|
||||
}
|
||||
|
||||
/* count the # of maps */
|
||||
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255;
|
||||
nummaps++)
|
||||
{
|
||||
}
|
||||
|
||||
lightmap = surf->samples;
|
||||
|
||||
/* add all the lightmaps */
|
||||
if (nummaps == 1)
|
||||
{
|
||||
int maps;
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = r_modulate->value *
|
||||
r_newrefdef.lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0];
|
||||
bl[1] = lightmap[i * 3 + 1];
|
||||
bl[2] = lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] = lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] = lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int maps;
|
||||
|
||||
memset(s_blocklights, 0, sizeof(s_blocklights[0]) * size * 3);
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = r_modulate->value *
|
||||
r_newrefdef.lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0];
|
||||
bl[1] += lightmap[i * 3 + 1];
|
||||
bl[2] += lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] += lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] += lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
|
||||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf, &r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
}
|
||||
|
||||
store:
|
||||
/* put into texture format */
|
||||
stride -= (smax << 2);
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < tmax; i++, dest += stride)
|
||||
{
|
||||
for (j = 0; j < smax; j++)
|
||||
{
|
||||
r = Q_ftol(bl[0]);
|
||||
g = Q_ftol(bl[1]);
|
||||
b = Q_ftol(bl[2]);
|
||||
|
||||
/* catch negative lights */
|
||||
if (r < 0)
|
||||
{
|
||||
r = 0;
|
||||
}
|
||||
|
||||
if (g < 0)
|
||||
{
|
||||
g = 0;
|
||||
}
|
||||
|
||||
if (b < 0)
|
||||
{
|
||||
b = 0;
|
||||
}
|
||||
|
||||
/* determine the brightest of the three color components */
|
||||
if (r > g)
|
||||
{
|
||||
max = r;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = g;
|
||||
}
|
||||
|
||||
if (b > max)
|
||||
{
|
||||
max = b;
|
||||
}
|
||||
|
||||
/* alpha is ONLY used for the mono lightmap case. For this
|
||||
reason we set it to the brightest of the color components
|
||||
so that things don't get too dim. */
|
||||
a = max;
|
||||
|
||||
/* rescale all the color components if the
|
||||
intensity of the greatest channel exceeds
|
||||
1.0 */
|
||||
if (max > 255)
|
||||
{
|
||||
float t = 255.0F / max;
|
||||
|
||||
r = r * t;
|
||||
g = g * t;
|
||||
b = b * t;
|
||||
a = a * t;
|
||||
}
|
||||
|
||||
dest[0] = r;
|
||||
dest[1] = g;
|
||||
dest[2] = b;
|
||||
dest[3] = a;
|
||||
|
||||
bl += 3;
|
||||
dest += 4;
|
||||
}
|
||||
}
|
||||
R_BuildLightMap(surf, dest, stride, &r_newrefdef, s_blocklights, s_blocklights_max,
|
||||
r_modulate->value, r_framecount);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
extern gllightmapstate_t gl_lms;
|
||||
|
||||
void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
|
||||
void
|
||||
LM_InitBlock(void)
|
||||
|
@ -255,7 +255,7 @@ LM_CreateSurfaceLightmap(msurface_t *surf)
|
|||
base += (surf->light_t * BLOCK_WIDTH + surf->light_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -39,7 +39,7 @@ void LM_InitBlock(void);
|
|||
void LM_UploadBlock(qboolean dynamic);
|
||||
qboolean LM_AllocBlock(int w, int h, int *x, int *y);
|
||||
|
||||
void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
|
||||
static void
|
||||
R_DrawGLPoly(mpoly_t *p)
|
||||
|
@ -328,7 +328,7 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
base += (surf->dlight_t * BLOCK_WIDTH +
|
||||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -374,7 +374,7 @@ R_BlendLightmaps(const model_t *currentmodel)
|
|||
base += (surf->dlight_t * BLOCK_WIDTH +
|
||||
surf->dlight_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,7 +508,7 @@ R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
|
|||
smax = (fa->extents[0] >> fa->lmshift) + 1;
|
||||
tmax = (fa->extents[1] >> fa->lmshift) + 1;
|
||||
|
||||
R_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
RI_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
R_Bind(gl_state.lightmap_textures + fa->lightmaptexturenum);
|
||||
|
|
|
@ -380,8 +380,8 @@ extern bspxlightgrid_t *Mod_LoadBSPXLightGrid(const bspx_header_t *bspx_header,
|
|||
extern void R_LightPoint(const bspxlightgrid_t *grid, const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
|
||||
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
|
||||
extern void R_SetCacheState(msurface_t *surf, refdef_t *r_newrefdef);
|
||||
extern void R_AddDynamicLights(msurface_t *surf, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max);
|
||||
extern void R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max, float modulate, int r_framecount);
|
||||
|
||||
/* Warp Sky logic */
|
||||
extern void R_ClipSkyPolygon(int nump, vec3_t vecs, int stage,
|
||||
|
|
|
@ -73,6 +73,7 @@ R_PushDlights(const model_t *model)
|
|||
static void
|
||||
RI_AddDynamicLights(drawsurf_t* drawsurf)
|
||||
{
|
||||
/* TODO: Covert to reuse with shared files/light */
|
||||
msurface_t *surf;
|
||||
int lnum;
|
||||
int smax, tmax;
|
||||
|
@ -209,7 +210,7 @@ RI_AddDynamicLights(drawsurf_t* drawsurf)
|
|||
* Combine and scale multiple lightmaps into the 8.8 format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(drawsurf_t* drawsurf)
|
||||
RI_BuildLightMap(drawsurf_t* drawsurf)
|
||||
{
|
||||
int smax, tmax;
|
||||
int size;
|
||||
|
|
|
@ -32,7 +32,7 @@ static int r_numvblocks;
|
|||
static unsigned char *r_source, *r_sourcemax;
|
||||
static unsigned *r_lightptr;
|
||||
|
||||
void R_BuildLightMap (drawsurf_t *drawsurf);
|
||||
void RI_BuildLightMap (drawsurf_t *drawsurf);
|
||||
|
||||
static int sc_size;
|
||||
static surfcache_t *sc_rover;
|
||||
|
@ -482,7 +482,7 @@ D_CacheSurface (const entity_t *currententity, msurface_t *surface, int miplevel
|
|||
c_surf++;
|
||||
|
||||
// calculate the lightings
|
||||
R_BuildLightMap (&r_drawsurf);
|
||||
RI_BuildLightMap (&r_drawsurf);
|
||||
|
||||
// rasterize the surface into the cache
|
||||
R_DrawSurface (&r_drawsurf);
|
||||
|
|
|
@ -192,7 +192,7 @@ void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel);
|
|||
void R_DrawBeam(entity_t *currententity);
|
||||
void R_DrawWorld(void);
|
||||
void R_RenderDlights(void);
|
||||
void R_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void RI_BuildLightMap(msurface_t *surf, byte *dest, int stride);
|
||||
void R_DrawAlphaSurfaces(void);
|
||||
void RE_InitParticleTexture(void);
|
||||
void Draw_InitLocal(void);
|
||||
|
|
|
@ -174,25 +174,11 @@ float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
|||
* Combine and scale multiple lightmaps into the floating format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||
{
|
||||
int smax, tmax;
|
||||
int r, g, b, a, max;
|
||||
int i, j, size;
|
||||
byte *lightmap;
|
||||
float scale[4];
|
||||
int nummaps;
|
||||
float *bl;
|
||||
int size;
|
||||
|
||||
if (surf->texinfo->flags &
|
||||
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
|
||||
{
|
||||
Com_Error(ERR_DROP, "R_BuildLightMap called for non-lit surface");
|
||||
}
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax * tmax;
|
||||
size = surf->extents[0] * surf->extents[1];
|
||||
|
||||
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
|
||||
{
|
||||
|
@ -217,180 +203,6 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
|||
}
|
||||
}
|
||||
|
||||
/* set to full bright if no light data */
|
||||
if (!surf->samples)
|
||||
{
|
||||
for (i = 0; i < size * 3; i++)
|
||||
{
|
||||
s_blocklights[i] = 255;
|
||||
}
|
||||
|
||||
goto store;
|
||||
}
|
||||
|
||||
/* count the # of maps */
|
||||
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255;
|
||||
nummaps++)
|
||||
{
|
||||
}
|
||||
|
||||
lightmap = surf->samples;
|
||||
|
||||
/* add all the lightmaps */
|
||||
if (nummaps == 1)
|
||||
{
|
||||
int maps;
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = r_modulate->value *
|
||||
r_newrefdef.lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0];
|
||||
bl[1] = lightmap[i * 3 + 1];
|
||||
bl[2] = lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] = lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] = lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] = lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int maps;
|
||||
|
||||
memset(s_blocklights, 0, sizeof(s_blocklights[0]) * size * 3);
|
||||
|
||||
for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++)
|
||||
{
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
scale[i] = r_modulate->value *
|
||||
r_newrefdef.lightstyles[surf->styles[maps]].rgb[i];
|
||||
}
|
||||
|
||||
if ((scale[0] == 1.0F) &&
|
||||
(scale[1] == 1.0F) &&
|
||||
(scale[2] == 1.0F))
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0];
|
||||
bl[1] += lightmap[i * 3 + 1];
|
||||
bl[2] += lightmap[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size; i++, bl += 3)
|
||||
{
|
||||
bl[0] += lightmap[i * 3 + 0] * scale[0];
|
||||
bl[1] += lightmap[i * 3 + 1] * scale[1];
|
||||
bl[2] += lightmap[i * 3 + 2] * scale[2];
|
||||
}
|
||||
}
|
||||
|
||||
lightmap += size * 3; /* skip to next lightmap */
|
||||
}
|
||||
}
|
||||
|
||||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf, &r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
}
|
||||
|
||||
store:
|
||||
/* put into texture format */
|
||||
stride -= (smax << 2);
|
||||
bl = s_blocklights;
|
||||
|
||||
for (i = 0; i < tmax; i++, dest += stride)
|
||||
{
|
||||
for (j = 0; j < smax; j++)
|
||||
{
|
||||
r = Q_ftol(bl[0]);
|
||||
g = Q_ftol(bl[1]);
|
||||
b = Q_ftol(bl[2]);
|
||||
|
||||
/* catch negative lights */
|
||||
if (r < 0)
|
||||
{
|
||||
r = 0;
|
||||
}
|
||||
|
||||
if (g < 0)
|
||||
{
|
||||
g = 0;
|
||||
}
|
||||
|
||||
if (b < 0)
|
||||
{
|
||||
b = 0;
|
||||
}
|
||||
|
||||
/* determine the brightest of the three color components */
|
||||
if (r > g)
|
||||
{
|
||||
max = r;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = g;
|
||||
}
|
||||
|
||||
if (b > max)
|
||||
{
|
||||
max = b;
|
||||
}
|
||||
|
||||
/* alpha is ONLY used for the mono lightmap case. For this
|
||||
reason we set it to the brightest of the color components
|
||||
so that things don't get too dim. */
|
||||
a = max;
|
||||
|
||||
/* rescale all the color components if the
|
||||
intensity of the greatest channel exceeds
|
||||
1.0 */
|
||||
if (max > 255)
|
||||
{
|
||||
float t = 255.0F / max;
|
||||
|
||||
r = r * t;
|
||||
g = g * t;
|
||||
b = b * t;
|
||||
a = a * t;
|
||||
}
|
||||
|
||||
dest[0] = r;
|
||||
dest[1] = g;
|
||||
dest[2] = b;
|
||||
dest[3] = a;
|
||||
|
||||
bl += 3;
|
||||
dest += 4;
|
||||
}
|
||||
}
|
||||
R_BuildLightMap(surf, dest, stride, &r_newrefdef, s_blocklights, s_blocklights_max,
|
||||
r_modulate->value, r_framecount);
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ Vk_CreateSurfaceLightmap(msurface_t *surf)
|
|||
base += (surf->light_t * BLOCK_WIDTH + surf->light_s) * LIGHTMAP_BYTES;
|
||||
|
||||
R_SetCacheState(surf, &r_newrefdef);
|
||||
R_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
RI_BuildLightMap(surf, base, BLOCK_WIDTH * LIGHTMAP_BYTES);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -247,7 +247,7 @@ R_RenderBrushPoly(msurface_t *fa, float *modelMatrix, float alpha, entity_t *cur
|
|||
smax = (fa->extents[0] >> fa->lmshift) + 1;
|
||||
tmax = (fa->extents[1] >> fa->lmshift) + 1;
|
||||
|
||||
R_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
RI_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||
R_SetCacheState(fa, &r_newrefdef);
|
||||
|
||||
QVk_UpdateTextureData(&vk_state.lightmap_textures[fa->lightmaptexturenum], (unsigned char*)temp, fa->light_s, fa->light_t, smax, tmax);
|
||||
|
@ -448,7 +448,7 @@ Vk_RenderLightmappedPoly(msurface_t *surf, float *modelMatrix, float alpha, enti
|
|||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
R_BuildLightMap(surf, (void *)temp, smax * 4);
|
||||
RI_BuildLightMap(surf, (void *)temp, smax * 4);
|
||||
|
||||
if ((surf->styles[map] >= 32 || surf->styles[map] == 0) && (surf->dlightframe != r_framecount))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue