- dist2 += d * d;
- if (dist2 >= maxdist)
- continue;
- }
- }
-
- d = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
-
- if (d < 0)
- {
- dist2 += d * d;
- if (dist2 >= maxdist)
- continue;
- }
- else
- {
- d -= surf->extents[1] + 16;
- if (d > 0)
- {
- dist2 += d * d;
- if (dist2 >= maxdist)
- continue;
- }
- }
- */
-
- 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_framecount;
- }
- surf->dlightbits[bitindex] |= bit;
-
- /*
- if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
- {
- 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_framecount;
- }
- surf->dlightbits[bitindex] |= bit;
- }
- */
- }
-
- if (node->children[0]->contents >= 0)
- {
- if (node->children[1]->contents >= 0)
- {
- R_OldMarkLights (lightorigin, rd, bit, bitindex, node->children[0]);
- node = node->children[1];
- goto loc0;
- }
- else
- {
- node = node->children[0];
- goto loc0;
- }
- }
- else if (node->children[1]->contents >= 0)
- {
- node = node->children[1];
- goto loc0;
- }
-}
-
-/*
-static void R_NoVisMarkLights (rdlight_t *rd, int bit, int bitindex)
-{
- vec3_t lightorigin;
- softwareuntransform(rd->origin, lightorigin);
-
- R_OldMarkLights(lightorigin, rd, bit, bitindex, currentrenderentity->model->nodes + currentrenderentity->model->hulls[0].firstclipnode);
-}
-*/
-
-static void R_VisMarkLights (rdlight_t *rd, int bit, int bitindex)
-{
- static int lightframe = 0;
- mleaf_t *pvsleaf;
- vec3_t lightorigin;
- model_t *model;
- int i, k, m, c, leafnum;
- msurface_t *surf, **mark;
- mleaf_t *leaf;
- qbyte *in;
- int row;
- float low[3], high[3], dist, maxdist;
-
- if (!r_dynamic.integer)
- return;
-
- model = currentrenderentity->model;
- softwareuntransform(rd->origin, lightorigin);
-
- if (!r_vismarklights.integer)
- {
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- pvsleaf = Mod_PointInLeaf (lightorigin, model);
- if (pvsleaf == NULL)
- {
- Con_Printf("R_VisMarkLights: NULL leaf??\n");
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- in = pvsleaf->compressed_vis;
- if (!in)
- {
- // no vis info, so make all visible
- R_OldMarkLights(lightorigin, rd, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
- return;
- }
-
- lightframe++;
-
- low[0] = lightorigin[0] - rd->cullradius;low[1] = lightorigin[1] - rd->cullradius;low[2] = lightorigin[2] - rd->cullradius;
- high[0] = lightorigin[0] + rd->cullradius;high[1] = lightorigin[1] + rd->cullradius;high[2] = lightorigin[2] + rd->cullradius;
-
- // for comparisons to minimum acceptable light
- maxdist = rd->cullradius2;
-
- row = (model->numleafs+7)>>3;
-
- k = 0;
- while (k < row)
- {
- c = *in++;
- if (c)
- {
- for (i = 0;i < 8;i++)
- {
- if (c & (1<<i))
- {
- // warning to the clumsy: numleafs is one less than it should be, it only counts leafs with vis bits (skips leaf 0)
- leafnum = (k << 3)+i+1;
- if (leafnum > model->numleafs)
- return;
- leaf = &model->leafs[leafnum];
- if (leaf->visframe != r_framecount
- || leaf->contents == CONTENTS_SOLID
- || 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_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;
- if ((m = leaf->nummarksurfaces))
- {
- mark = leaf->firstmarksurface;
- do
- {
- surf = *mark++;
- // 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 < rd->cullradius && (dist > -0.25f || ((surf->flags & SURF_LIGHTBOTHSIDES) && dist > -rd->cullradius)))
- {
- int d;
- int impacts, impactt;
- float dist2, impact[3];
-
- dist2 = dist * dist;
-
- impact[0] = rd->origin[0] - surf->plane->normal[0] * dist;
- impact[1] = rd->origin[1] - surf->plane->normal[1] * dist;
- impact[2] = rd->origin[2] - surf->plane->normal[2] * dist;
-
-#if 0
- d = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
- if (d < 0)
- {
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
- }
- else
- {
- d -= surf->extents[0];
- if (d < 0)
- {
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
- }
- }
-
- d = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
- if (d < 0)
- {
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
- }
- else
- {
- d -= surf->extents[1];
- if (d < 0)
- {
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
- }
- }
-
-#else
-
- impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
- d = bound(0, impacts, surf->extents[0] + 16) - impacts;
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
-
- impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
- d = bound(0, impactt, surf->extents[1] + 16) - impactt;
- dist2 += d * d;
- if (dist2 > maxdist)
- continue;
-
-#endif
-
- 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_framecount;
- }
- surf->dlightbits[bitindex] |= bit;
- }
- }
- while (--m);
- }
- }