Bugfix - make dlights move correctly with respect to moving bsp entities, instead of the light being in the wrong place.

Obviously this doesn't affect baked lights, but at least mappers have more control over those.
This commit is contained in:
Spike 2018-05-25 11:54:33 +01:00 committed by Shpoike
parent 9d1c386a1b
commit f6d31e9db9
4 changed files with 18 additions and 12 deletions

View file

@ -166,7 +166,7 @@ DYNAMIC LIGHTS
R_MarkLights -- johnfitz -- rewritten to use LordHavoc's lighting speedup R_MarkLights -- johnfitz -- rewritten to use LordHavoc's lighting speedup
============= =============
*/ */
void R_MarkLights (dlight_t *light, int num, mnode_t *node) void R_MarkLights (dlight_t *light, vec3_t lightorg, int num, mnode_t *node)
{ {
mplane_t *splitplane; mplane_t *splitplane;
msurface_t *surf; msurface_t *surf;
@ -182,9 +182,9 @@ start:
splitplane = node->plane; splitplane = node->plane;
if (splitplane->type < 3) if (splitplane->type < 3)
dist = light->origin[splitplane->type] - splitplane->dist; dist = lightorg[splitplane->type] - splitplane->dist;
else else
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist; dist = DotProduct (lightorg, splitplane->normal) - splitplane->dist;
if (dist > light->radius) if (dist > light->radius)
{ {
@ -203,7 +203,7 @@ start:
for (i=0 ; i<node->numsurfaces ; i++, surf++) for (i=0 ; i<node->numsurfaces ; i++, surf++)
{ {
for (j=0 ; j<3 ; j++) for (j=0 ; j<3 ; j++)
impact[j] = light->origin[j] - surf->plane->normal[j]*dist; impact[j] = lightorg[j] - surf->plane->normal[j]*dist;
// clamp center of light to corner and check brightness // clamp center of light to corner and check brightness
l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0]; l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
s = l+0.5;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0]; s = l+0.5;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0];
@ -225,9 +225,9 @@ start:
} }
if (node->children[0]->contents >= 0) if (node->children[0]->contents >= 0)
R_MarkLights (light, num, node->children[0]); R_MarkLights (light, lightorg, num, node->children[0]);
if (node->children[1]->contents >= 0) if (node->children[1]->contents >= 0)
R_MarkLights (light, num, node->children[1]); R_MarkLights (light, lightorg, num, node->children[1]);
} }
/* /*
@ -251,7 +251,7 @@ void R_PushDlights (void)
{ {
if (l->die < cl.time || !l->radius) if (l->die < cl.time || !l->radius)
continue; continue;
R_MarkLights (l, i, cl.worldmodel->nodes); R_MarkLights (l, l->origin, i, cl.worldmodel->nodes);
} }
} }

View file

@ -917,6 +917,8 @@ R_RenderScene
*/ */
void R_RenderScene (void) void R_RenderScene (void)
{ {
static entity_t r_worldentity; //so we can make sure currententity is valid
currententity = &r_worldentity;
R_SetupScene (); //johnfitz -- this does everything that should be done once per call to RenderScene R_SetupScene (); //johnfitz -- this does everything that should be done once per call to RenderScene
Fog_EnableGFog (); //johnfitz Fog_EnableGFog (); //johnfitz
@ -924,6 +926,7 @@ void R_RenderScene (void)
Sky_DrawSky (); //johnfitz Sky_DrawSky (); //johnfitz
R_DrawWorld (); R_DrawWorld ();
currententity = NULL;
S_ExtraUpdate (); // don't let sound get messed up if going slow S_ExtraUpdate (); // don't let sound get messed up if going slow

View file

@ -376,7 +376,7 @@ qboolean R_CullBox (vec3_t emins, vec3_t emaxs);
void R_StoreEfrags (efrag_t **ppefrag); void R_StoreEfrags (efrag_t **ppefrag);
qboolean R_CullModelForEntity (entity_t *e); qboolean R_CullModelForEntity (entity_t *e);
void R_RotateForEntity (vec3_t origin, vec3_t angles, unsigned char scale); void R_RotateForEntity (vec3_t origin, vec3_t angles, unsigned char scale);
void R_MarkLights (dlight_t *light, int num, mnode_t *node); void R_MarkLights (dlight_t *light, vec3_t lightorg, int num, mnode_t *node);
void R_InitParticles (void); void R_InitParticles (void);
void R_DrawParticles (void); void R_DrawParticles (void);

View file

@ -504,6 +504,7 @@ void R_DrawBrushModel (entity_t *e)
float dot; float dot;
mplane_t *pplane; mplane_t *pplane;
qmodel_t *clmodel; qmodel_t *clmodel;
vec3_t lightorg;
if (R_CullModelForEntity(e)) if (R_CullModelForEntity(e))
return; return;
@ -536,7 +537,8 @@ void R_DrawBrushModel (entity_t *e)
(!cl_dlights[k].radius)) (!cl_dlights[k].radius))
continue; continue;
R_MarkLights (&cl_dlights[k], k, VectorSubtract(cl_dlights[k].origin, e->origin, lightorg);
R_MarkLights (&cl_dlights[k], lightorg, k,
clmodel->nodes + clmodel->hulls[0].firstclipnode); clmodel->nodes + clmodel->hulls[0].firstclipnode);
} }
} }
@ -1057,6 +1059,7 @@ void R_AddDynamicLights (msurface_t *surf)
float cred, cgreen, cblue, brightness; float cred, cgreen, cblue, brightness;
unsigned *bl; unsigned *bl;
//johnfitz //johnfitz
vec3_t lightofs; //Spike: light surfaces based upon where they are now instead of their default position.
int lmscale; int lmscale;
smax = (surf->extents[0]>>surf->lmshift)+1; smax = (surf->extents[0]>>surf->lmshift)+1;
@ -1070,8 +1073,8 @@ void R_AddDynamicLights (msurface_t *surf)
continue; // not lit by this light continue; // not lit by this light
rad = cl_dlights[lnum].radius; rad = cl_dlights[lnum].radius;
dist = DotProduct (cl_dlights[lnum].origin, surf->plane->normal) - VectorSubtract(cl_dlights[lnum].origin, currententity->origin, lightofs);
surf->plane->dist; dist = DotProduct (lightofs, surf->plane->normal) - surf->plane->dist;
rad -= fabs(dist); rad -= fabs(dist);
minlight = cl_dlights[lnum].minlight; minlight = cl_dlights[lnum].minlight;
if (rad < minlight) if (rad < minlight)
@ -1080,7 +1083,7 @@ void R_AddDynamicLights (msurface_t *surf)
for (i=0 ; i<3 ; i++) for (i=0 ; i<3 ; i++)
{ {
impact[i] = cl_dlights[lnum].origin[i] - impact[i] = lightofs[i] -
surf->plane->normal[i]*dist; surf->plane->normal[i]*dist;
} }