- if (dist >= -rd->cullradius)
- R_RecursiveMarkLights(ent, lightorigin, rd, bit, bitindex, node->children[0], pvs, pvsbits);
- node = node->children[1];
- }
- }
-
- // check if leaf is visible according to pvs
- leaf = (mleaf_t *)node;
- i = (leaf - ent->model->brushq1.leafs) - 1;
- if (leaf->nummarksurfaces && (i >= pvsbits || pvs[i >> 3] & (1 << (i & 7))))
- {
- int *surfacepvsframes, d, impacts, impactt;
- float sdist, maxdist, dist2, impact[3];
- msurface_t *surf;
- // mark the polygons
- maxdist = rd->cullradius2;
- surfacepvsframes = ent->model->brushq1.surfacepvsframes;
- for (i = 0;i < leaf->nummarksurfaces;i++)
- {
- if (surfacepvsframes[leaf->firstmarksurface[i]] != ent->model->brushq1.pvsframecount)
- continue;
- surf = ent->model->brushq1.surfaces + leaf->firstmarksurface[i];
- dist = sdist = PlaneDiff(lightorigin, surf->plane);
- if (surf->flags & SURF_PLANEBACK)
- dist = -dist;
-
- if (dist < -0.25f && !(surf->flags & SURF_LIGHTBOTHSIDES))
- continue;
-
- dist2 = dist * dist;
- if (dist2 >= maxdist)
- continue;
-
- VectorCopy(lightorigin, impact);
- if (surf->plane->type >= 3)
- VectorMA(impact, -sdist, surf->plane->normal, impact);
- else
- impact[surf->plane->type] -= sdist;
-
- 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;
-
- if (surf->dlightframe != r_framecount) // not dynamic until now