mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +00:00
port over gl's lighting improvements. only gives ~4.6% improvement on my c600
but that's better than nothing. (34.41 to 36.00)
This commit is contained in:
parent
c64c31b2e9
commit
a81828fe38
3 changed files with 147 additions and 26 deletions
|
@ -456,7 +456,7 @@ R_RecursiveWorldNode (mnode_t *node, int clipflags)
|
||||||
|
|
||||||
if (c) {
|
if (c) {
|
||||||
do {
|
do {
|
||||||
(*mark)->visframe = r_framecount;
|
(*mark)->visframe = r_visframecount;
|
||||||
mark++;
|
mark++;
|
||||||
} while (--c);
|
} while (--c);
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ R_RecursiveWorldNode (mnode_t *node, int clipflags)
|
||||||
if (dot < -BACKFACE_EPSILON) {
|
if (dot < -BACKFACE_EPSILON) {
|
||||||
do {
|
do {
|
||||||
if ((surf->flags & SURF_PLANEBACK) &&
|
if ((surf->flags & SURF_PLANEBACK) &&
|
||||||
(surf->visframe == r_framecount)) {
|
(surf->visframe == r_visframecount)) {
|
||||||
if (r_drawpolys) {
|
if (r_drawpolys) {
|
||||||
if (r_worldpolysbacktofront) {
|
if (r_worldpolysbacktofront) {
|
||||||
if (numbtofpolys < MAX_BTOFPOLYS) {
|
if (numbtofpolys < MAX_BTOFPOLYS) {
|
||||||
|
@ -527,7 +527,7 @@ R_RecursiveWorldNode (mnode_t *node, int clipflags)
|
||||||
} else if (dot > BACKFACE_EPSILON) {
|
} else if (dot > BACKFACE_EPSILON) {
|
||||||
do {
|
do {
|
||||||
if (!(surf->flags & SURF_PLANEBACK) &&
|
if (!(surf->flags & SURF_PLANEBACK) &&
|
||||||
(surf->visframe == r_framecount)) {
|
(surf->visframe == r_visframecount)) {
|
||||||
if (r_drawpolys) {
|
if (r_drawpolys) {
|
||||||
if (r_worldpolysbacktofront) {
|
if (r_worldpolysbacktofront) {
|
||||||
if (numbtofpolys < MAX_BTOFPOLYS) {
|
if (numbtofpolys < MAX_BTOFPOLYS) {
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
#include "r_local.h"
|
#include "r_local.h"
|
||||||
|
|
||||||
int r_dlightframecount;
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
R_AnimateLight (void)
|
R_AnimateLight (void)
|
||||||
|
@ -64,40 +62,167 @@ R_AnimateLight (void)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, model_t *model)
|
R_RecursiveMarkLights (vec3_t lightorigin, dlight_t *light, int bit,
|
||||||
|
mnode_t *node)
|
||||||
{
|
{
|
||||||
mnode_t *node = (mnode_t *)model;//FIXME evilness
|
|
||||||
mplane_t *splitplane;
|
mplane_t *splitplane;
|
||||||
float dist;
|
float ndist, maxdist;
|
||||||
msurface_t *surf;
|
msurface_t *surf;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
maxdist = light->radius * light->radius;
|
||||||
|
loc0:
|
||||||
if (node->contents < 0)
|
if (node->contents < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
splitplane = node->plane;
|
splitplane = node->plane;
|
||||||
dist = DotProduct (lightorigin, splitplane->normal) - splitplane->dist;
|
ndist = DotProduct (lightorigin, splitplane->normal) - splitplane->dist;
|
||||||
|
|
||||||
if (dist > light->radius) {
|
if (ndist > light->radius) {
|
||||||
R_MarkLights (lightorigin, light, bit, (model_t*)node->children[0]);
|
if (node->children[0]->contents >= 0) {
|
||||||
|
node = node->children[0];
|
||||||
|
goto loc0;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (dist < -light->radius) {
|
if (ndist < -light->radius) {
|
||||||
R_MarkLights (lightorigin, light, bit, (model_t*)node->children[1]);
|
if (node->children[1]->contents >= 0) {
|
||||||
|
node = node->children[1];
|
||||||
|
goto loc0;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// mark the polygons
|
// mark the polygons
|
||||||
surf = r_worldentity.model->surfaces + node->firstsurface;
|
surf = r_worldentity.model->surfaces + node->firstsurface;
|
||||||
for (i = 0; i < node->numsurfaces; i++, surf++) {
|
for (i = 0; i < node->numsurfaces; i++, surf++) {
|
||||||
if (surf->dlightframe != r_dlightframecount) {
|
if (surf->dlightframe != r_framecount) {
|
||||||
surf->dlightbits = 0;
|
surf->dlightbits = 0;
|
||||||
surf->dlightframe = r_dlightframecount;
|
surf->dlightframe = r_framecount;
|
||||||
}
|
}
|
||||||
surf->dlightbits |= bit;
|
surf->dlightbits |= bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
R_MarkLights (lightorigin, light, bit, (model_t*)node->children[0]);
|
if (node->children[0]->contents >= 0) {
|
||||||
R_MarkLights (lightorigin, light, bit, (model_t*)node->children[1]);
|
if (node->children[1]->contents >= 0)
|
||||||
|
R_RecursiveMarkLights (lightorigin, light, bit, node->children[1]);
|
||||||
|
node = node->children[0];
|
||||||
|
goto loc0;
|
||||||
|
} else if (node->children[1]->contents >= 0) {
|
||||||
|
node = node->children[1];
|
||||||
|
goto loc0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mark_surfaces (msurface_t *surf, vec3_t lightorigin, dlight_t *light,
|
||||||
|
int bit)
|
||||||
|
{
|
||||||
|
float dist;
|
||||||
|
#if 1
|
||||||
|
float dist2, d;
|
||||||
|
float maxdist = light->radius * light->radius;
|
||||||
|
vec3_t impact;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dist = PlaneDiff(lightorigin, surf->plane);
|
||||||
|
if (surf->flags & SURF_PLANEBACK)
|
||||||
|
dist = -dist;
|
||||||
|
if ((dist < -0.25f && !(surf->flags & SURF_LIGHTBOTHSIDES))
|
||||||
|
|| dist > light->radius)
|
||||||
|
return;
|
||||||
|
#if 1
|
||||||
|
dist2 = dist * dist;
|
||||||
|
dist = -dist;
|
||||||
|
VectorMA (light->origin, dist, surf->plane->normal, impact);
|
||||||
|
|
||||||
|
d = DotProduct (impact, surf->texinfo->vecs[0])
|
||||||
|
+ surf->texinfo->vecs[0][3] - surf->texturemins[0];
|
||||||
|
if (d < 0) {
|
||||||
|
dist2 += d * d;
|
||||||
|
if (dist2 >= maxdist)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
d -= surf->extents[0] + 16;
|
||||||
|
if (d > 0) {
|
||||||
|
dist2 += d * d;
|
||||||
|
if (dist2 >= maxdist)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d = DotProduct (impact, surf->texinfo->vecs[1])
|
||||||
|
+ surf->texinfo->vecs[1][3] - surf->texturemins[1];
|
||||||
|
if (d < 0) {
|
||||||
|
dist2 += d * d;
|
||||||
|
if (dist2 >= maxdist)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
d -= surf->extents[1] + 16;
|
||||||
|
if (d > 0) {
|
||||||
|
dist2 += d * d;
|
||||||
|
if (dist2 >= maxdist)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (surf->dlightframe != r_framecount) {
|
||||||
|
surf->dlightbits = 0;
|
||||||
|
surf->dlightframe = r_framecount;
|
||||||
|
}
|
||||||
|
surf->dlightbits |= bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, model_t *model)
|
||||||
|
{
|
||||||
|
mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
|
||||||
|
|
||||||
|
if (!pvsleaf->compressed_vis) {
|
||||||
|
mnode_t *node = model->nodes + model->hulls[0].firstclipnode;
|
||||||
|
R_RecursiveMarkLights (lightorigin, light, bit, node);
|
||||||
|
} else {
|
||||||
|
float radius = light->radius;
|
||||||
|
vec3_t mins, maxs;
|
||||||
|
int leafnum = 0;
|
||||||
|
byte *in = pvsleaf->compressed_vis;
|
||||||
|
byte vis_bits;
|
||||||
|
|
||||||
|
mins[0] = lightorigin[0] - radius;
|
||||||
|
mins[1] = lightorigin[1] - radius;
|
||||||
|
mins[2] = lightorigin[2] - radius;
|
||||||
|
maxs[0] = lightorigin[0] + radius;
|
||||||
|
maxs[1] = lightorigin[1] + radius;
|
||||||
|
maxs[2] = lightorigin[2] + radius;
|
||||||
|
while (leafnum < model->numleafs) {
|
||||||
|
int i;
|
||||||
|
if (!(vis_bits = *in++)) {
|
||||||
|
leafnum += (*in++) * 8;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = 0; i < 8 && leafnum < model->numleafs; i++, leafnum++) {
|
||||||
|
int m;
|
||||||
|
mleaf_t *leaf = &model->leafs[leafnum + 1];
|
||||||
|
if (!(vis_bits & (1 << i)))
|
||||||
|
continue;
|
||||||
|
if (leaf->visframe != r_visframecount)
|
||||||
|
continue;
|
||||||
|
if (leaf->mins[0] > maxs[0] || leaf->maxs[0] < mins[0]
|
||||||
|
|| leaf->mins[1] > maxs[1] || leaf->maxs[1] < mins[1]
|
||||||
|
|| leaf->mins[2] > maxs[2] || leaf->maxs[2] < mins[2])
|
||||||
|
continue;
|
||||||
|
if (leaf->dlightframe != r_framecount) {
|
||||||
|
leaf->dlightbits = 0;
|
||||||
|
leaf->dlightframe = r_framecount;
|
||||||
|
}
|
||||||
|
leaf->dlightbits |= bit;
|
||||||
|
for (m = 0; m < leaf->nummarksurfaces; m++) {
|
||||||
|
msurface_t *surf = leaf->firstmarksurface[m];
|
||||||
|
if (surf->visframe != r_visframecount)
|
||||||
|
continue;
|
||||||
|
mark_surfaces (surf, lightorigin, light, bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,15 +233,13 @@ R_PushDlights (vec3_t entorigin)
|
||||||
dlight_t *l;
|
dlight_t *l;
|
||||||
vec3_t lightorigin;
|
vec3_t lightorigin;
|
||||||
|
|
||||||
r_dlightframecount = r_framecount + 1; // because the count hasn't
|
|
||||||
// advanced yet for this frame
|
|
||||||
l = r_dlights;
|
l = r_dlights;
|
||||||
|
|
||||||
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
|
for (i = 0; i < MAX_DLIGHTS; i++, l++) {
|
||||||
if (l->die < r_realtime || !l->radius)
|
if (l->die < r_realtime || !l->radius)
|
||||||
continue;
|
continue;
|
||||||
VectorSubtract (l->origin, entorigin, lightorigin);
|
VectorSubtract (l->origin, entorigin, lightorigin);
|
||||||
R_MarkLights (lightorigin, l, 1 << i, (model_t*)r_worldentity.model->nodes);
|
R_MarkLights (lightorigin, l, 1 << i, r_worldentity.model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -671,7 +671,6 @@ R_DrawBEntitiesOnList (void)
|
||||||
|
|
||||||
VectorCopy (modelorg, oldorigin);
|
VectorCopy (modelorg, oldorigin);
|
||||||
insubmodel = true;
|
insubmodel = true;
|
||||||
r_dlightframecount = r_framecount;
|
|
||||||
|
|
||||||
for (i = 0; i < r_numvisedicts; i++) {
|
for (i = 0; i < r_numvisedicts; i++) {
|
||||||
currententity = r_visedicts[i];
|
currententity = r_visedicts[i];
|
||||||
|
@ -713,10 +712,9 @@ R_DrawBEntitiesOnList (void)
|
||||||
|
|
||||||
VectorSubtract (r_dlights[k].origin,
|
VectorSubtract (r_dlights[k].origin,
|
||||||
currententity->origin, lightorigin);
|
currententity->origin, lightorigin);
|
||||||
R_MarkLights (lightorigin, &r_dlights[k], 1 << k,
|
R_RecursiveMarkLights (lightorigin, &r_dlights[k], 1 << k,
|
||||||
(model_t*)(//FIXME this is so evil
|
|
||||||
clmodel->nodes +
|
clmodel->nodes +
|
||||||
clmodel->hulls[0].firstclipnode));
|
clmodel->hulls[0].firstclipnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the driver wants polygons, deliver those.
|
// if the driver wants polygons, deliver those.
|
||||||
|
@ -852,12 +850,12 @@ R_RenderView_ (void)
|
||||||
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
|
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
|
||||||
r_time1 = Sys_DoubleTime ();
|
r_time1 = Sys_DoubleTime ();
|
||||||
|
|
||||||
R_PushDlights (vec3_origin);
|
|
||||||
|
|
||||||
R_SetupFrame ();
|
R_SetupFrame ();
|
||||||
|
|
||||||
R_MarkLeaves (); // done here so we know if we're in water
|
R_MarkLeaves (); // done here so we know if we're in water
|
||||||
|
|
||||||
|
R_PushDlights (vec3_origin);
|
||||||
|
|
||||||
// make FDIV fast. This reduces timing precision after we've been running for a
|
// make FDIV fast. This reduces timing precision after we've been running for a
|
||||||
// while, so we don't do it globally. This also sets chop mode, and we do it
|
// while, so we don't do it globally. This also sets chop mode, and we do it
|
||||||
// here so that setup stuff like the refresh area calculations match what's
|
// here so that setup stuff like the refresh area calculations match what's
|
||||||
|
|
Loading…
Reference in a new issue