Share R_MarkLights

This commit is contained in:
Denis Pauk 2022-10-31 21:01:20 +02:00
parent d326b1be51
commit 32ab1e1815
10 changed files with 86 additions and 114 deletions

View file

@ -70,3 +70,49 @@ 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);
}

View file

@ -26,8 +26,6 @@
#include "header/local.h"
#define DLIGHT_CUTOFF 64
int r_dlightframecount;
vec3_t pointcolor;
cplane_t *lightplane; /* used as shadow plane */
@ -121,39 +119,19 @@ R_RenderDlights(void)
}
void
R_MarkLights(dlight_t *light, int bit, mnode_t *node)
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
int sidebit;
if (node->contents != CONTENTS_NODE)
{
return;
}
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->intensity - DLIGHT_CUTOFF)
{
R_MarkLights(light, bit, node->children[0]);
return;
}
if (dist < -light->intensity + DLIGHT_CUTOFF)
{
R_MarkLights(light, bit, node->children[1]);
return;
}
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;
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
if (dist >= 0)
@ -178,9 +156,6 @@ R_MarkLights(dlight_t *light, int bit, mnode_t *node)
surf->dlightbits |= bit;
}
R_MarkLights(light, bit, node->children[0]);
R_MarkLights(light, bit, node->children[1]);
}
void
@ -201,7 +176,8 @@ R_PushDlights(void)
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
{
R_MarkLights(l, 1 << i, r_worldmodel->nodes);
R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount,
R_MarkSurfaceLights);
}
}

View file

@ -650,7 +650,9 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel)
for (k = 0; k < r_newrefdef.num_dlights; k++, lt++)
{
R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode);
R_MarkLights(lt, 1 << k,
currentmodel->nodes + currentmodel->firstnode,
r_dlightframecount, R_MarkSurfaceLights);
}
}

View file

@ -271,12 +271,14 @@ qboolean R_CullBox(vec3_t mins, vec3_t maxs);
void R_RotateForEntity(entity_t *e);
void R_MarkLeaves(void);
extern int r_dlightframecount;
glpoly_t *WaterWarpPolyVerts(glpoly_t *p);
void R_EmitWaterPolys(msurface_t *fa);
void R_AddSkySurface(msurface_t *fa);
void R_ClearSkyBox(void);
void R_DrawSkyBox(void);
void R_MarkLights(dlight_t *light, int bit, mnode_t *node);
void R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node,
int r_dlightframecount);
void COM_StripExtension(char *in, char *out);

View file

@ -29,47 +29,25 @@
extern gl3lightmapstate_t gl3_lms;
#define DLIGHT_CUTOFF 64
static int r_dlightframecount;
int r_dlightframecount;
static vec3_t pointcolor;
static cplane_t *lightplane; /* used as shadow plane */
vec3_t lightspot;
void // bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits if surface is affected by this light
GL3_MarkLights(dlight_t *light, int bit, mnode_t *node)
void
GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
int sidebit;
if (node->contents != CONTENTS_NODE)
{
return;
}
splitplane = node->plane;
dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->intensity - DLIGHT_CUTOFF)
{
GL3_MarkLights(light, bit, node->children[0]);
return;
}
if (dist < -light->intensity + DLIGHT_CUTOFF)
{
GL3_MarkLights(light, bit, node->children[1]);
return;
}
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;
@ -94,9 +72,6 @@ GL3_MarkLights(dlight_t *light, int bit, mnode_t *node)
surf->dlightbits |= bit;
}
GL3_MarkLights(light, bit, node->children[0]);
GL3_MarkLights(light, bit, node->children[1]);
}
void
@ -115,7 +90,7 @@ GL3_PushDlights(void)
for (i = 0; i < gl3_newrefdef.num_dlights; i++, l++)
{
gl3UniDynLight* udl = &gl3state.uniLightsData.dynLights[i];
GL3_MarkLights(l, 1 << i, gl3_worldmodel->nodes);
R_MarkLights(l, 1 << i, gl3_worldmodel->nodes, r_dlightframecount, GL3_MarkSurfaceLights);
VectorCopy(l->origin, udl->origin);
VectorCopy(l->color, udl->color);

View file

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

View file

@ -449,7 +449,9 @@ extern qboolean GL3_ImageHasFreeSpace(void);
extern void GL3_ImageList_f(void);
// gl3_light.c
extern void GL3_MarkLights(dlight_t *light, int bit, mnode_t *node);
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_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
extern void GL3_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride);

View file

@ -208,6 +208,14 @@ extern void Mod_LoadSurfedges (const char *name, int **surfedges, int *numsurfed
const byte *mod_base, const lump_t *l, int extra);
extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra);
extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node);
/* 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);
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

@ -450,9 +450,6 @@ R_DrawSubmodelPolygons(entity_t *currententity, const model_t *currentmodel, int
}
}
static int c_drawnode;
/*
================
R_RecursiveWorldNode
@ -511,8 +508,6 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod
}
}
c_drawnode++;
// if a leaf node, draw stuff
if (node->contents != CONTENTS_NODE)
{
@ -631,8 +626,6 @@ R_RenderWorld (entity_t *currententity)
if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
return;
c_drawnode=0;
// auto cycle the world frame for texture animation
currententity->frame = (int)(r_newrefdef.time*2);

View file

@ -29,44 +29,15 @@ DYNAMIC LIGHTS
=============================================================================
*/
/*
=============
R_MarkLights
=============
*/
static void
R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
cplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
if (node->contents != CONTENTS_NODE)
return;
splitplane = node->plane;
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
i = light->intensity;
if (i < 0)
i = -i;
if (dist > i) // (dist > light->intensity)
{
R_MarkLights (light, bit, node->children[0], r_dlightframecount);
return;
}
if (dist < -i) // (dist < -light->intensity)
{
R_MarkLights (light, bit, node->children[1], r_dlightframecount);
return;
}
// mark the polygons
surf = r_worldmodel->surfaces + node->firstsurface;
for (i=0 ; i<node->numsurfaces ; i++, surf++)
for (i = 0; i < node->numsurfaces; i++, surf++)
{
if (surf->dlightframe != r_dlightframecount)
{
@ -75,12 +46,8 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
}
surf->dlightbits |= bit;
}
R_MarkLights (light, bit, node->children[0], r_dlightframecount);
R_MarkLights (light, bit, node->children[1], r_dlightframecount);
}
/*
=============
R_PushDlights
@ -96,7 +63,7 @@ R_PushDlights (const model_t *model)
{
R_MarkLights ( l, 1<<i,
model->nodes + model->firstnode,
r_framecount);
r_framecount, R_MarkSurfaceLights);
}
}
@ -334,7 +301,7 @@ R_AddDynamicLights (drawsurf_t* drawsurf)
dist = DotProduct (dl->origin, surf->plane->normal) -
surf->plane->dist;
rad -= fabs(dist);
minlight = 32; // dl->minlight;
minlight = DLIGHT_CUTOFF; // dl->minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;