+ if (!visiblevolumes)
+ {
+ if (wl->castshadows)
+ R_Shadow_Stage_LightWithShadows();
+ else
+ R_Shadow_Stage_LightWithoutShadows();
+
+ // calculate world to filter matrix
+ Matrix4x4_CreateFromQuakeEntity(&matrix, wl->origin[0], wl->origin[1], wl->origin[2], wl->angles[0], wl->angles[1], wl->angles[2], lightradius);
+ Matrix4x4_Invert_Simple(&matrix_worldtofilter, &matrix);
+ // calculate world to attenuationxyz/xy matrix
+ Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5, 0.5, 0.5, 0, 0, 0, 0.5);
+ Matrix4x4_Concat(&matrix_worldtoattenuationxyz, &matrix, &matrix_worldtofilter);
+ // calculate world to attenuationz matrix
+ matrix.m[0][0] = 0;matrix.m[0][1] = 0;matrix.m[0][2] = 0.5;matrix.m[0][3] = 0.5;
+ matrix.m[1][0] = 0;matrix.m[1][1] = 0;matrix.m[1][2] = 0 ;matrix.m[1][3] = 0.5;
+ matrix.m[2][0] = 0;matrix.m[2][1] = 0;matrix.m[2][2] = 0 ;matrix.m[2][3] = 0.5;
+ matrix.m[3][0] = 0;matrix.m[3][1] = 0;matrix.m[3][2] = 0 ;matrix.m[3][3] = 1;
+ Matrix4x4_Concat(&matrix_worldtoattenuationz, &matrix, &matrix_worldtofilter);
+
+ ent = &cl_entities[0].render;
+ if (ent->model && ent->model->DrawLight)
+ {
+ Matrix4x4_Transform(&ent->inversematrix, wl->origin, relativelightorigin);
+ Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
+ Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
+ Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
+ Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
+ if (wl->numsurfaces)
+ R_Model_Brush_DrawLightForSurfaceList(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, wl->surfaces, wl->numsurfaces, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+ else
+ ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+ }
+ if (r_drawentities.integer)
+ {
+ for (i = 0;i < r_refdef.numentities;i++)
+ {
+ ent = r_refdef.entities[i];
+ if (ent->visframe == r_framecount && ent->model && ent->model->DrawLight
+ && ent->maxs[0] >= clipmins[0] && ent->mins[0] <= clipmaxs[0]
+ && ent->maxs[1] >= clipmins[1] && ent->mins[1] <= clipmaxs[1]
+ && ent->maxs[2] >= clipmins[2] && ent->mins[2] <= clipmaxs[2]
+ && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
+ {
+ Matrix4x4_Transform(&ent->inversematrix, wl->origin, relativelightorigin);
+ Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
+ Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
+ Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
+ Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
+ ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+ }
+ }
+ }
+ }
+ }
+ for (lnum = 0, rd = r_dlight;lnum < r_numdlights;lnum++, rd++)
+ {
+ lightradius = rd->cullradius;
+ clipmins[0] = rd->origin[0] - lightradius;
+ clipmins[1] = rd->origin[1] - lightradius;
+ clipmins[2] = rd->origin[2] - lightradius;
+ clipmaxs[0] = rd->origin[0] + lightradius;
+ clipmaxs[1] = rd->origin[1] + lightradius;
+ clipmaxs[2] = rd->origin[2] + lightradius;
+ if (VIS_CullBox(clipmins, clipmaxs))
+ continue;