- int i;
- vec3_t p, p2, temp, relativelightorigin, mins, maxs;
- float dist, projectdistance;
- // rough checks
- if (ent->model && ent->model->DrawShadowVolume)
- {
- temp[0] = bound(ent->mins[0], lightorigin[0], ent->maxs[0]) - lightorigin[0];
- temp[1] = bound(ent->mins[1], lightorigin[1], ent->maxs[1]) - lightorigin[1];
- temp[2] = bound(ent->mins[2], lightorigin[2], ent->maxs[2]) - lightorigin[2];
- dist = DotProduct(temp, temp);
- if (dist < cullradius * cullradius)
- {
- if (!Light_CullBox(ent->mins, ent->maxs))
- {
- projectdistance = cullradius - sqrt(dist);
- // calculate projected bounding box and decide if it is on-screen
- VectorCopy(ent->mins, mins);
- VectorCopy(ent->maxs, maxs);
- for (i = 0;i < 8;i++)
- {
- p[0] = i & 1 ? ent->maxs[0] : ent->mins[0];
- p[1] = i & 2 ? ent->maxs[1] : ent->mins[1];
- p[2] = i & 4 ? ent->maxs[2] : ent->mins[2];
- VectorSubtract(p, lightorigin, temp);
- dist = projectdistance / sqrt(DotProduct(temp, temp));
- VectorMA(p, dist, temp, p2);
- if (mins[0] > p2[0]) mins[0] = p2[0];if (maxs[0] < p2[0]) maxs[0] = p2[0];
- if (mins[1] > p2[1]) mins[1] = p2[1];if (maxs[1] < p2[1]) maxs[1] = p2[1];
- if (mins[2] > p2[2]) mins[2] = p2[2];if (maxs[2] < p2[2]) maxs[2] = p2[2];
- }
- if (mins[0] < clipmaxs[0] && maxs[0] > clipmins[0]
- && mins[1] < clipmaxs[1] && maxs[1] > clipmins[1]
- && mins[2] < clipmaxs[2] && maxs[2] > clipmins[2]
- && !LightAndVis_CullBox(mins, maxs))
- {
- Matrix4x4_Transform(&ent->inversematrix, lightorigin, relativelightorigin);
- ent->model->DrawShadowVolume (ent, relativelightorigin, lightradius);
- }
- }
- }
- }
-}
-
-void R_Shadow_DrawWorldLightShadowVolume(matrix4x4_t *matrix, worldlight_t *light);
-
-#define SHADOWSPHERE_SEGMENTS 16
-
-shadowmesh_t *shadowsphere;
-void R_CreateShadowSphere(void)
-{
- int i, j;
- vec3_t angles, angles2, angles3, angles4;
- float verts[12];
- shadowsphere = Mod_ShadowMesh_Begin(zonemempool, SHADOWSPHERE_SEGMENTS * SHADOWSPHERE_SEGMENTS / 2);
- for (i = 0;i < SHADOWSPHERE_SEGMENTS / 2;i++)
- {
- for (j = 0;j < SHADOWSPHERE_SEGMENTS;j++)
- {
- angles[0] = (i * 360.0f / SHADOWSPHERE_SEGMENTS) + 90.0f;
- angles[1] = j * 360.0f / SHADOWSPHERE_SEGMENTS;
- angles[2] = 0;
- VectorCopy(angles, angles2);
- VectorCopy(angles, angles3);
- VectorCopy(angles, angles4);
- angles2[1] += 360.0f / SHADOWSPHERE_SEGMENTS;
- angles3[0] += 360.0f / SHADOWSPHERE_SEGMENTS;
- angles3[1] += 360.0f / SHADOWSPHERE_SEGMENTS;
- angles4[0] += 360.0f / SHADOWSPHERE_SEGMENTS;
- AngleVectorsFLU(angles, verts, NULL, NULL);
- AngleVectorsFLU(angles2, verts + 9, NULL, NULL);
- AngleVectorsFLU(angles3, verts + 6, NULL, NULL);
- AngleVectorsFLU(angles4, verts + 3, NULL, NULL);
- VectorScale(&verts[0], 1.0f, &verts[0]);
- VectorScale(&verts[3], 1.0f, &verts[3]);
- VectorScale(&verts[6], 1.0f, &verts[6]);
- VectorScale(&verts[9], 1.0f, &verts[9]);
- Mod_ShadowMesh_AddPolygon(zonemempool, shadowsphere, 4, verts);
- }
- }
- shadowsphere = Mod_ShadowMesh_Finish(zonemempool, shadowsphere);
-}