mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 20:51:31 +00:00
gl1,vk: share R_AddDynamicLights
This commit is contained in:
parent
85c18a8090
commit
0dde2cc731
5 changed files with 151 additions and 226 deletions
|
@ -289,3 +289,104 @@ R_SetCacheState(msurface_t *surf, refdef_t *refdef)
|
|||
refdef->lightstyles[surf->styles[maps]].white;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
R_AddDynamicLights(msurface_t *surf, refdef_t *r_newrefdef,
|
||||
float *s_blocklights, const float *s_blocklights_max)
|
||||
{
|
||||
int lnum;
|
||||
float fdist, frad, fminlight;
|
||||
vec3_t impact, local;
|
||||
int t;
|
||||
int i;
|
||||
int smax, tmax;
|
||||
dlight_t *dl;
|
||||
float *plightdest;
|
||||
float fsacc, ftacc;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
for (lnum = 0; lnum < r_newrefdef->num_dlights; lnum++)
|
||||
{
|
||||
if (!(surf->dlightbits & (1 << lnum)))
|
||||
{
|
||||
continue; /* not lit by this light */
|
||||
}
|
||||
|
||||
dl = &r_newrefdef->dlights[lnum];
|
||||
frad = dl->intensity;
|
||||
fdist = DotProduct(dl->origin, surf->plane->normal) -
|
||||
surf->plane->dist;
|
||||
frad -= fabs(fdist);
|
||||
|
||||
/* rad is now the highest intensity on the plane */
|
||||
fminlight = DLIGHT_CUTOFF;
|
||||
|
||||
if (frad < fminlight)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fminlight = frad - fminlight;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
impact[i] = dl->origin[i] -
|
||||
surf->plane->normal[i] * fdist;
|
||||
}
|
||||
|
||||
local[0] = DotProduct(impact, surf->lmvecs[0]) +
|
||||
surf->lmvecs[0][3] - surf->texturemins[0];
|
||||
local[1] = DotProduct(impact, surf->lmvecs[1]) +
|
||||
surf->lmvecs[1][3] - surf->texturemins[1];
|
||||
|
||||
plightdest = s_blocklights;
|
||||
|
||||
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
||||
{
|
||||
int s, td;
|
||||
|
||||
td = local[1] - ftacc;
|
||||
|
||||
if (td < 0)
|
||||
{
|
||||
td = -td;
|
||||
}
|
||||
|
||||
td *= surf->lmvlen[1];
|
||||
|
||||
for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), plightdest += 3)
|
||||
{
|
||||
int sd;
|
||||
|
||||
sd = Q_ftol(local[0] - fsacc);
|
||||
|
||||
if (sd < 0)
|
||||
{
|
||||
sd = -sd;
|
||||
}
|
||||
|
||||
sd *= surf->lmvlen[0];
|
||||
|
||||
if (sd > td)
|
||||
{
|
||||
fdist = sd + (td >> 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fdist = td + (sd >> 1);
|
||||
}
|
||||
|
||||
if ((fdist < fminlight) && (plightdest < (s_blocklights_max - 3)))
|
||||
{
|
||||
float diff = frad - fdist;
|
||||
|
||||
plightdest[0] += diff * dl->color[0];
|
||||
plightdest[1] += diff * dl->color[1];
|
||||
plightdest[2] += diff * dl->color[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,103 +178,6 @@ R_PushDlights(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
R_AddDynamicLights(msurface_t *surf)
|
||||
{
|
||||
int lnum;
|
||||
int sd, td;
|
||||
float fdist, frad, fminlight;
|
||||
vec3_t impact, local;
|
||||
int s, t;
|
||||
int i;
|
||||
int smax, tmax;
|
||||
dlight_t *dl;
|
||||
float *plightdest;
|
||||
float fsacc, ftacc;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++)
|
||||
{
|
||||
if (!(surf->dlightbits & (1 << lnum)))
|
||||
{
|
||||
continue; /* not lit by this light */
|
||||
}
|
||||
|
||||
dl = &r_newrefdef.dlights[lnum];
|
||||
frad = dl->intensity;
|
||||
fdist = DotProduct(dl->origin, surf->plane->normal) -
|
||||
surf->plane->dist;
|
||||
frad -= fabs(fdist);
|
||||
|
||||
/* rad is now the highest intensity on the plane */
|
||||
fminlight = DLIGHT_CUTOFF;
|
||||
|
||||
if (frad < fminlight)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fminlight = frad - fminlight;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
impact[i] = dl->origin[i] -
|
||||
surf->plane->normal[i] * fdist;
|
||||
}
|
||||
|
||||
local[0] = DotProduct(impact, surf->lmvecs[0]) +
|
||||
surf->lmvecs[0][3] - surf->texturemins[0];
|
||||
local[1] = DotProduct(impact, surf->lmvecs[1]) +
|
||||
surf->lmvecs[1][3] - surf->texturemins[1];
|
||||
|
||||
plightdest = s_blocklights;
|
||||
|
||||
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
||||
{
|
||||
td = local[1] - ftacc;
|
||||
|
||||
if (td < 0)
|
||||
{
|
||||
td = -td;
|
||||
}
|
||||
|
||||
td *= surf->lmvlen[1];
|
||||
|
||||
for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), plightdest += 3)
|
||||
{
|
||||
sd = Q_ftol(local[0] - fsacc);
|
||||
|
||||
if (sd < 0)
|
||||
{
|
||||
sd = -sd;
|
||||
}
|
||||
|
||||
sd *= surf->lmvlen[0];
|
||||
|
||||
if (sd > td)
|
||||
{
|
||||
fdist = sd + (td >> 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fdist = td + (sd >> 1);
|
||||
}
|
||||
|
||||
if ((fdist < fminlight) && (plightdest < (s_blocklights_max - 3)))
|
||||
{
|
||||
float diff = frad - fdist;
|
||||
|
||||
plightdest[0] += diff * dl->color[0];
|
||||
plightdest[1] += diff * dl->color[1];
|
||||
plightdest[2] += diff * dl->color[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
||||
|
||||
/*
|
||||
|
@ -426,7 +329,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
|||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf);
|
||||
R_AddDynamicLights(surf, &r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
}
|
||||
|
||||
store:
|
||||
|
|
|
@ -380,6 +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);
|
||||
|
||||
/* Warp Sky logic */
|
||||
extern void R_ClipSkyPolygon(int nump, vec3_t vecs, int stage,
|
||||
|
|
|
@ -57,7 +57,7 @@ R_PushDlights
|
|||
=============
|
||||
*/
|
||||
void
|
||||
R_PushDlights (const model_t *model)
|
||||
R_PushDlights(const model_t *model)
|
||||
{
|
||||
int i;
|
||||
dlight_t *l;
|
||||
|
@ -71,12 +71,12 @@ R_PushDlights (const model_t *model)
|
|||
}
|
||||
|
||||
static void
|
||||
R_AddDynamicLights(drawsurf_t* drawsurf)
|
||||
RI_AddDynamicLights(drawsurf_t* drawsurf)
|
||||
{
|
||||
msurface_t *surf;
|
||||
int lnum;
|
||||
int smax, tmax;
|
||||
mtexinfo_t *tex;
|
||||
int lnum;
|
||||
int smax, tmax;
|
||||
mtexinfo_t *tex;
|
||||
|
||||
surf = drawsurf->surf;
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
|
@ -129,39 +129,57 @@ R_AddDynamicLights(drawsurf_t* drawsurf)
|
|||
surf->plane->dist;
|
||||
rad -= fabs(dist);
|
||||
minlight = DLIGHT_CUTOFF; // dl->minlight;
|
||||
if (rad < minlight)
|
||||
continue;
|
||||
minlight = rad - minlight;
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
if (rad < minlight)
|
||||
{
|
||||
impact[i] = dl->origin[i] -
|
||||
surf->plane->normal[i]*dist;
|
||||
continue;
|
||||
}
|
||||
|
||||
local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3];
|
||||
local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3];
|
||||
minlight = rad - minlight;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
impact[i] = dl->origin[i] -
|
||||
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];
|
||||
|
||||
for (t = 0 ; t < tmax ; t++)
|
||||
for (t = 0; t < tmax; t++)
|
||||
{
|
||||
int s, td;
|
||||
|
||||
td = local[1] - t * (1 << surf->lmshift);
|
||||
if (td < 0)
|
||||
{
|
||||
td = -td;
|
||||
for (s=0 ; s<smax ; s++)
|
||||
}
|
||||
|
||||
for (s = 0; s < smax; s++)
|
||||
{
|
||||
int sd;
|
||||
|
||||
sd = local[0] - s * (1 << surf->lmshift);
|
||||
|
||||
if (sd < 0)
|
||||
{
|
||||
sd = -sd;
|
||||
}
|
||||
|
||||
if (sd > td)
|
||||
{
|
||||
dist = sd + (td >> 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = td + (sd >> 1);
|
||||
}
|
||||
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
|
@ -188,25 +206,21 @@ R_AddDynamicLights(drawsurf_t* drawsurf)
|
|||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
R_BuildLightMap
|
||||
|
||||
Combine and scale multiple lightmaps into the 8.8 format in blocklights
|
||||
===============
|
||||
*/
|
||||
* Combine and scale multiple lightmaps into the 8.8 format in blocklights
|
||||
*/
|
||||
void
|
||||
R_BuildLightMap (drawsurf_t* drawsurf)
|
||||
R_BuildLightMap(drawsurf_t* drawsurf)
|
||||
{
|
||||
int smax, tmax;
|
||||
int size;
|
||||
byte *lightmap;
|
||||
msurface_t *surf;
|
||||
int smax, tmax;
|
||||
int size;
|
||||
byte *lightmap;
|
||||
msurface_t *surf;
|
||||
|
||||
surf = drawsurf->surf;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
size = smax*tmax*3;
|
||||
size = smax * tmax * 3;
|
||||
|
||||
if (blocklight_max <= blocklights + size)
|
||||
{
|
||||
|
@ -214,7 +228,7 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
return;
|
||||
}
|
||||
|
||||
// clear to no light
|
||||
/* clear to no light */
|
||||
memset(blocklights, 0, size * sizeof(light_t));
|
||||
|
||||
if (r_fullbright->value || !r_worldmodel->lightdata)
|
||||
|
@ -222,7 +236,7 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
return;
|
||||
}
|
||||
|
||||
// add all the lightmaps
|
||||
/* add all the lightmaps */
|
||||
lightmap = surf->samples;
|
||||
if (lightmap)
|
||||
{
|
||||
|
@ -302,7 +316,9 @@ R_BuildLightMap (drawsurf_t* drawsurf)
|
|||
|
||||
// add all the dynamic lights
|
||||
if (surf->dlightframe == r_framecount)
|
||||
R_AddDynamicLights (drawsurf);
|
||||
{
|
||||
RI_AddDynamicLights (drawsurf);
|
||||
}
|
||||
|
||||
// bound, invert, and shift
|
||||
{
|
||||
|
|
|
@ -168,103 +168,6 @@ R_PushDlights(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
R_AddDynamicLights(msurface_t *surf)
|
||||
{
|
||||
int lnum;
|
||||
int sd, td;
|
||||
float fdist, frad, fminlight;
|
||||
vec3_t impact, local;
|
||||
int s, t;
|
||||
int i;
|
||||
int smax, tmax;
|
||||
dlight_t *dl;
|
||||
float *plightdest;
|
||||
float fsacc, ftacc;
|
||||
|
||||
smax = (surf->extents[0] >> surf->lmshift) + 1;
|
||||
tmax = (surf->extents[1] >> surf->lmshift) + 1;
|
||||
|
||||
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++)
|
||||
{
|
||||
if (!(surf->dlightbits & (1 << lnum)))
|
||||
{
|
||||
continue; /* not lit by this light */
|
||||
}
|
||||
|
||||
dl = &r_newrefdef.dlights[lnum];
|
||||
frad = dl->intensity;
|
||||
fdist = DotProduct(dl->origin, surf->plane->normal) -
|
||||
surf->plane->dist;
|
||||
frad -= fabs(fdist);
|
||||
|
||||
/* rad is now the highest intensity on the plane */
|
||||
fminlight = DLIGHT_CUTOFF;
|
||||
|
||||
if (frad < fminlight)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fminlight = frad - fminlight;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
impact[i] = dl->origin[i] -
|
||||
surf->plane->normal[i] * fdist;
|
||||
}
|
||||
|
||||
local[0] = DotProduct(impact, surf->lmvecs[0]) +
|
||||
surf->lmvecs[0][3] - surf->texturemins[0];
|
||||
local[1] = DotProduct(impact, surf->lmvecs[1]) +
|
||||
surf->lmvecs[1][3] - surf->texturemins[1];
|
||||
|
||||
plightdest = s_blocklights;
|
||||
|
||||
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
||||
{
|
||||
td = local[1] - ftacc;
|
||||
|
||||
if (td < 0)
|
||||
{
|
||||
td = -td;
|
||||
}
|
||||
|
||||
td *= surf->lmvlen[1];
|
||||
|
||||
for (s = 0, fsacc = 0; s < smax; s++, fsacc += (1 << surf->lmshift), plightdest += 3)
|
||||
{
|
||||
sd = Q_ftol(local[0] - fsacc);
|
||||
|
||||
if (sd < 0)
|
||||
{
|
||||
sd = -sd;
|
||||
}
|
||||
|
||||
sd *= surf->lmvlen[0];
|
||||
|
||||
if (sd > td)
|
||||
{
|
||||
fdist = sd + (td >> 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fdist = td + (sd >> 1);
|
||||
}
|
||||
|
||||
if ((fdist < fminlight) && (plightdest < (s_blocklights_max - 3)))
|
||||
{
|
||||
float diff = frad - fdist;
|
||||
|
||||
plightdest[0] += diff * dl->color[0];
|
||||
plightdest[1] += diff * dl->color[1];
|
||||
plightdest[2] += diff * dl->color[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float *s_blocklights = NULL, *s_blocklights_max = NULL;
|
||||
|
||||
/*
|
||||
|
@ -416,7 +319,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
|||
/* add all the dynamic lights */
|
||||
if (surf->dlightframe == r_framecount)
|
||||
{
|
||||
R_AddDynamicLights(surf);
|
||||
R_AddDynamicLights(surf, &r_newrefdef, s_blocklights, s_blocklights_max);
|
||||
}
|
||||
|
||||
store:
|
||||
|
|
Loading…
Reference in a new issue