-/*
-static int castshadowcount = 0;
-static void Mod_Q1BSP_ProcessLightList(void)
-{
- int j, k, l, *mark, lnum;
- mlight_t *e;
- msurface_t *surf;
- float dist;
- mleaf_t *leaf;
- qbyte *pvs;
- vec3_t temp;
- float *v, radius2;
- for (lnum = 0, e = loadmodel->brushq1.lights;lnum < loadmodel->brushq1.numlights;lnum++, e++)
- {
- e->cullradius2 = DotProduct(e->light, e->light) / (e->falloff * e->falloff * 8192.0f * 8192.0f * 2.0f * 2.0f);// + 4096.0f;
- if (e->cullradius2 > 4096.0f * 4096.0f)
- e->cullradius2 = 4096.0f * 4096.0f;
- e->cullradius = e->lightradius = sqrt(e->cullradius2);
- leaf = Mod_Q1BSP_PointInLeaf(e->origin, loadmodel);
- if (leaf->compressed_vis)
- pvs = Mod_Q1BSP_DecompressVis(leaf->compressed_vis, loadmodel);
- else
- pvs = mod_q1bsp_novis;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- loadmodel->brushq1.surfacevisframes[j] = -1;
- for (j = 0, leaf = loadmodel->brushq1.leafs + 1;j < loadmodel->brushq1.numleafs - 1;j++, leaf++)
- {
- if (pvs[j >> 3] & (1 << (j & 7)))
- {
- for (k = 0, mark = leaf->firstmarksurface;k < leaf->nummarksurfaces;k++, mark++)
- {
- surf = loadmodel->brushq1.surfaces + *mark;
- if (surf->number != *mark)
- Con_Printf("%d != %d\n", surf->number, *mark);
- dist = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
- if (surf->flags & SURF_PLANEBACK)
- dist = -dist;
- if (dist > 0 && dist < e->cullradius)
- {
- temp[0] = bound(surf->poly_mins[0], e->origin[0], surf->poly_maxs[0]) - e->origin[0];
- temp[1] = bound(surf->poly_mins[1], e->origin[1], surf->poly_maxs[1]) - e->origin[1];
- temp[2] = bound(surf->poly_mins[2], e->origin[2], surf->poly_maxs[2]) - e->origin[2];
- if (DotProduct(temp, temp) < lightradius2)
- loadmodel->brushq1.surfacevisframes[*mark] = -2;
- }
- }
- }
- }
- // build list of light receiving surfaces
- e->numsurfaces = 0;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- if (loadmodel->brushq1.surfacevisframes[j] == -2)
- e->numsurfaces++;
- e->surfaces = NULL;
- if (e->numsurfaces > 0)
- {
- e->surfaces = Mem_Alloc(loadmodel->mempool, sizeof(msurface_t *) * e->numsurfaces);
- e->numsurfaces = 0;
- for (j = 0;j < loadmodel->brushq1.numsurfaces;j++)
- if (loadmodel->brushq1.surfacevisframes[j] == -2)
- e->surfaces[e->numsurfaces++] = loadmodel->brushq1.surfaces + j;
- }
- // find bounding box and sphere of lit surfaces
- // (these will be used for creating a shape to clip the light)
- radius2 = 0;
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (j == 0)
- {
- VectorCopy(surf->poly_verts, e->mins);
- VectorCopy(surf->poly_verts, e->maxs);
- }
- for (k = 0, v = surf->poly_verts;k < surf->poly_numverts;k++, v += 3)
- {
- if (e->mins[0] > v[0]) e->mins[0] = v[0];if (e->maxs[0] < v[0]) e->maxs[0] = v[0];
- if (e->mins[1] > v[1]) e->mins[1] = v[1];if (e->maxs[1] < v[1]) e->maxs[1] = v[1];
- if (e->mins[2] > v[2]) e->mins[2] = v[2];if (e->maxs[2] < v[2]) e->maxs[2] = v[2];
- VectorSubtract(v, e->origin, temp);
- dist = DotProduct(temp, temp);
- if (radius2 < dist)
- radius2 = dist;
- }
- }
- if (e->cullradius2 > radius2)
- {
- e->cullradius2 = radius2;
- e->cullradius = sqrt(e->cullradius2);
- }
- if (e->mins[0] < e->origin[0] - e->lightradius) e->mins[0] = e->origin[0] - e->lightradius;
- if (e->maxs[0] > e->origin[0] + e->lightradius) e->maxs[0] = e->origin[0] + e->lightradius;
- if (e->mins[1] < e->origin[1] - e->lightradius) e->mins[1] = e->origin[1] - e->lightradius;
- if (e->maxs[1] > e->origin[1] + e->lightradius) e->maxs[1] = e->origin[1] + e->lightradius;
- if (e->mins[2] < e->origin[2] - e->lightradius) e->mins[2] = e->origin[2] - e->lightradius;
- if (e->maxs[2] > e->origin[2] + e->lightradius) e->maxs[2] = e->origin[2] + e->lightradius;
- // clip shadow volumes against eachother to remove unnecessary
- // polygons(and sections of polygons)
- {
- //vec3_t polymins, polymaxs;
- int maxverts = 4;
- float *verts = Mem_Alloc(loadmodel->mempool, maxverts * sizeof(float[3]));
- float f, *v0, *v1, projectdistance;
-
- e->shadowvolume = Mod_ShadowMesh_Begin(loadmodel->mempool, 1024);
-#if 0
- {
- vec3_t outermins, outermaxs, innermins, innermaxs;
- innermins[0] = e->mins[0] - 1;
- innermins[1] = e->mins[1] - 1;
- innermins[2] = e->mins[2] - 1;
- innermaxs[0] = e->maxs[0] + 1;
- innermaxs[1] = e->maxs[1] + 1;
- innermaxs[2] = e->maxs[2] + 1;
- outermins[0] = loadmodel->normalmins[0] - 1;
- outermins[1] = loadmodel->normalmins[1] - 1;
- outermins[2] = loadmodel->normalmins[2] - 1;
- outermaxs[0] = loadmodel->normalmaxs[0] + 1;
- outermaxs[1] = loadmodel->normalmaxs[1] + 1;
- outermaxs[2] = loadmodel->normalmaxs[2] + 1;
- // add bounding box around the whole shadow volume set,
- // facing inward to limit light area, with an outer bounding box
- // facing outward (this is needed by the shadow rendering method)
- // X major
- verts[ 0] = innermaxs[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermaxs[0];verts[ 7] = innermaxs[1];verts[ 8] = innermins[2];
- verts[ 9] = innermaxs[0];verts[10] = innermaxs[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermaxs[0];verts[ 7] = outermins[1];verts[ 8] = outermins[2];
- verts[ 9] = outermaxs[0];verts[10] = outermins[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // X minor
- verts[ 0] = innermins[0];verts[ 1] = innermaxs[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermins[0];verts[ 4] = innermaxs[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermins[0];verts[ 1] = outermins[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermins[0];verts[ 4] = outermins[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Y major
- verts[ 0] = innermaxs[0];verts[ 1] = innermaxs[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermaxs[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermaxs[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermaxs[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermins[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermins[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermaxs[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermaxs[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Y minor
- verts[ 0] = innermins[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermins[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermaxs[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermaxs[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermins[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermins[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermins[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermins[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Z major
- verts[ 0] = innermaxs[0];verts[ 1] = innermins[1];verts[ 2] = innermaxs[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermaxs[1];verts[ 5] = innermaxs[2];
- verts[ 6] = innermins[0];verts[ 7] = innermaxs[1];verts[ 8] = innermaxs[2];
- verts[ 9] = innermins[0];verts[10] = innermins[1];verts[11] = innermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermaxs[1];verts[ 2] = outermaxs[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermins[1];verts[ 5] = outermaxs[2];
- verts[ 6] = outermins[0];verts[ 7] = outermins[1];verts[ 8] = outermaxs[2];
- verts[ 9] = outermins[0];verts[10] = outermaxs[1];verts[11] = outermaxs[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- // Z minor
- verts[ 0] = innermaxs[0];verts[ 1] = innermaxs[1];verts[ 2] = innermins[2];
- verts[ 3] = innermaxs[0];verts[ 4] = innermins[1];verts[ 5] = innermins[2];
- verts[ 6] = innermins[0];verts[ 7] = innermins[1];verts[ 8] = innermins[2];
- verts[ 9] = innermins[0];verts[10] = innermaxs[1];verts[11] = innermins[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- verts[ 0] = outermaxs[0];verts[ 1] = outermins[1];verts[ 2] = outermins[2];
- verts[ 3] = outermaxs[0];verts[ 4] = outermaxs[1];verts[ 5] = outermins[2];
- verts[ 6] = outermins[0];verts[ 7] = outermaxs[1];verts[ 8] = outermins[2];
- verts[ 9] = outermins[0];verts[10] = outermins[1];verts[11] = outermins[2];
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- }
-#endif
- castshadowcount++;
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (surf->flags & SURF_SHADOWCAST)
- surf->castshadow = castshadowcount;
- }
- for (j = 0;j < e->numsurfaces;j++)
- {
- surf = e->surfaces[j];
- if (surf->castshadow != castshadowcount)
- continue;
- f = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
- if (surf->flags & SURF_PLANEBACK)
- f = -f;
- projectdistance = e->lightradius;
- if (maxverts < surf->poly_numverts)
- {
- maxverts = surf->poly_numverts;
- if (verts)
- Mem_Free(verts);
- verts = Mem_Alloc(loadmodel->mempool, maxverts * sizeof(float[3]));
- }
- // copy the original polygon, for the front cap of the volume
- for (k = 0, v0 = surf->poly_verts, v1 = verts;k < surf->poly_numverts;k++, v0 += 3, v1 += 3)
- VectorCopy(v0, v1);
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, surf->poly_numverts, verts);
- // project the original polygon, reversed, for the back cap of the volume
- for (k = 0, v0 = surf->poly_verts + (surf->poly_numverts - 1) * 3, v1 = verts;k < surf->poly_numverts;k++, v0 -= 3, v1 += 3)
- {
- VectorSubtract(v0, e->origin, temp);
- VectorNormalize(temp);
- VectorMA(v0, projectdistance, temp, v1);
- }
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, surf->poly_numverts, verts);
- // project the shadow volume sides
- for (l = surf->poly_numverts - 1, k = 0, v0 = surf->poly_verts + (surf->poly_numverts - 1) * 3, v1 = surf->poly_verts;k < surf->poly_numverts;l = k, k++, v0 = v1, v1 += 3)
- {
- if (!surf->neighborsurfaces[l] || surf->neighborsurfaces[l]->castshadow != castshadowcount)
- {
- VectorCopy(v1, &verts[0]);
- VectorCopy(v0, &verts[3]);
- VectorCopy(v0, &verts[6]);
- VectorCopy(v1, &verts[9]);
- VectorSubtract(&verts[6], e->origin, temp);
- VectorNormalize(temp);
- VectorMA(&verts[6], projectdistance, temp, &verts[6]);
- VectorSubtract(&verts[9], e->origin, temp);
- VectorNormalize(temp);
- VectorMA(&verts[9], projectdistance, temp, &verts[9]);
- Mod_ShadowMesh_AddPolygon(loadmodel->mempool, e->shadowvolume, 4, verts);
- }
- }
- }
- // build the triangle mesh
- e->shadowvolume = Mod_ShadowMesh_Finish(loadmodel->mempool, e->shadowvolume);
- {
- shadowmesh_t *mesh;
- l = 0;
- for (mesh = e->shadowvolume;mesh;mesh = mesh->next)
- l += mesh->numtriangles;
- Con_Printf("light %i shadow volume built containing %i triangles\n", lnum, l);
- }
- }
- }
-}
-*/
-
-