+ int i;
+ entity_render_t *ent;
+ int lnum;
+ float f, lightradius, cullradius;
+ vec3_t relativelightorigin, relativeeyeorigin, lightcolor, clipmins, clipmaxs;
+ worldlight_t *wl;
+ //mlight_t *sl;
+ rdlight_t *rd;
+ rmeshstate_t m;
+ mleaf_t *leaf;
+
+ if (visiblevolumes)
+ {
+ memset(&m, 0, sizeof(m));
+ m.blendfunc1 = GL_ONE;
+ m.blendfunc2 = GL_ONE;
+ if (r_shadow_realtime.integer >= 3)
+ m.depthdisable = true;
+ R_Mesh_State(&m);
+ qglDisable(GL_CULL_FACE);
+ GL_Color(0.0 * r_colorscale, 0.0125 * r_colorscale, 0.1 * r_colorscale, 1);
+ }
+ else
+ R_Shadow_Stage_Begin();
+ shadowframecount++;
+ for (lnum = 0, wl = r_shadow_worldlightchain;wl;wl = wl->next, lnum++)
+ {
+ if (d_lightstylevalue[wl->style] <= 0)
+ continue;
+ cullradius = wl->cullradius;
+ lightradius = wl->lightradius;
+ if (R_CullSphere(wl->origin, lightradius))
+ continue;
+ //if (R_CullBox(wl->mins, wl->maxs) || R_CullSphere(wl->origin, lightradius))
+ // continue;
+ //if (VIS_CullBox(wl->mins, wl->maxs) || VIS_CullSphere(wl->origin, lightradius))
+ // continue;
+ if (r_shadow_debuglight.integer >= 0 && lnum != r_shadow_debuglight.integer)
+ continue;
+
+ for (i = 0;i < wl->numleafs;i++)
+ if (wl->leafs[i]->visframe == r_framecount)
+ break;
+ if (i == wl->numleafs)
+ continue;
+ leaf = wl->leafs[i++];
+ VectorCopy(leaf->mins, clipmins);
+ VectorCopy(leaf->maxs, clipmaxs);
+ for (i++;i < wl->numleafs;i++)
+ {
+ leaf = wl->leafs[i];
+ if (leaf->visframe == r_framecount)
+ {
+ if (clipmins[0] > leaf->mins[0]) clipmins[0] = leaf->mins[0];
+ if (clipmaxs[0] < leaf->maxs[0]) clipmaxs[0] = leaf->maxs[0];
+ if (clipmins[1] > leaf->mins[1]) clipmins[1] = leaf->mins[1];
+ if (clipmaxs[1] < leaf->maxs[1]) clipmaxs[1] = leaf->maxs[1];
+ if (clipmins[2] > leaf->mins[2]) clipmins[2] = leaf->mins[2];
+ if (clipmaxs[2] < leaf->maxs[2]) clipmaxs[2] = leaf->maxs[2];
+ }
+ }
+ if (clipmins[0] < wl->mins[0]) clipmins[0] = wl->mins[0];
+ if (clipmins[1] < wl->mins[1]) clipmins[1] = wl->mins[1];
+ if (clipmins[2] < wl->mins[2]) clipmins[2] = wl->mins[2];
+ if (clipmaxs[0] > wl->maxs[0]) clipmaxs[0] = wl->maxs[0];
+ if (clipmaxs[1] > wl->maxs[1]) clipmaxs[1] = wl->maxs[1];
+ if (clipmaxs[2] > wl->maxs[2]) clipmaxs[2] = wl->maxs[2];
+
+ if (R_Shadow_ScissorForBBoxAndSphere(clipmins, clipmaxs, wl->origin, wl->cullradius))
+ continue;
+
+ // mark the leafs we care about so only things in those leafs will matter
+ for (i = 0;i < wl->numleafs;i++)
+ wl->leafs[i]->worldnodeframe = shadowframecount;
+
+
+ f = d_lightstylevalue[wl->style] * (1.0f / 256.0f);
+ VectorScale(wl->light, f, lightcolor);
+ if (wl->selected)
+ {
+ f = 2 + sin(realtime * M_PI * 4.0);
+ VectorScale(lightcolor, f, lightcolor);
+ }
+
+ if (!visiblevolumes)
+ R_Shadow_Stage_ShadowVolumes();
+ ent = &cl_entities[0].render;
+ if (wl->shadowvolume && r_shadow_staticworldlights.integer)
+ R_Shadow_DrawWorldLightShadowVolume(&ent->matrix, wl);
+ else
+ R_TestAndDrawShadowVolume(ent, wl->origin, cullradius, lightradius, wl->mins, wl->maxs, clipmins, clipmaxs);
+ if (r_drawentities.integer)
+ {
+ for (i = 0;i < r_refdef.numentities;i++)
+ {
+ ent = r_refdef.entities[i];
+ if (ent->model && !strcmp(ent->model->name, "progs/missile.mdl"))
+ R_TestAndDrawShadowVolume(ent, wl->origin, cullradius, lightradius, wl->mins, wl->maxs, clipmins, clipmaxs);
+ }
+ }