gl4: Prepare to share R_LightPoint

This commit is contained in:
Denis Pauk 2023-10-06 23:47:10 +03:00
parent b0835a92e6
commit 22095bb832
5 changed files with 43 additions and 17 deletions

View file

@ -107,16 +107,15 @@ GL4_PushDlights(void)
}
void
GL4_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;
float add;
if (!gl4_worldmodel->lightdata || !currententity)
if (!currententity)
{
color[0] = color[1] = color[2] = 1.0;
return;
@ -126,10 +125,8 @@ GL4_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
end[1] = p[1];
end[2] = p[2] - 2048;
// TODO: don't just aggregate the color, but also save position of brightest+nearest light
// for shadow position and maybe lighting on model?
r = R_RecursiveLightPoint(gl4_worldmodel->surfaces, gl4_worldmodel->nodes,
gl4_newrefdef.lightstyles, p, end, pointcolor, lightspot, r_modulate->value);
r = R_RecursiveLightPoint(surfaces, nodes, refdef->lightstyles,
p, end, pointcolor, lightspot, modulate);
if (r == -1)
{
@ -141,10 +138,12 @@ GL4_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
}
/* add dynamic lights */
dl = gl4_newrefdef.dlights;
dl = refdef->dlights;
for (lnum = 0; lnum < gl4_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);
@ -156,7 +155,7 @@ GL4_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
}
}
VectorScale(color, r_modulate->value, color);
VectorScale(color, modulate, color);
}

View file

@ -71,6 +71,8 @@ int c_brush_polys, c_alias_polys;
static float v_blend[4]; /* final blending color */
extern vec3_t lightspot;
int gl4_viewcluster, gl4_viewcluster2, gl4_oldviewcluster, gl4_oldviewcluster2;
const hmm_mat4 gl4_identityMat4 = {{
@ -934,13 +936,15 @@ GL4_DrawNullModel(entity_t *currententity)
{
vec3_t shadelight;
if (currententity->flags & RF_FULLBRIGHT)
if (currententity->flags & RF_FULLBRIGHT || !gl4_worldmodel || !gl4_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
{
GL4_LightPoint(currententity, currententity->origin, shadelight);
R_LightPoint(currententity, &gl4_newrefdef, gl4_worldmodel->surfaces,
gl4_worldmodel->nodes, currententity->origin, shadelight,
r_modulate->value, lightspot);
}
hmm_mat4 origModelMat = gl4state.uni3DData.transModelMat4;
@ -1715,7 +1719,9 @@ GL4_SetLightLevel(entity_t *currententity)
}
/* save off light value for server to look at */
GL4_LightPoint(currententity, gl4_newrefdef.vieworg, shadelight);
R_LightPoint(currententity, &gl4_newrefdef, gl4_worldmodel->surfaces,
gl4_worldmodel->nodes, gl4_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

@ -717,7 +717,24 @@ GL4_DrawAliasModel(entity_t *entity)
}
else
{
GL4_LightPoint(entity, entity->origin, shadelight);
if (gl4_worldmodel->grid)
{
BSPX_LightGridValue(gl4_worldmodel->grid, gl4_newrefdef.lightstyles,
entity->origin, shadelight);
}
else
{
if (!gl4_worldmodel || !gl4_worldmodel->lightdata)
{
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
}
else
{
R_LightPoint(entity, &gl4_newrefdef, gl4_worldmodel->surfaces,
gl4_worldmodel->nodes, entity->origin, shadelight,
r_modulate->value, lightspot);
}
}
/* player lighting hack for communication back to server */
if (entity->flags & RF_WEAPONMODEL)

View file

@ -457,7 +457,8 @@ 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_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
extern 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);
extern void GL4_BuildLightMap(msurface_t *surf, int offsetInLMbuf, int stride);
// gl4_lightmap.c

View file

@ -106,6 +106,9 @@ typedef struct model_s
// submodules
vec3_t origin; // for sounds or lights
/* octree */
bspxlightgrid_t *grid;
} gl4model_t;
#endif /* SRC_CLIENT_REFRESH_GL4_HEADER_MODEL_H_ */