#include "quakedef.h"
-cvar_t r_lightmodels = {"r_lightmodels", "1"};
+cvar_t r_lightmodels = {0, "r_lightmodels", "1"};
-extern cvar_t gl_transform;
+void r_light_start(void)
+{
+}
-void r_light_start()
+void r_light_shutdown(void)
{
}
-void r_light_shutdown()
+void r_light_newmap(void)
{
}
-void R_Light_Init()
+void R_Light_Init(void)
{
Cvar_RegisterVariable(&r_lightmodels);
- R_RegisterModule("R_Light", r_light_start, r_light_shutdown);
+ R_RegisterModule("R_Light", r_light_start, r_light_shutdown, r_light_newmap);
}
-int r_dlightframecount;
-
/*
==================
R_AnimateLight
{
float ndist, maxdist;
msurface_t *surf;
+ mleaf_t *leaf;
int i;
if (!r_dynamic.value)
loc0:
if (node->contents < 0)
+ {
+ if (node->contents != CONTENTS_SOLID)
+ {
+ leaf = (mleaf_t *)node;
+ if (leaf->dlightframe != r_framecount) // not dynamic until now
+ {
+ leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
+ leaf->dlightframe = r_framecount;
+ }
+ leaf->dlightbits[bitindex] |= bit;
+ }
return;
+ }
ndist = PlaneDiff(lightorigin, node->plane);
if (ndist > light->radius)
{
- if (node->children[0]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
- {
- node = node->children[0];
- goto loc0;
- }
- return;
+ node = node->children[0];
+ goto loc0;
}
if (ndist < -light->radius)
{
- if (node->children[1]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
- {
- node = node->children[1];
- goto loc0;
- }
- return;
- }
-
- if (node->dlightframe != r_dlightframecount) // not dynamic until now
- {
- node->dlightbits[0] = node->dlightbits[1] = node->dlightbits[2] = node->dlightbits[3] = node->dlightbits[4] = node->dlightbits[5] = node->dlightbits[6] = node->dlightbits[7] = 0;
- node->dlightframe = r_dlightframecount;
+ node = node->children[1];
+ goto loc0;
}
- node->dlightbits[bitindex] |= bit;
// mark the polygons
surf = cl.worldmodel->surfaces + node->firstsurface;
{
int d;
float dist, dist2, impact[3];
+ if (surf->visframe != r_framecount)
+ continue;
dist = ndist;
if (surf->flags & SURF_PLANEBACK)
dist = -dist;
}
}
- if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+ if (surf->dlightframe != r_framecount) // not dynamic until now
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
- surf->dlightframe = r_dlightframecount;
+ surf->dlightframe = r_framecount;
}
surf->dlightbits[bitindex] |= bit;
/*
if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
{
- if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+ if (surf->dlightframe != r_framecount) // not dynamic until now
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
- surf->dlightframe = r_dlightframecount;
+ surf->dlightframe = r_framecount;
}
surf->dlightbits[bitindex] |= bit;
}
R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
}
-int lightframe = 0;
void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
{
+ static int lightframe = 0;
mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
if (!r_dynamic.value)
}
else
{
- int i, k, l, m, c;
+ int i, k, m, c, leafnum;
msurface_t *surf, **mark;
mleaf_t *leaf;
byte *in = pvsleaf->compressed_vis;
lightframe++;
- radius = light->radius * 2;
+ radius = light->radius * 3;
// clamp radius to avoid exceeding 32768 entry division table
if (radius > 2048)
c = *in++;
if (c)
{
- l = model->numleafs - (k << 3);
- if (l > 8)
- l = 8;
- for (i=0 ; i<l ; i++)
+ for (i = 0;i < 8;i++)
{
if (c & (1<<i))
{
- leaf = &model->leafs[(k << 3)+i+1];
- leaf->lightframe = lightframe;
- if (leaf->visframe != r_visframecount)
- continue;
- if (leaf->contents == CONTENTS_SOLID)
- continue;
+ leafnum = (k << 3)+i+1;
+ if (leafnum > model->numleafs)
+ return;
+ leaf = &model->leafs[leafnum];
+// if (leaf->visframe != r_framecount)
+// continue;
+// if (leaf->contents == CONTENTS_SOLID)
+// continue;
// if out of the light radius, skip
- if (leaf->minmaxs[0] > high[0] || leaf->minmaxs[3] < low[0]
- || leaf->minmaxs[1] > high[1] || leaf->minmaxs[4] < low[1]
- || leaf->minmaxs[2] > high[2] || leaf->minmaxs[5] < low[2])
+ if (leaf->mins[0] > high[0] || leaf->maxs[0] < low[0]
+ || leaf->mins[1] > high[1] || leaf->maxs[1] < low[1]
+ || leaf->mins[2] > high[2] || leaf->maxs[2] < low[2])
continue;
- if (leaf->dlightframe != r_dlightframecount) // not dynamic until now
+ if (leaf->dlightframe != r_framecount) // not dynamic until now
{
leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
- leaf->dlightframe = r_dlightframecount;
+ leaf->dlightframe = r_framecount;
}
leaf->dlightbits[bitindex] |= bit;
if ((m = leaf->nummarksurfaces))
do
{
surf = *mark++;
- if (surf->visframe != r_framecount || surf->lightframe == lightframe)
+ // if not visible in current frame, or already marked because it was in another leaf we passed, skip
+ if (surf->lightframe == lightframe)
continue;
surf->lightframe = lightframe;
+ if (surf->visframe != r_framecount)
+ continue;
dist = PlaneDiff(lightorigin, surf->plane);
if (surf->flags & SURF_PLANEBACK)
dist = -dist;
// LordHavoc: make sure it is infront of the surface and not too far away
- if ((dist >= -0.25f || (surf->flags & SURF_LIGHTBOTHSIDES)) && dist < radius)
+ if (dist < radius && (dist > -0.25f || ((surf->flags & SURF_LIGHTBOTHSIDES) && dist > -radius)))
{
int d;
float dist2, impact[3];
}
}
- if (surf->dlightframe != r_dlightframecount) // not dynamic until now
+ if (surf->dlightframe != r_framecount) // not dynamic until now
{
surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
- surf->dlightframe = r_dlightframecount;
+ surf->dlightframe = r_framecount;
}
surf->dlightbits[bitindex] |= bit;
}
int i;
dlight_t *l;
- r_dlightframecount = r_framecount + 1; // because the count hasn't advanced yet for this frame
-
if (!r_dynamic.value)
return;
for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
{
- if (l->die < cl.time || !l->radius)
+ if (!l->radius)
continue;
// R_MarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel->nodes );
R_VisMarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel);
}
+
+
}
mplane_t *lightplane;
vec3_t lightspot;
-extern cvar_t r_ambient;
-
/*
int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
{
lightmap += size3;
}
+ /*
+ // LordHavoc: here's the readable version of the interpolation
+ // code, not quite as easy for the compiler to optimize...
+
+ // dsfrac is the X position in the lightmap pixel, * 16
+ // dtfrac is the Y position in the lightmap pixel, * 16
+ // r00 is top left corner, r01 is top right corner
+ // r10 is bottom left corner, r11 is bottom right corner
+ // g and b are the same layout.
+ // r0 and r1 are the top and bottom intermediate results
+
+ // first we interpolate the top two points, to get the top
+ // edge sample
+ r0 = (((r01-r00) * dsfrac) >> 4) + r00;
+ g0 = (((g01-g00) * dsfrac) >> 4) + g00;
+ b0 = (((b01-b00) * dsfrac) >> 4) + b00;
+ // then we interpolate the bottom two points, to get the
+ // bottom edge sample
+ r1 = (((r11-r10) * dsfrac) >> 4) + r10;
+ g1 = (((g11-g10) * dsfrac) >> 4) + g10;
+ b1 = (((b11-b10) * dsfrac) >> 4) + b10;
+ // then we interpolate the top and bottom samples to get the
+ // middle sample (the one which was requested)
+ r = (((r1-r0) * dtfrac) >> 4) + r0;
+ g = (((g1-g0) * dtfrac) >> 4) + g0;
+ b = (((b1-b0) * dtfrac) >> 4) + b0;
+ */
+
color[0] += (float) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)) * (1.0f / 256.0f);
color[1] += (float) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)) * (1.0f / 256.0f);
color[2] += (float) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)) * (1.0f / 256.0f);
if (!((1 << i) & dlightbits[j]))
continue;
k = (j<<5)+i;
- if (cl_dlights[k].die < cl.time || !cl_dlights[k].radius)
+ if (!cl_dlights[k].radius)
continue;
VectorSubtract (org, cl_dlights[k].origin, dist);
f = DotProduct(dist, dist) + LIGHTOFFSET;
}
}
-void R_CompleteLightPoint (vec3_t color, vec3_t p)
+void R_CompleteLightPoint (vec3_t color, vec3_t p, int dynamic)
{
mleaf_t *leaf;
leaf = Mod_PointInLeaf(p, cl.worldmodel);
color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
- R_DynamicLightPoint(color, p, leaf->dlightbits);
+ if (dynamic)
+ R_DynamicLightPoint(color, p, leaf->dlightbits);
}
void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits)
color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
- if (leaf->dlightframe == r_dlightframecount)
+ if (leaf->dlightframe == r_framecount)
{
dlightbits[0] = leaf->dlightbits[0];
dlightbits[1] = leaf->dlightbits[1];
for (i=0 ; i<MAX_DLIGHTS ; i++)
{
- if (cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
+ if (!cl_dlights[i].radius)
continue;
VectorSubtract (org, cl_dlights[i].origin, dist);
f = DotProduct(dist, dist) + LIGHTOFFSET;
}
*/
-extern float *aliasvert;
-extern float *aliasvertnorm;
-extern byte *aliasvertcolor;
-extern float modelalpha;
-void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
+void R_LightModel(entity_t *ent, int numverts, vec3_t center, vec3_t basecolor)
{
// LordHavoc: warning: reliance on int being 4 bytes here (of course the d_8to24table relies on that too...)
int i, j, nearlights = 0, color;
a = (byte) bound((int) 0, (int) (modelalpha * 255.0f), (int) 255);
if (lighthalf)
{
- mod[0] = currententity->colormod[0] * 0.5f;
- mod[1] = currententity->colormod[1] * 0.5f;
- mod[2] = currententity->colormod[2] * 0.5f;
+ mod[0] = ent->render.colormod[0] * 0.5f;
+ mod[1] = ent->render.colormod[1] * 0.5f;
+ mod[2] = ent->render.colormod[2] * 0.5f;
}
else
{
- mod[0] = currententity->colormod[0];
- mod[1] = currententity->colormod[1];
- mod[2] = currententity->colormod[2];
+ mod[0] = ent->render.colormod[0];
+ mod[1] = ent->render.colormod[1];
+ mod[2] = ent->render.colormod[2];
}
- if (currententity->effects & EF_FULLBRIGHT)
+ if (ent->render.effects & EF_FULLBRIGHT)
{
((byte *)&color)[0] = (byte) (255.0f * mod[0]);
((byte *)&color)[1] = (byte) (255.0f * mod[1]);
nearlight[nearlights].color[0] = cl_dlights[i].color[0] * t1 * mod[0];
nearlight[nearlights].color[1] = cl_dlights[i].color[1] * t1 * mod[1];
nearlight[nearlights].color[2] = cl_dlights[i].color[2] * t1 * mod[2];
- if (r_lightmodels.value)
+ if (r_lightmodels.value && (ent == NULL || ent != cl_dlights[i].ent))
nearlights++;
else
{