5 static texture_t r_aliasnotexture;
6 static texture_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mesh)
8 model_t *model = ent->model;
12 if ((unsigned int)s >= (unsigned int)model->numskins)
14 if (model->skinscenes[s].framecount > 1)
15 s = model->skinscenes[s].firstframe + (unsigned int) (r_refdef.time * model->skinscenes[s].framerate) % model->skinscenes[s].framecount;
17 s = model->skinscenes[s].firstframe;
18 if (s >= mesh->num_skins)
20 return mesh->data_skins + s;
24 memset(&r_aliasnotexture, 0, sizeof(r_aliasnotexture));
25 r_aliasnotexture.skin.base = r_texture_notexture;
26 return &r_aliasnotexture;
30 static void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
32 int c, fbbase, fbpants, fbshirt, doglow;
33 float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3], colorbase[3], colorpants[3], colorshirt[3];
34 float *vertex3f, *normal3f;
38 const entity_render_t *ent = calldata1;
39 aliasmesh_t *mesh = ent->model->alias.aliasdata_meshes + calldata2;
42 R_Mesh_Matrix(&ent->matrix);
47 VectorSubtract(ent->origin, r_vieworigin, diff);
48 fog = DotProduct(diff,diff);
51 fog = exp(fogdensity/fog);
56 // fog method: darken, additive fog
57 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
58 // 2. render fog as additive
62 VectorScale(ent->colormod, ifog, colorbase);
63 VectorClear(colorpants);
64 VectorClear(colorshirt);
65 fbbase = ent->effects & EF_FULLBRIGHT;
68 if (ent->colormap >= 0)
70 // 128-224 are backwards ranges
71 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
74 bcolor = (qbyte *) (&palette_complete[c]);
75 colorpants[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f);
76 colorpants[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f);
77 colorpants[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f);
78 // 128-224 are backwards ranges
79 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
82 bcolor = (qbyte *) (&palette_complete[c]);
83 colorshirt[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f);
84 colorshirt[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f);
85 colorshirt[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f);
88 texture = R_FetchAliasSkin(ent, mesh);
90 if ((ent->effects & EF_ADDITIVE))
92 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
95 else if (texture->skin.fog || ent->alpha != 1.0)
97 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
102 GL_BlendFunc(GL_ONE, GL_ZERO);
105 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
107 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
109 vertex3f = mesh->data_basevertex3f;
110 normal3f = mesh->data_basenormal3f;
114 vertex3f = varray_vertex3f;
115 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
119 doglow = texture->skin.glow != NULL;
121 memset(&m, 0, sizeof(m));
122 m.pointer_vertex = vertex3f;
123 m.pointer_texcoord[0] = mesh->data_texcoord2f;
124 if (gl_combine.integer)
127 m.texrgbscale[0] = 4;
130 m.tex[0] = R_GetTexture((ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged);
131 VectorScale(colorbase, colorscale, tint);
132 m.pointer_color = NULL;
134 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
135 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
137 m.pointer_color = varray_color4f;
138 if (normal3f == NULL)
140 normal3f = varray_normal3f;
141 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
143 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
146 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
147 if (gl_combine.integer && doglow)
150 m.tex[1] = R_GetTexture(texture->skin.glow);
151 m.pointer_texcoord[1] = mesh->data_texcoord2f;
152 m.texcombinergb[1] = GL_ADD;
155 c_alias_polys += mesh->num_triangles;
156 GL_LockArrays(0, mesh->num_vertices);
157 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
160 m.pointer_texcoord[1] = NULL;
161 m.texcombinergb[1] = 0;
163 VectorScale(colorpants, colorscale, tint);
164 if (ent->colormap >= 0 && texture->skin.pants && VectorLength2(tint) >= 0.001)
166 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
168 m.tex[0] = R_GetTexture(texture->skin.pants);
169 m.pointer_color = NULL;
171 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
172 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
174 m.pointer_color = varray_color4f;
175 if (normal3f == NULL)
177 normal3f = varray_normal3f;
178 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
180 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
183 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
185 c_alias_polys += mesh->num_triangles;
186 GL_LockArrays(0, mesh->num_vertices);
187 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
191 VectorScale(colorshirt, colorscale, tint);
192 if (ent->colormap >= 0 && texture->skin.shirt && VectorLength2(tint) >= 0.001)
194 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
196 m.tex[0] = R_GetTexture(texture->skin.shirt);
197 m.pointer_color = NULL;
199 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
200 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
202 m.pointer_color = varray_color4f;
203 if (normal3f == NULL)
205 normal3f = varray_normal3f;
206 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
208 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
211 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
213 c_alias_polys += mesh->num_triangles;
214 GL_LockArrays(0, mesh->num_vertices);
215 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
220 m.texrgbscale[0] = 0;
221 m.pointer_color = NULL;
225 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
227 m.tex[0] = R_GetTexture(texture->skin.glow);
228 GL_Color(1, 1, 1, ent->alpha);
230 c_alias_polys += mesh->num_triangles;
231 GL_LockArrays(0, mesh->num_vertices);
232 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
238 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
240 m.tex[0] = R_GetTexture(texture->skin.fog);
241 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], fog * ent->alpha);
243 c_alias_polys += mesh->num_triangles;
244 GL_LockArrays(0, mesh->num_vertices);
245 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
250 void R_Model_Alias_Draw(entity_render_t *ent)
254 if (ent->alpha < (1.0f / 64.0f))
255 return; // basically completely transparent
259 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
261 if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->skin.fog)
262 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : ent->origin, R_DrawAliasModelCallback, ent, meshnum);
264 R_DrawAliasModelCallback(ent, meshnum);
268 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)
273 float projectdistance, *vertex3f;
274 if (!(ent->flags & RENDER_SHADOW))
276 // check the box in modelspace, it was already checked in worldspace
277 if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs))
279 projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin));
280 if (projectdistance > 0.1)
282 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
284 texture = R_FetchAliasSkin(ent, mesh);
285 if (texture->skin.fog)
287 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
288 vertex3f = mesh->data_basevertex3f;
291 vertex3f = varray_vertex3f;
292 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
294 // identify lit faces within the bounding box
295 R_Shadow_PrepareShadowMark(mesh->num_triangles);
296 R_Shadow_MarkVolumeFromBox(0, mesh->num_triangles, vertex3f, mesh->data_element3i, relativelightorigin, lightmins, lightmaxs, ent->model->normalmins, ent->model->normalmaxs);
297 R_Shadow_VolumeFromList(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist);
302 void R_Model_Alias_DrawLight(entity_render_t *ent, float *lightcolor, int numsurfaces, const int *surfacelist)
305 float fog, ifog, lightcolorbase[3], lightcolorpants[3], lightcolorshirt[3];
306 float *vertex3f, *svector3f, *tvector3f, *normal3f;
315 VectorSubtract(ent->origin, r_vieworigin, diff);
316 fog = DotProduct(diff,diff);
319 fog = exp(fogdensity/fog);
324 // fog method: darken, additive fog
325 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
326 // 2. render fog as additive
330 VectorScale(lightcolor, ifog, lightcolorbase);
331 if (VectorLength2(lightcolorbase) < 0.001)
333 VectorClear(lightcolorpants);
334 VectorClear(lightcolorshirt);
335 if (ent->colormap >= 0)
337 // 128-224 are backwards ranges
338 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
339 // fullbright passes were already taken care of, so skip them in realtime lighting passes
342 bcolor = (qbyte *) (&palette_complete[c]);
343 lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
344 lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
345 lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
347 // 128-224 are backwards ranges
348 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
349 // fullbright passes were already taken care of, so skip them in realtime lighting passes
352 bcolor = (qbyte *) (&palette_complete[c]);
353 lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
354 lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
355 lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
359 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
361 texture = R_FetchAliasSkin(ent, mesh);
362 // FIXME: transparent skins need to be lit during the transparent render
363 if (texture->skin.fog)
365 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
367 vertex3f = mesh->data_basevertex3f;
368 svector3f = mesh->data_basesvector3f;
369 tvector3f = mesh->data_basetvector3f;
370 normal3f = mesh->data_basenormal3f;
374 vertex3f = varray_vertex3f;
375 svector3f = varray_svector3f;
376 tvector3f = varray_tvector3f;
377 normal3f = varray_normal3f;
378 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
379 Mod_BuildTextureVectorsAndNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
381 c_alias_polys += mesh->num_triangles;
382 R_Shadow_RenderLighting(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, lightcolorbase, lightcolorpants, lightcolorshirt, (ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged, ent->colormap >= 0 ? texture->skin.pants : 0, ent->colormap >= 0 ? texture->skin.shirt : 0, texture->skin.nmap, texture->skin.gloss);