+ skin = R_FetchAliasSkin(ent, mesh);
+ if (skin->flags & ALIASSKIN_TRANSPARENT)
+ continue;
+ R_Mesh_GetSpace(mesh->num_vertices);
+ R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f, NULL, NULL, NULL);
+ for (i = 0, v = varray_vertex3f;i < mesh->num_vertices;i++, v += 3)
+ {
+ dist = DotProduct(v, planenormal) - planedist;
+ if (dist > 0)
+ VectorMA(v, dist, projection, v);
+ }
+ c_alias_polys += mesh->num_triangles;
+ R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
+ }
+}
+
+void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
+{
+ int meshnum;
+ aliasmesh_t *mesh;
+ aliasskin_t *skin;
+ float projectdistance;
+ if (ent->effects & EF_ADDITIVE || ent->alpha < 1)
+ return;
+ projectdistance = lightradius + ent->model->radius - sqrt(DotProduct(relativelightorigin, relativelightorigin));
+ if (projectdistance > 0.1)
+ {
+ R_Mesh_Matrix(&ent->matrix);
+ for (meshnum = 0, mesh = ent->model->aliasdata_meshes;meshnum < ent->model->aliasnum_meshes;meshnum++, mesh++)
+ {
+ skin = R_FetchAliasSkin(ent, mesh);
+ if (skin->flags & ALIASSKIN_TRANSPARENT)
+ continue;
+ R_Mesh_GetSpace(mesh->num_vertices * 2);
+ R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f, NULL, NULL, NULL);
+ R_Shadow_Volume(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, lightradius, projectdistance);
+ }
+ }
+}
+
+void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
+{
+ int c, meshnum, layernum;
+ float fog, ifog, lightcolor2[3], *vertices;
+ vec3_t diff;
+ qbyte *bcolor;
+ aliasmesh_t *mesh;
+ aliaslayer_t *layer;
+ aliasskin_t *skin;
+
+ if (ent->effects & (EF_ADDITIVE | EF_FULLBRIGHT) || ent->alpha < 1)
+ return;
+
+ R_Mesh_Matrix(&ent->matrix);
+
+ fog = 0;
+ if (fogenabled)
+ {
+ VectorSubtract(ent->origin, r_origin, diff);
+ fog = DotProduct(diff,diff);
+ if (fog < 0.01f)
+ fog = 0.01f;
+ fog = exp(fogdensity/fog);
+ if (fog > 1)
+ fog = 1;
+ if (fog < 0.01f)
+ fog = 0;
+ // fog method: darken, additive fog
+ // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
+ // 2. render fog as additive
+ }
+ ifog = 1 - fog;
+
+ for (meshnum = 0, mesh = ent->model->aliasdata_meshes;meshnum < ent->model->aliasnum_meshes;meshnum++, mesh++)
+ {
+ skin = R_FetchAliasSkin(ent, mesh);
+ if (skin->flags & ALIASSKIN_TRANSPARENT)
+ continue;
+ expandaliasvert(mesh->num_vertices);
+ vertices = R_Shadow_VertexBuffer(mesh->num_vertices);
+ R_Model_Alias_GetMesh_Vertex3f(ent, mesh, vertices, aliasvert_normal3f, aliasvert_svector3f, aliasvert_tvector3f);
+ for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
+ {
+ if (!(layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0))
+ continue;
+ lightcolor2[0] = lightcolor[0] * ifog;
+ lightcolor2[1] = lightcolor[1] * ifog;
+ lightcolor2[2] = lightcolor[2] * ifog;
+ if (layer->flags & ALIASLAYER_SPECULAR)
+ {
+ c_alias_polys += mesh->num_triangles;
+ R_Shadow_SpecularLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertices, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightradius, lightcolor2, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, NULL);
+ }
+ else if (layer->flags & ALIASLAYER_DIFFUSE)
+ {
+ if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
+ {
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
+ // fullbright passes were already taken care of, so skip them in realtime lighting passes
+ if (c >= 224)
+ continue;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
+ lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
+ lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
+ }
+ else if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
+ {
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
+ // fullbright passes were already taken care of, so skip them in realtime lighting passes
+ if (c >= 224)
+ continue;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
+ lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
+ lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
+ }
+ c_alias_polys += mesh->num_triangles;
+ R_Shadow_DiffuseLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertices, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, lightradius, lightcolor2, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, NULL);
+ }
+ }