Share R_MarkSurfaceLights between all renders

This commit is contained in:
Denis Pauk 2023-10-14 01:32:19 +03:00
parent a124953432
commit 4dbb6eb4bc
16 changed files with 104 additions and 248 deletions

View File

@ -593,3 +593,92 @@ store:
}
}
}
static void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
msurface_t *surfaces)
{
msurface_t *surf;
int i;
/* mark the polygons */
surf = surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
surf->dlightbits |= bit;
}
}
/*
=============
R_MarkLights
bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits
if surface is affected by this light
=============
*/
void
R_MarkLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
msurface_t *surfaces)
{
cplane_t *splitplane;
float dist;
int intensity;
if (node->contents != CONTENTS_NODE)
{
return;
}
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
intensity = light->intensity;
if (dist > (intensity - DLIGHT_CUTOFF)) // (dist > light->intensity)
{
R_MarkLights(light, bit, node->children[0], r_dlightframecount,
surfaces);
return;
}
if (dist < (-intensity + DLIGHT_CUTOFF)) // (dist < -light->intensity)
{
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
surfaces);
return;
}
R_MarkSurfaceLights(light, bit, node, r_dlightframecount, surfaces);
R_MarkLights(light, bit, node->children[0], r_dlightframecount,
surfaces);
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
surfaces);
}

View File

@ -73,52 +73,6 @@ R_AreaVisible(const byte *areabits, mleaf_t *pleaf)
return false; // not visible
}
/*
=============
R_MarkLights
bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits
if surface is affected by this light
=============
*/
void
R_MarkLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
marksurfacelights_t mark_surface_lights)
{
cplane_t *splitplane;
float dist;
int intensity;
if (node->contents != CONTENTS_NODE)
return;
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
intensity = light->intensity;
if (dist > intensity - DLIGHT_CUTOFF) // (dist > light->intensity)
{
R_MarkLights (light, bit, node->children[0], r_dlightframecount,
mark_surface_lights);
return;
}
if (dist < -intensity + DLIGHT_CUTOFF) // (dist < -light->intensity)
{
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
mark_surface_lights);
return;
}
mark_surface_lights(light, bit, node, r_dlightframecount);
R_MarkLights(light, bit, node->children[0], r_dlightframecount,
mark_surface_lights);
R_MarkLights(light, bit, node->children[1], r_dlightframecount,
mark_surface_lights);
}
/*
* Returns true if the box is completely outside the frustom
*/

View File

@ -115,46 +115,6 @@ R_RenderDlights(void)
glDepthMask(1);
}
void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
msurface_t *surf;
int i;
/* mark the polygons */
surf = r_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
surf->dlightbits |= bit;
}
}
void
R_PushDlights(void)
{
@ -174,7 +134,7 @@ R_PushDlights(void)
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
{
R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount,
R_MarkSurfaceLights);
r_worldmodel->surfaces);
}
}

View File

@ -646,7 +646,7 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
{
R_MarkLights(lt, 1 << k,
currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, R_MarkSurfaceLights);
r_dlightframecount, currentmodel->surfaces);
}
}

View File

@ -260,8 +260,6 @@ void R_EmitWaterPolys(msurface_t *fa);
void RE_AddSkySurface(msurface_t *fa);
void RE_ClearSkyBox(void);
void R_DrawSkyBox(void);
void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
void R_SwapBuffers(int);

View File

@ -32,46 +32,6 @@ extern gl3lightmapstate_t gl3_lms;
int r_dlightframecount;
vec3_t lightspot;
void
GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
msurface_t *surf;
int i;
/* mark the polygons */
surf = gl3_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
surf->dlightbits |= bit;
}
}
void
GL3_PushDlights(void)
{
@ -88,7 +48,8 @@ GL3_PushDlights(void)
for (i = 0; i < gl3_newrefdef.num_dlights; i++, l++)
{
gl3UniDynLight* udl = &gl3state.uniLightsData.dynLights[i];
R_MarkLights(l, 1 << i, gl3_worldmodel->nodes, r_dlightframecount, GL3_MarkSurfaceLights);
R_MarkLights(l, 1 << i, gl3_worldmodel->nodes, r_dlightframecount,
gl3_worldmodel->surfaces);
VectorCopy(l->origin, udl->origin);
VectorCopy(l->color, udl->color);

View File

@ -492,7 +492,7 @@ DrawInlineBModel(entity_t *currententity, gl3model_t *currentmodel)
for (k = 0; k < gl3_newrefdef.num_dlights; k++, lt++)
{
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, GL3_MarkSurfaceLights);
r_dlightframecount, currentmodel->surfaces);
}
psurf = &currentmodel->surfaces[currentmodel->firstmodelsurface];

View File

@ -456,8 +456,6 @@ extern void GL3_ImageList_f(void);
// gl3_light.c
extern int r_dlightframecount;
extern void GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
extern void GL3_PushDlights(void);
extern void GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride);

View File

@ -32,46 +32,6 @@ extern gl4lightmapstate_t gl4_lms;
int r_dlightframecount;
vec3_t lightspot;
void
GL4_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
msurface_t *surf;
int i;
/* mark the polygons */
surf = gl4_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
surf->dlightbits |= bit;
}
}
void
GL4_PushDlights(void)
{
@ -88,7 +48,8 @@ GL4_PushDlights(void)
for (i = 0; i < gl4_newrefdef.num_dlights; i++, l++)
{
gl4UniDynLight* udl = &gl4state.uniLightsData.dynLights[i];
R_MarkLights(l, 1 << i, gl4_worldmodel->nodes, r_dlightframecount, GL4_MarkSurfaceLights);
R_MarkLights(l, 1 << i, gl4_worldmodel->nodes, r_dlightframecount,
gl4_worldmodel->surfaces);
VectorCopy(l->origin, udl->origin);
VectorCopy(l->color, udl->color);
@ -155,8 +116,8 @@ GL4_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride)
for (i = 0; i < tmax; i++, dest += stride)
{
memset(dest, c, 4*smax);
dest += 4*smax;
memset(dest, c, 4 * smax);
dest += 4 * smax;
}
}

View File

@ -492,7 +492,7 @@ DrawInlineBModel(entity_t *currententity, gl4model_t *currentmodel)
for (k = 0; k < gl4_newrefdef.num_dlights; k++, lt++)
{
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, GL4_MarkSurfaceLights);
r_dlightframecount, currentmodel->surfaces);
}
psurf = &currentmodel->surfaces[currentmodel->firstmodelsurface];

View File

@ -456,8 +456,6 @@ extern void GL4_ImageList_f(void);
// gl4_light.c
extern int r_dlightframecount;
extern void GL4_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
extern void GL4_PushDlights(void);
extern void GL4_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride);

View File

@ -362,10 +362,8 @@ extern int Mod_LoadFile(char *name, void **buffer);
/* Surface logic */
#define DLIGHT_CUTOFF 64
typedef void (*marksurfacelights_t)(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
extern void R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount,
marksurfacelights_t mark_surface_lights);
msurface_t *surfaces);
extern struct image_s *R_TextureAnimation(const entity_t *currententity,
const mtexinfo_t *tex);
extern qboolean R_AreaVisible(const byte *areabits, mleaf_t *pleaf);

View File

@ -32,25 +32,6 @@ DYNAMIC LIGHTS
=============================================================================
*/
static void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
msurface_t *surf;
int i;
// mark the polygons
surf = r_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
surf->dlightbits |= bit;
}
}
/*
=============
R_PushDlights
@ -64,9 +45,9 @@ R_PushDlights(const model_t *model)
for (i=0, l = r_newrefdef.dlights ; i<r_newrefdef.num_dlights ; i++, l++)
{
R_MarkLights ( l, 1<<i,
R_MarkLights(l, 1<<i,
model->nodes + model->firstnode,
r_framecount, R_MarkSurfaceLights);
r_framecount, model->surfaces);
}
}

View File

@ -205,8 +205,6 @@ void EmitWaterPolys(msurface_t *fa, image_t *texture,
void RE_AddSkySurface(msurface_t *fa);
void RE_ClearSkyBox(void);
void R_DrawSkyBox(void);
void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
struct image_s *RE_Draw_FindPic (const char *name);

View File

@ -105,46 +105,6 @@ R_RenderDlights(void)
}
}
void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
msurface_t *surf;
int i;
/* mark the polygons */
surf = r_worldmodel->surfaces + node->firstsurface;
for (i = 0; i < node->numsurfaces; i++, surf++)
{
int sidebit;
float dist;
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
surf->dlightbits |= bit;
}
}
void
R_PushDlights(void)
{
@ -164,7 +124,7 @@ R_PushDlights(void)
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
{
R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount,
R_MarkSurfaceLights);
r_worldmodel->surfaces);
}
}

View File

@ -612,7 +612,7 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel, float *
{
R_MarkLights(lt, 1 << k,
currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, R_MarkSurfaceLights);
r_dlightframecount, currentmodel->surfaces);
}
}