gl1: Prepare to share R_LightPoint

This commit is contained in:
Denis Pauk 2023-10-06 23:15:53 +03:00
parent 8f5a40710b
commit 7fd23f07db
8 changed files with 103 additions and 92 deletions

View File

@ -132,6 +132,12 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
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)
@ -148,12 +154,6 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
continue;
}
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
surf->dlightbits |= bit;
}
}
@ -161,8 +161,8 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
void
R_PushDlights(void)
{
int i;
dlight_t *l;
int i;
if (gl1_flashblend->value)
{
@ -182,15 +182,15 @@ R_PushDlights(void)
}
void
R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
R_LightPoint(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)
{
vec3_t end;
vec3_t end, dist;
float r;
int lnum;
dlight_t *dl;
vec3_t dist;
if (!r_worldmodel || !r_worldmodel->lightdata || !currententity)
if (!currententity)
{
color[0] = color[1] = color[2] = 1.0;
return;
@ -200,8 +200,8 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
end[1] = p[1];
end[2] = p[2] - 2048;
r = R_RecursiveLightPoint(r_worldmodel->surfaces, r_worldmodel->nodes,
r_newrefdef.lightstyles, p, end, pointcolor, lightspot, r_modulate->value);
r = R_RecursiveLightPoint(surfaces, nodes, refdef->lightstyles,
p, end, pointcolor, lightspot, modulate);
if (r == -1)
{
@ -213,16 +213,16 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
}
/* add dynamic lights */
dl = r_newrefdef.dlights;
dl = refdef->dlights;
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++)
for (lnum = 0; lnum < refdef->num_dlights; lnum++, dl++)
{
float add;
VectorSubtract(currententity->origin,
dl->origin, dist);
add = dl->intensity - VectorLength(dist);
add *= (1.0 / 256);
add *= (1.0f / 256.0f);
if (add > 0)
{
@ -230,7 +230,7 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
}
}
VectorScale(color, r_modulate->value, color);
VectorScale(color, modulate, color);
}
void
@ -478,7 +478,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
}
store:
/* put into texture format */
stride -= (smax << 2);
bl = s_blocklights;

View File

@ -32,6 +32,7 @@ viddef_t vid;
model_t *r_worldmodel;
float gldepthmin, gldepthmax;
extern vec3_t lightspot;
glconfig_t gl_config;
glstate_t gl_state;
@ -250,13 +251,15 @@ R_DrawNullModel(entity_t *currententity)
{
vec3_t shadelight;
if (currententity->flags & RF_FULLBRIGHT)
if (currententity->flags & RF_FULLBRIGHT || !r_worldmodel || !r_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
{
R_LightPoint(currententity, currententity->origin, shadelight);
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, currententity->origin, shadelight,
r_modulate->value, lightspot);
}
glPushMatrix();
@ -1122,7 +1125,9 @@ R_SetLightLevel(entity_t *currententity)
}
/* save off light value for server to look at */
R_LightPoint(currententity, r_newrefdef.vieworg, shadelight);
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, r_newrefdef.vieworg, shadelight,
r_modulate->value, lightspot);
/* pick the greatest component, which should be the
* same as the mono value returned by software */

View File

@ -678,7 +678,16 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
}
else
{
R_LightPoint(currententity, currententity->origin, shadelight);
if (!r_worldmodel || !r_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
{
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
r_worldmodel->nodes, currententity->origin, shadelight,
r_modulate->value, lightspot);
}
}
/* player lighting hack for communication back to server */

View File

@ -249,7 +249,8 @@ void R_Bind(int texnum);
void R_TexEnv(GLenum value);
void R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
void R_LightPoint(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);
void R_PushDlights(void);
extern model_t *r_worldmodel;

View File

@ -76,8 +76,8 @@ GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframe
void
GL3_PushDlights(void)
{
int i;
dlight_t *l;
int i;
/* because the count hasn't advanced yet for this frame */
r_dlightframecount = gl3_framecount + 1;
@ -109,12 +109,10 @@ GL3_PushDlights(void)
void
GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
{
vec3_t end;
vec3_t end, dist;
float r;
int lnum;
dlight_t *dl;
vec3_t dist;
float add;
if (!gl3_worldmodel->lightdata || !currententity)
{
@ -145,6 +143,8 @@ GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
for (lnum = 0; lnum < gl3_newrefdef.num_dlights; lnum++, dl++)
{
float add;
VectorSubtract(currententity->origin,
dl->origin, dist);
add = dl->intensity - VectorLength(dist);

View File

@ -84,7 +84,7 @@ R_LightPoint
===============
*/
void
R_LightPoint (const entity_t *currententity, vec3_t p, vec3_t color)
R_LightPoint(const entity_t *currententity, vec3_t p, vec3_t color)
{
vec3_t end;
float r;

View File

@ -517,7 +517,7 @@ R_DrawSpanlet66Stipple(const int *r_turb_turb)
** Throws out the back side
*/
static int
R_ClipPolyFace (int nump, clipplane_t *pclipplane)
R_ClipPolyFace(int nump, clipplane_t *pclipplane)
{
int i, outcount;
float frac, clipdist, *pclipnormal;
@ -1045,7 +1045,7 @@ R_BuildPolygonFromSurface(const entity_t *currententity, const model_t *currentm
r_polydesc.nump = 0;
// reconstruct the polygon
/* reconstruct the polygon */
pedges = currentmodel->edges;
lnumverts = fa->numedges;

View File

@ -23,12 +23,12 @@
* Lightmaps and dynamic lighting
*
* =======================================================================
*
*/
#include "header/local.h"
int r_dlightframecount;
int r_dlightframecount;
vec3_t lightspot;
static void
R_RenderDlight(dlight_t *light)
@ -83,40 +83,28 @@ R_RenderDlight(dlight_t *light)
vkCmdDrawIndexed(vk_activeCmdbuffer, 48, 1, 0, 0, 0);
}
/*
=============
R_RenderDlights
=============
*/
void
R_RenderDlights(void)
{
int i;
dlight_t *l;
int i;
dlight_t *l;
if (!vk_flashblend->value)
{
return;
}
r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame
/* because the count hasn't advanced yet for this frame */
r_dlightframecount = r_framecount + 1;
l = r_newrefdef.dlights;
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
{
R_RenderDlight(l);
}
}
/*
=============================================================================
DYNAMIC LIGHTS
=============================================================================
*/
void
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
{
@ -128,6 +116,25 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
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)
{
sidebit = 0;
}
else
{
sidebit = SURF_PLANEBACK;
}
if ((surf->flags & SURF_PLANEBACK) != sidebit)
{
continue;
}
if (surf->dlightframe != r_dlightframecount)
{
surf->dlightbits = 0;
@ -141,8 +148,8 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
void
R_PushDlights(void)
{
dlight_t *l;
int i;
dlight_t *l;
int i;
if (vk_flashblend->value)
{
@ -161,25 +168,13 @@ R_PushDlights(void)
}
}
/*
=============================================================================
LIGHT SAMPLING
=============================================================================
*/
vec3_t lightspot;
void
R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
{
vec3_t end, pointcolor, dist;
float r;
int lnum;
dlight_t *dl;
vec3_t end, pointcolor, dist;
float r;
int lnum;
dlight_t *dl;
if (!r_worldmodel->lightdata || !currententity)
{
@ -227,16 +222,16 @@ R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
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;
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;
@ -270,12 +265,13 @@ R_AddDynamicLights(msurface_t *surf)
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];
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;
@ -341,13 +337,13 @@ float *s_blocklights = NULL, *s_blocklights_max = NULL;
void
R_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 mapscount;
float *bl;
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))
@ -394,15 +390,15 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
}
/* count the # of maps */
for (mapscount = 0; mapscount < MAXLIGHTMAPS && surf->styles[mapscount] != 255 ;
mapscount++)
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255;
nummaps++)
{
}
lightmap = surf->samples;
/* add all the lightmaps */
if (mapscount == 1)
if (nummaps == 1)
{
int maps;