diff --git a/src/client/refresh/files/light.c b/src/client/refresh/files/light.c index 1ed4384a..c97038ee 100644 --- a/src/client/refresh/files/light.c +++ b/src/client/refresh/files/light.c @@ -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); +} diff --git a/src/client/refresh/files/surf.c b/src/client/refresh/files/surf.c index e2d28bf3..8a39c4a0 100644 --- a/src/client/refresh/files/surf.c +++ b/src/client/refresh/files/surf.c @@ -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 */ diff --git a/src/client/refresh/gl1/gl1_light.c b/src/client/refresh/gl1/gl1_light.c index 5a38e276..f71b6e0e 100644 --- a/src/client/refresh/gl1/gl1_light.c +++ b/src/client/refresh/gl1/gl1_light.c @@ -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); } } diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index 1338195f..90c7f488 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -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); } } diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 2daedf13..68d8e1bd 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -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); diff --git a/src/client/refresh/gl3/gl3_light.c b/src/client/refresh/gl3/gl3_light.c index 61151d4f..f2912322 100644 --- a/src/client/refresh/gl3/gl3_light.c +++ b/src/client/refresh/gl3/gl3_light.c @@ -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); diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index a0156d49..e6db657e 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -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 = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 307a8eea..da8d48d8 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -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); diff --git a/src/client/refresh/gl4/gl4_light.c b/src/client/refresh/gl4/gl4_light.c index 783242a2..dcefa024 100644 --- a/src/client/refresh/gl4/gl4_light.c +++ b/src/client/refresh/gl4/gl4_light.c @@ -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; } } diff --git a/src/client/refresh/gl4/gl4_surf.c b/src/client/refresh/gl4/gl4_surf.c index 5c153f83..484f1b35 100644 --- a/src/client/refresh/gl4/gl4_surf.c +++ b/src/client/refresh/gl4/gl4_surf.c @@ -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 = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; diff --git a/src/client/refresh/gl4/header/local.h b/src/client/refresh/gl4/header/local.h index 10c792bb..87005411 100644 --- a/src/client/refresh/gl4/header/local.h +++ b/src/client/refresh/gl4/header/local.h @@ -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); diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index dde16bc4..fbdba28e 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -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); diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index d613bdd3..1defcb90 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -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 ; inodes + model->firstnode, - r_framecount, R_MarkSurfaceLights); + r_framecount, model->surfaces); } } diff --git a/src/client/refresh/vk/header/local.h b/src/client/refresh/vk/header/local.h index ef7f68a3..7e3b2174 100644 --- a/src/client/refresh/vk/header/local.h +++ b/src/client/refresh/vk/header/local.h @@ -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); diff --git a/src/client/refresh/vk/vk_light.c b/src/client/refresh/vk/vk_light.c index 465ca446..19e11008 100644 --- a/src/client/refresh/vk/vk_light.c +++ b/src/client/refresh/vk/vk_light.c @@ -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); } } diff --git a/src/client/refresh/vk/vk_surf.c b/src/client/refresh/vk/vk_surf.c index c598a664..020d7d7c 100644 --- a/src/client/refresh/vk/vk_surf.c +++ b/src/client/refresh/vk/vk_surf.c @@ -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); } }