Dynamic lighting fixes. (relative bmodel lighting, mainly)

This commit is contained in:
Forest Hale 2000-06-30 22:26:11 +00:00
parent e73700f4e8
commit 0793a90813
6 changed files with 32 additions and 29 deletions

View file

@ -214,31 +214,30 @@ R_MarkLights
*/ */
// LordHavoc: heavily modified, to eliminate unnecessary texture uploads, // LordHavoc: heavily modified, to eliminate unnecessary texture uploads,
// and support bmodel lighting better // and support bmodel lighting better
void R_MarkLights (dlight_t *light, int bit, mnode_t *node) void R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, mnode_t *node)
{ {
mplane_t *splitplane; mplane_t *splitplane;
float dist, l, maxdist; float dist, l, maxdist;
msurface_t *surf; msurface_t *surf;
int i, j, s, t; int i, j, s, t;
vec3_t impact, lightorigin; vec3_t impact;
if (node->contents < 0) if (node->contents < 0)
return; return;
VectorSubtract(light->origin, currententity->origin, lightorigin);
splitplane = node->plane; splitplane = node->plane;
dist = DotProduct (lightorigin, splitplane->normal) - splitplane->dist; dist = DotProduct (lightorigin, splitplane->normal) - splitplane->dist;
if (dist > light->radius) if (dist > light->radius)
{ {
if (node->children[0]->contents >= 0) // save some time by not pushing another stack frame if (node->children[0]->contents >= 0) // save some time by not pushing another stack frame
R_MarkLights (light, bit, node->children[0]); R_MarkLights (lightorigin, light, bit, node->children[0]);
return; return;
} }
if (dist < -light->radius) if (dist < -light->radius)
{ {
if (node->children[1]->contents >= 0) // save some time by not pushing another stack frame if (node->children[1]->contents >= 0) // save some time by not pushing another stack frame
R_MarkLights (light, bit, node->children[1]); R_MarkLights (lightorigin, light, bit, node->children[1]);
return; return;
} }
@ -273,9 +272,9 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
} }
if (node->children[0]->contents >= 0) // save some time by not pushing another stack frame if (node->children[0]->contents >= 0) // save some time by not pushing another stack frame
R_MarkLights (light, bit, node->children[0]); R_MarkLights (lightorigin, light, bit, node->children[0]);
if (node->children[1]->contents >= 0) // save some time by not pushing another stack frame if (node->children[1]->contents >= 0) // save some time by not pushing another stack frame
R_MarkLights (light, bit, node->children[1]); R_MarkLights (lightorigin, light, bit, node->children[1]);
} }
@ -284,10 +283,11 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
R_PushDlights R_PushDlights
============= =============
*/ */
void R_PushDlights (void) void R_PushDlights (vec3_t entorigin)
{ {
int i; int i;
dlight_t *l; dlight_t *l;
vec3_t lightorigin;
if (gl_flashblend->value) if (gl_flashblend->value)
return; return;
@ -300,7 +300,8 @@ void R_PushDlights (void)
{ {
if (l->die < cl.time || !l->radius) if (l->die < cl.time || !l->radius)
continue; continue;
R_MarkLights ( l, 1<<i, cl.worldmodel->nodes ); VectorSubtract(l->origin, entorigin, lightorigin);
R_MarkLights (lightorigin, l, 1<<i, cl.worldmodel->nodes );
} }
} }

View file

@ -861,13 +861,15 @@ void R_DrawBrushModel (entity_t *e)
// instanced model // instanced model
if (clmodel->firstmodelsurface != 0 && !gl_flashblend->value) if (clmodel->firstmodelsurface != 0 && !gl_flashblend->value)
{ {
vec3_t lightorigin;
for (k=0 ; k<MAX_DLIGHTS ; k++) for (k=0 ; k<MAX_DLIGHTS ; k++)
{ {
if ((cl_dlights[k].die < cl.time) || if ((cl_dlights[k].die < cl.time) ||
(!cl_dlights[k].radius)) (!cl_dlights[k].radius))
continue; continue;
R_MarkLights (&cl_dlights[k], 1<<k, VectorSubtract(cl_dlights[k].origin, e->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1<<k,
clmodel->nodes + clmodel->hulls[0].firstclipnode); clmodel->nodes + clmodel->hulls[0].firstclipnode);
} }
} }
@ -1044,8 +1046,6 @@ void R_DrawWorld (void)
currententity = &ent; currententity = &ent;
R_PushDlights (); // LordHavoc: moved from V_RenderView to R_DrawWorld
glColor3f (1.0, 1.0, 1.0); glColor3f (1.0, 1.0, 1.0);
memset (lightmap_polys, 0, sizeof(lightmap_polys)); memset (lightmap_polys, 0, sizeof(lightmap_polys));
// Be sure to clear the skybox --KB // Be sure to clear the skybox --KB

View file

@ -76,7 +76,7 @@ DYNAMIC LIGHTS
R_MarkLights R_MarkLights
============= =============
*/ */
void R_MarkLights (dlight_t *light, int bit, mnode_t *node) void R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, mnode_t *node)
{ {
mplane_t *splitplane; mplane_t *splitplane;
float dist; float dist;
@ -87,16 +87,16 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
return; return;
splitplane = node->plane; splitplane = node->plane;
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist; dist = DotProduct (lightorigin, splitplane->normal) - splitplane->dist;
if (dist > light->radius) if (dist > light->radius)
{ {
R_MarkLights (light, bit, node->children[0]); R_MarkLights (lightorigin, light, bit, node->children[0]);
return; return;
} }
if (dist < -light->radius) if (dist < -light->radius)
{ {
R_MarkLights (light, bit, node->children[1]); R_MarkLights (lightorigin, light, bit, node->children[1]);
return; return;
} }
@ -112,8 +112,8 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
surf->dlightbits |= bit; surf->dlightbits |= bit;
} }
R_MarkLights (light, bit, node->children[0]); R_MarkLights (lightorigin, light, bit, node->children[0]);
R_MarkLights (light, bit, node->children[1]); R_MarkLights (lightorigin, light, bit, node->children[1]);
} }
@ -122,10 +122,11 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
R_PushDlights R_PushDlights
============= =============
*/ */
void R_PushDlights (void) void R_PushDlights (vec3_t entorigin)
{ {
int i; int i;
dlight_t *l; dlight_t *l;
vec3_t lightorigin;
r_dlightframecount = r_framecount + 1; // because the count hasn't r_dlightframecount = r_framecount + 1; // because the count hasn't
// advanced yet for this frame // advanced yet for this frame
@ -135,7 +136,8 @@ void R_PushDlights (void)
{ {
if (l->die < cl.time || !l->radius) if (l->die < cl.time || !l->radius)
continue; continue;
R_MarkLights ( l, 1<<i, cl.worldmodel->nodes ); VectorSubtract(l->origin, entorigin, lightorigin);
R_MarkLights (lightorigin, l, 1<<i, cl.worldmodel->nodes );
} }
} }

View file

@ -831,15 +831,15 @@ void R_DrawBEntitiesOnList (void)
// instanced model // instanced model
if (clmodel->firstmodelsurface != 0) if (clmodel->firstmodelsurface != 0)
{ {
vec3_t lightorigin;
for (k=0 ; k<MAX_DLIGHTS ; k++) for (k=0 ; k<MAX_DLIGHTS ; k++)
{ {
if ((cl_dlights[k].die < cl.time) || if ((cl_dlights[k].die < cl.time) ||
(!cl_dlights[k].radius)) (!cl_dlights[k].radius))
{
continue; continue;
}
R_MarkLights (&cl_dlights[k], 1<<k, VectorSubtract(cl_dlights[k].origin, currententity->origin, lightorigin);
R_MarkLights (lightorigin, &cl_dlights[k], 1<<k,
clmodel->nodes + clmodel->hulls[0].firstclipnode); clmodel->nodes + clmodel->hulls[0].firstclipnode);
} }
} }

View file

@ -75,7 +75,7 @@ void R_AddDynamicLights (void)
int lnum; int lnum;
int sd, td; int sd, td;
float dist, rad, minlight; float dist, rad, minlight;
vec3_t impact, local; vec3_t impact, local, lightorigin;
int s, t; int s, t;
int i; int i;
int smax, tmax; int smax, tmax;
@ -91,8 +91,9 @@ void R_AddDynamicLights (void)
if ( !(surf->dlightbits & (1<<lnum) ) ) if ( !(surf->dlightbits & (1<<lnum) ) )
continue; // not lit by this light continue; // not lit by this light
VectorSubtract(cl_dlights[lnum].origin, currententity->origin, lightorigin);
rad = cl_dlights[lnum].radius; rad = cl_dlights[lnum].radius;
dist = DotProduct (cl_dlights[lnum].origin, surf->plane->normal) - dist = DotProduct (lightorigin, surf->plane->normal) -
surf->plane->dist; surf->plane->dist;
rad -= fabs(dist); rad -= fabs(dist);
minlight = cl_dlights[lnum].minlight; minlight = cl_dlights[lnum].minlight;
@ -101,10 +102,7 @@ void R_AddDynamicLights (void)
minlight = rad - minlight; minlight = rad - minlight;
for (i=0 ; i<3 ; i++) for (i=0 ; i<3 ; i++)
{ impact[i] = lightorigin[i] - surf->plane->normal[i]*dist;
impact[i] = cl_dlights[lnum].origin[i] -
surf->plane->normal[i]*dist;
}
local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3]; local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3];
local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3]; local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3];

View file

@ -811,6 +811,8 @@ void V_RenderView (void)
V_CalcRefdef (); V_CalcRefdef ();
} }
R_PushDlights (vec3_origin);
R_RenderView (); R_RenderView ();
} }