- skinframe = R_FetchSkinFrame(ent);
- R_Mesh_ResizeCheck(ent->model->numverts);
- R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvert_normals);
- Mod_BuildTextureVectorsAndNormals(ent->model->numverts, ent->model->numtris, varray_vertex, ent->model->mdlmd2data_texcoords, ent->model->mdlmd2data_indices, aliasvert_svectors, aliasvert_tvectors, aliasvert_normals);
- R_Shadow_RenderLighting(ent->model->numverts, ent->model->numtris, ent->model->mdlmd2data_indices, aliasvert_svectors, aliasvert_tvectors, aliasvert_normals, ent->model->mdlmd2data_texcoords, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, skinframe->base, skinframe->gloss, skinframe->nmap, NULL);
+
+ 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_DRAW_PER_LIGHT)
+ || ((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);
+ }
+ }
+ }