+ 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;
+
+ memset(&m, 0, sizeof(m));
+ skin = R_FetchAliasSkin(ent, mesh);
+ R_Mesh_ResizeCheck(mesh->num_vertices);
+ R_Model_Alias_GetMeshVerts(ent, mesh, varray_vertex, aliasvert_normals, NULL, NULL);
+ memcpy(varray_texcoord[0], mesh->data_texcoords, mesh->num_vertices * sizeof(float[4]));
+ for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
+ {
+ if (((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
+ || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0)
+ || (layer->flags & ALIASLAYER_DRAW_PER_LIGHT))
+ continue;
+ if (layer->flags & ALIASLAYER_FOG)
+ {
+ m.blendfunc1 = GL_SRC_ALPHA;
+ m.blendfunc2 = GL_ONE;
+ colorscale = r_colorscale;
+ m.texrgbscale[0] = 1;
+ m.tex[0] = R_GetTexture(layer->texture);
+ R_Mesh_State(&m);
+ GL_Color(fogcolor[0] * fog * colorscale, fogcolor[1] * fog * colorscale, fogcolor[2] * fog * colorscale, ent->alpha);
+ c_alias_polys += mesh->num_triangles;
+ R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_elements);
+ continue;
+ }
+ if ((layer->flags & ALIASLAYER_ADD) || ((layer->flags & ALIASLAYER_ALPHA) && (ent->effects & EF_ADDITIVE)))
+ {
+ m.blendfunc1 = GL_SRC_ALPHA;
+ m.blendfunc2 = GL_ONE;
+ }
+ else if ((layer->flags & ALIASLAYER_ALPHA) || ent->alpha != 1.0)
+ {
+ m.blendfunc1 = GL_SRC_ALPHA;
+ m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
+ }
+ else
+ {
+ m.blendfunc1 = GL_ONE;
+ m.blendfunc2 = GL_ZERO;
+ }
+ colorscale = r_colorscale;
+ m.texrgbscale[0] = 1;
+ if (gl_combine.integer)
+ {
+ colorscale *= 0.25f;
+ m.texrgbscale[0] = 4;
+ }
+ m.tex[0] = R_GetTexture(layer->texture);
+ R_Mesh_State(&m);
+ if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
+ {
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ fullbright = c >= 224;
+ VectorScale(bcolor, (1.0f / 255.0f), tint);
+ }
+ else if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
+ {
+ // 128-224 are backwards ranges
+ c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
+ bcolor = (qbyte *) (&palette_complete[c]);
+ fullbright = c >= 224;
+ VectorScale(bcolor, (1.0f / 255.0f), tint);
+ }
+ else
+ {
+ tint[0] = tint[1] = tint[2] = 1;
+ fullbright = false;
+ }
+ VectorScale(tint, ifog * colorscale, tint);
+ if (!(layer->flags & ALIASLAYER_DIFFUSE))
+ fullbright = true;
+ if (ent->effects & EF_FULLBRIGHT)
+ fullbright = true;
+ if (fullbright)
+ GL_Color(tint[0], tint[1], tint[2], ent->alpha);
+ else
+ R_LightModel(ent, mesh->num_vertices, varray_vertex, aliasvert_normals, varray_color, tint[0], tint[1], tint[2], false);
+ c_alias_polys += mesh->num_triangles;
+ R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_elements);