X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=gl_models.c;h=f66348614b3ee4aa6682b48e29ef54cdbe26716c;hb=07c3a57d8ea2e9ecb5c0a98f99939d931e9f91d6;hp=14df524c781ef432cd221d568597f0c992a53803;hpb=c1d9e759b83908c5398daf43a94f8585b9c7356a;p=xonotic%2Fdarkplaces.git diff --git a/gl_models.c b/gl_models.c index 14df524c..f6634861 100644 --- a/gl_models.c +++ b/gl_models.c @@ -6,85 +6,8 @@ void GL_Models_Init(void) { } -void R_Model_Alias_GetMesh_Vertex3f(const entity_render_t *ent, const aliasmesh_t *mesh, float *out3f) -{ - if (mesh->num_vertexboneweights) - { - int i, k, blends; - aliasvertexboneweight_t *v; - float *out, *matrix, m[12], bonepose[256][12]; - // vertex weighted skeletal - // interpolate matrices and concatenate them to their parents - for (i = 0;i < ent->model->alias.aliasnum_bones;i++) - { - for (k = 0;k < 12;k++) - m[k] = 0; - for (blends = 0;blends < 4 && ent->frameblend[blends].lerp > 0;blends++) - { - matrix = ent->model->alias.aliasdata_poses + (ent->frameblend[blends].frame * ent->model->alias.aliasnum_bones + i) * 12; - for (k = 0;k < 12;k++) - m[k] += matrix[k] * ent->frameblend[blends].lerp; - } - if (ent->model->alias.aliasdata_bones[i].parent >= 0) - R_ConcatTransforms(bonepose[ent->model->alias.aliasdata_bones[i].parent], m, bonepose[i]); - else - for (k = 0;k < 12;k++) - bonepose[i][k] = m[k]; - } - // blend the vertex bone weights - memset(out3f, 0, mesh->num_vertices * sizeof(float[3])); - v = mesh->data_vertexboneweights; - for (i = 0;i < mesh->num_vertexboneweights;i++, v++) - { - out = out3f + v->vertexindex * 3; - matrix = bonepose[v->boneindex]; - // FIXME: this can very easily be optimized with SSE or 3DNow - out[0] += v->origin[0] * matrix[0] + v->origin[1] * matrix[1] + v->origin[2] * matrix[ 2] + v->origin[3] * matrix[ 3]; - out[1] += v->origin[0] * matrix[4] + v->origin[1] * matrix[5] + v->origin[2] * matrix[ 6] + v->origin[3] * matrix[ 7]; - out[2] += v->origin[0] * matrix[8] + v->origin[1] * matrix[9] + v->origin[2] * matrix[10] + v->origin[3] * matrix[11]; - } - } - else - { - int i, vertcount; - float lerp1, lerp2, lerp3, lerp4; - const float *vertsbase, *verts1, *verts2, *verts3, *verts4; - // vertex morph - vertsbase = mesh->data_morphvertex3f; - vertcount = mesh->num_vertices; - verts1 = vertsbase + ent->frameblend[0].frame * vertcount * 3; - lerp1 = ent->frameblend[0].lerp; - if (ent->frameblend[1].lerp) - { - verts2 = vertsbase + ent->frameblend[1].frame * vertcount * 3; - lerp2 = ent->frameblend[1].lerp; - if (ent->frameblend[2].lerp) - { - verts3 = vertsbase + ent->frameblend[2].frame * vertcount * 3; - lerp3 = ent->frameblend[2].lerp; - if (ent->frameblend[3].lerp) - { - verts4 = vertsbase + ent->frameblend[3].frame * vertcount * 3; - lerp4 = ent->frameblend[3].lerp; - for (i = 0;i < vertcount * 3;i++) - VectorMAMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, lerp4, verts4 + i, out3f + i); - } - else - for (i = 0;i < vertcount * 3;i++) - VectorMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, out3f + i); - } - else - for (i = 0;i < vertcount * 3;i++) - VectorMAM(lerp1, verts1 + i, lerp2, verts2 + i, out3f + i); - } - else - memcpy(out3f, verts1, vertcount * sizeof(float[3])); - } -} - -aliaslayer_t r_aliasnoskinlayers[2] = {{ALIASLAYER_DIFFUSE, NULL, NULL}, {ALIASLAYER_FOG | ALIASLAYER_FORCEDRAW_IF_FIRSTPASS, NULL, NULL}}; -aliasskin_t r_aliasnoskin = {0, 2, r_aliasnoskinlayers}; -aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mesh) +static texture_t r_aliasnotexture; +static texture_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mesh) { model_t *model = ent->model; if (model->numskins) @@ -93,7 +16,7 @@ aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mes if ((unsigned int)s >= (unsigned int)model->numskins) s = 0; if (model->skinscenes[s].framecount > 1) - s = model->skinscenes[s].firstframe + (int) (cl.time * model->skinscenes[s].framerate) % model->skinscenes[s].framecount; + s = model->skinscenes[s].firstframe + (unsigned int) (r_refdef.time * model->skinscenes[s].framerate) % model->skinscenes[s].framecount; else s = model->skinscenes[s].firstframe; if (s >= mesh->num_skins) @@ -102,22 +25,23 @@ aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mes } else { - r_aliasnoskinlayers[0].texture = r_notexture; - return &r_aliasnoskin; + memset(&r_aliasnotexture, 0, sizeof(r_aliasnotexture)); + r_aliasnotexture.skin.base = r_texture_notexture; + return &r_aliasnotexture; } } -void R_DrawAliasModelCallback (const void *calldata1, int calldata2) +static void R_DrawAliasModelCallback (const void *calldata1, int calldata2) { - int c, fullbright, layernum, firstpass, generatenormals = true; - float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3]; + int c, fbbase, fbpants, fbshirt, doglow; + float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3], colorbase[3], colorpants[3], colorshirt[3]; + float *vertex3f, *normal3f; vec3_t diff; qbyte *bcolor; rmeshstate_t m; const entity_render_t *ent = calldata1; aliasmesh_t *mesh = ent->model->alias.aliasdata_meshes + calldata2; - aliaslayer_t *layer; - aliasskin_t *skin; + texture_t *texture; R_Mesh_Matrix(&ent->matrix); @@ -139,99 +63,191 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2) } ifog = 1 - fog; - firstpass = true; - skin = R_FetchAliasSkin(ent, mesh); - R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f); - for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++) + VectorScale(ent->colormod, ifog, colorbase); + VectorClear(colorpants); + VectorClear(colorshirt); + fbbase = ent->effects & EF_FULLBRIGHT; + fbpants = fbbase; + fbshirt = fbbase; + if (ent->colormap >= 0) { - if (!(layer->flags & ALIASLAYER_FORCEDRAW_IF_FIRSTPASS) || !firstpass) - { - if (((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0) - || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0) - || ((layer->flags & ALIASLAYER_FOG) && !fogenabled) - || (layer->flags & ALIASLAYER_SPECULAR) - || ((layer->flags & ALIASLAYER_DIFFUSE) && (r_shadow_realtime_world.integer && r_shadow_realtime_world_lightmaps.value <= 0 && r_ambient.integer <= 0 && r_fullbright.integer == 0 && !(ent->effects & EF_FULLBRIGHT)))) - continue; - } - if (!firstpass || (ent->effects & EF_ADDITIVE)) - { - GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); - GL_DepthMask(false); - } - else if ((skin->flags & ALIASSKIN_TRANSPARENT) || ent->alpha != 1.0) - { - GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GL_DepthMask(false); - } - else + // 128-224 are backwards ranges + c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12; + if (c >= 224) + fbpants = true; + bcolor = (qbyte *) (&palette_complete[c]); + colorpants[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f); + colorpants[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f); + colorpants[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f); + // 128-224 are backwards ranges + c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12; + if (c >= 224) + fbshirt = true; + bcolor = (qbyte *) (&palette_complete[c]); + colorshirt[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f); + colorshirt[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f); + colorshirt[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f); + } + + texture = R_FetchAliasSkin(ent, mesh); + + if ((ent->effects & EF_ADDITIVE)) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + } + else if (texture->skin.fog || ent->alpha != 1.0) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + GL_DepthMask(false); + } + else + { + GL_BlendFunc(GL_ONE, GL_ZERO); + GL_DepthMask(true); + } + GL_DepthTest(!(ent->effects & EF_NODEPTHTEST)); + colorscale = 1.0f; + if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1) + { + vertex3f = mesh->data_basevertex3f; + normal3f = mesh->data_basenormal3f; + } + else + { + vertex3f = varray_vertex3f; + Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f); + normal3f = NULL; + } + + doglow = texture->skin.glow != NULL; + + memset(&m, 0, sizeof(m)); + m.pointer_vertex = vertex3f; + m.pointer_texcoord[0] = mesh->data_texcoord2f; + if (gl_combine.integer) + { + colorscale *= 0.25f; + m.texrgbscale[0] = 4; + } + + m.tex[0] = R_GetTexture((ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged); + VectorScale(colorbase, colorscale, tint); + m.pointer_color = NULL; + if (fbbase) + GL_Color(tint[0], tint[1], tint[2], ent->alpha); + else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false)) + { + m.pointer_color = varray_color4f; + if (normal3f == NULL) { - GL_BlendFunc(GL_ONE, GL_ZERO); - GL_DepthMask(true); + normal3f = varray_normal3f; + Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f); } - GL_DepthTest(true); - firstpass = false; - colorscale = 1.0f; + R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f); + } + else + GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]); + if (gl_combine.integer && doglow) + { + doglow = false; + m.tex[1] = R_GetTexture(texture->skin.glow); + m.pointer_texcoord[1] = mesh->data_texcoord2f; + m.texcombinergb[1] = GL_ADD; + } + R_Mesh_State(&m); + c_alias_polys += mesh->num_triangles; + GL_LockArrays(0, mesh->num_vertices); + R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); + GL_LockArrays(0, 0); + m.tex[1] = 0; + m.pointer_texcoord[1] = NULL; + m.texcombinergb[1] = 0; - memset(&m, 0, sizeof(m)); - if (layer->texture != NULL) + VectorScale(colorpants, colorscale, tint); + if (ent->colormap >= 0 && texture->skin.pants && VectorLength2(tint) >= 0.001) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + m.tex[0] = R_GetTexture(texture->skin.pants); + m.pointer_color = NULL; + if (fbpants) + GL_Color(tint[0], tint[1], tint[2], ent->alpha); + else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false)) { - m.tex[0] = R_GetTexture(layer->texture); - m.pointer_texcoord[0] = mesh->data_texcoord2f; - if (gl_combine.integer && layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR)) + m.pointer_color = varray_color4f; + if (normal3f == NULL) { - colorscale *= 0.25f; - m.texrgbscale[0] = 4; + normal3f = varray_normal3f; + Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f); } - } - m.pointer_vertex = varray_vertex3f; - - c_alias_polys += mesh->num_triangles; - if (layer->flags & ALIASLAYER_FOG) - { - colorscale *= fog; - GL_Color(fogcolor[0] * colorscale, fogcolor[1] * colorscale, fogcolor[2] * colorscale, ent->alpha); + R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f); } else + GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]); + R_Mesh_State(&m); + c_alias_polys += mesh->num_triangles; + GL_LockArrays(0, mesh->num_vertices); + R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); + GL_LockArrays(0, 0); + } + + VectorScale(colorshirt, colorscale, tint); + if (ent->colormap >= 0 && texture->skin.shirt && VectorLength2(tint) >= 0.001) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + m.tex[0] = R_GetTexture(texture->skin.shirt); + m.pointer_color = NULL; + if (fbshirt) + GL_Color(tint[0], tint[1], tint[2], ent->alpha); + else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false)) { - fullbright = !(layer->flags & ALIASLAYER_DIFFUSE) || r_fullbright.integer || (ent->effects & EF_FULLBRIGHT); - if (layer->flags & (ALIASLAYER_COLORMAP_PANTS | ALIASLAYER_COLORMAP_SHIRT)) + m.pointer_color = varray_color4f; + if (normal3f == NULL) { - // 128-224 are backwards ranges - if (layer->flags & ALIASLAYER_COLORMAP_PANTS) - c = (ent->colormap & 0xF) << 4; - else //if (layer->flags & ALIASLAYER_COLORMAP_SHIRT) - c = (ent->colormap & 0xF0); - c += (c >= 128 && c < 224) ? 4 : 12; - bcolor = (qbyte *) (&palette_complete[c]); - fullbright = fullbright || c >= 224; - VectorScale(bcolor, (1.0f / 255.0f), tint); - } - else - tint[0] = tint[1] = tint[2] = 1; - if (r_shadow_realtime_world.integer && !fullbright) - VectorScale(tint, r_shadow_realtime_world_lightmaps.value, tint); - colorscale *= ifog; - if (fullbright) - GL_Color(tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha); - else - { - if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false)) - { - m.pointer_color = varray_color4f; - if (generatenormals) - { - generatenormals = false; - Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_texcoord2f, mesh->data_element3i, NULL, NULL, varray_normal3f); - } - R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, varray_vertex3f, varray_normal3f, varray_color4f); - } - else - GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]); + normal3f = varray_normal3f; + Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f); } + R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f); } + else + GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]); R_Mesh_State(&m); + c_alias_polys += mesh->num_triangles; + GL_LockArrays(0, mesh->num_vertices); + R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); + GL_LockArrays(0, 0); + } + + colorscale = 1; + m.texrgbscale[0] = 0; + + if (texture->skin.glow) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + m.tex[0] = R_GetTexture(texture->skin.glow); + m.pointer_color = NULL; + GL_Color(1, 1, 1, ent->alpha); + R_Mesh_State(&m); + c_alias_polys += mesh->num_triangles; GL_LockArrays(0, mesh->num_vertices); - R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); + R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); + GL_LockArrays(0, 0); + } + + if (fog > 0) + { + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + m.tex[0] = R_GetTexture(texture->skin.fog); + m.pointer_color = NULL; + GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], fog * ent->alpha); + R_Mesh_State(&m); + c_alias_polys += mesh->num_triangles; + GL_LockArrays(0, mesh->num_vertices); + R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i); GL_LockArrays(0, 0); } } @@ -247,20 +263,23 @@ void R_Model_Alias_Draw(entity_render_t *ent) for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++) { - if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->flags & ALIASSKIN_TRANSPARENT) - R_MeshQueue_AddTransparent(ent->origin, R_DrawAliasModelCallback, ent, meshnum); + if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->skin.fog) + R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : ent->origin, R_DrawAliasModelCallback, ent, meshnum); else R_DrawAliasModelCallback(ent, meshnum); } } -void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius) +void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs) { int meshnum; aliasmesh_t *mesh; - aliasskin_t *skin; - float projectdistance; - if (ent->effects & EF_ADDITIVE || ent->alpha < 1) + texture_t *texture; + float projectdistance, *vertex3f; + if (!(ent->flags & RENDER_SHADOW)) + return; + // check the box in modelspace, it was already checked in worldspace + if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs)) return; projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin)); if (projectdistance > 0.1) @@ -268,27 +287,33 @@ void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightor R_Mesh_Matrix(&ent->matrix); for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++) { - skin = R_FetchAliasSkin(ent, mesh); - if (skin->flags & ALIASSKIN_TRANSPARENT) + texture = R_FetchAliasSkin(ent, mesh); + if (texture->skin.fog) continue; - R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f); - R_Shadow_VolumeFromSphere(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, lightradius); + if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1) + vertex3f = mesh->data_basevertex3f; + else + { + vertex3f = varray_vertex3f; + Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f); + } + // identify lit faces within the bounding box + R_Shadow_PrepareShadowMark(mesh->num_triangles); + R_Shadow_MarkVolumeFromBox(0, mesh->num_triangles, vertex3f, mesh->data_element3i, relativelightorigin, lightmins, lightmaxs, ent->model->normalmins, ent->model->normalmaxs); + R_Shadow_VolumeFromList(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist); } } } -void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap) +void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist) { - int c, meshnum, layernum; - float fog, ifog, lightcolor2[3]; + int c, meshnum; + float fog, ifog, lightcolorbase[3], lightcolorpants[3], lightcolorshirt[3]; + float *vertex3f, *svector3f, *tvector3f, *normal3f; 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; + texture_t *texture; R_Mesh_Matrix(&ent->matrix); @@ -310,56 +335,65 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v } ifog = 1 - fog; + VectorScale(lightcolor, ifog, lightcolorbase); + if (VectorLength2(lightcolorbase) < 0.001) + return; + VectorClear(lightcolorpants); + VectorClear(lightcolorshirt); + if (ent->colormap >= 0) + { + // 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) + { + bcolor = (qbyte *) (&palette_complete[c]); + lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f); + lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f); + lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f); + } + // 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) + { + bcolor = (qbyte *) (&palette_complete[c]); + lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f); + lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f); + lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f); + } + } + for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++) { - skin = R_FetchAliasSkin(ent, mesh); - if (skin->flags & ALIASSKIN_TRANSPARENT) + texture = R_FetchAliasSkin(ent, mesh); + // FIXME: transparent skins need to be lit during the transparent render + if (texture->skin.fog) continue; - R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f); - Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_texcoord2f, mesh->data_element3i, varray_svector3f, varray_tvector3f, varray_normal3f); - for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++) + if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1) { - 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_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, varray_vertex3f, varray_svector3f, varray_tvector3f, varray_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_SPECULAR); - } - 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_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, varray_vertex3f, varray_svector3f, varray_tvector3f, varray_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_DIFFUSE); - } + vertex3f = mesh->data_basevertex3f; + svector3f = mesh->data_basesvector3f; + tvector3f = mesh->data_basetvector3f; + normal3f = mesh->data_basenormal3f; + } + else + { + vertex3f = varray_vertex3f; + svector3f = varray_svector3f; + tvector3f = varray_tvector3f; + normal3f = varray_normal3f; + Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f); + Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f); + } + c_alias_polys += mesh->num_triangles; + R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorbase, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, (ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged, texture->skin.nmap, texture->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale); + if (ent->colormap >= 0) + { + if (texture->skin.pants && VectorLength2(lightcolorpants) >= 0.001) + R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorpants, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.pants, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0); + if (texture->skin.shirt && VectorLength2(lightcolorshirt) >= 0.001) + R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorshirt, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.shirt, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0); } } }