5 static texture_t r_aliasnotexture;
6 static texture_t *R_FetchAliasSkin(const entity_render_t *ent, const surfmesh_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 msurface_t *surface = ent->model->data_surfaces + calldata2;
40 surfmesh_t *mesh = surface->groupmesh;
43 R_Mesh_Matrix(&ent->matrix);
48 VectorSubtract(ent->origin, r_vieworigin, diff);
49 fog = DotProduct(diff,diff);
52 fog = exp(fogdensity/fog);
57 // fog method: darken, additive fog
58 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
59 // 2. render fog as additive
63 VectorScale(ent->colormod, ifog, colorbase);
64 VectorClear(colorpants);
65 VectorClear(colorshirt);
66 fbbase = ent->effects & EF_FULLBRIGHT;
69 if (ent->colormap >= 0)
71 // 128-224 are backwards ranges
72 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
75 bcolor = (qbyte *) (&palette_complete[c]);
76 colorpants[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f);
77 colorpants[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f);
78 colorpants[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f);
79 // 128-224 are backwards ranges
80 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
83 bcolor = (qbyte *) (&palette_complete[c]);
84 colorshirt[0] = colorbase[0] * bcolor[0] * (1.0f / 255.0f);
85 colorshirt[1] = colorbase[1] * bcolor[1] * (1.0f / 255.0f);
86 colorshirt[2] = colorbase[2] * bcolor[2] * (1.0f / 255.0f);
89 texture = R_FetchAliasSkin(ent, mesh);
91 if ((ent->effects & EF_ADDITIVE))
93 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
96 else if (texture->skin.fog || ent->alpha != 1.0)
98 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
103 GL_BlendFunc(GL_ONE, GL_ZERO);
106 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
108 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
110 vertex3f = mesh->data_vertex3f;
111 normal3f = mesh->data_normal3f;
115 vertex3f = varray_vertex3f;
116 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
120 doglow = texture->skin.glow != NULL;
122 memset(&m, 0, sizeof(m));
123 m.pointer_vertex = vertex3f;
124 m.pointer_texcoord[0] = mesh->data_texcoordtexture2f;
125 if (gl_combine.integer)
128 m.texrgbscale[0] = 4;
131 m.tex[0] = R_GetTexture((ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged);
132 VectorScale(colorbase, colorscale, tint);
133 m.pointer_color = NULL;
135 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
136 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
138 m.pointer_color = varray_color4f;
139 if (normal3f == NULL)
141 normal3f = varray_normal3f;
142 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
144 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
147 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
148 if (gl_combine.integer && doglow)
151 m.tex[1] = R_GetTexture(texture->skin.glow);
152 m.pointer_texcoord[1] = mesh->data_texcoordtexture2f;
153 m.texcombinergb[1] = GL_ADD;
156 c_alias_polys += mesh->num_triangles;
157 GL_LockArrays(0, mesh->num_vertices);
158 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
161 m.pointer_texcoord[1] = NULL;
162 m.texcombinergb[1] = 0;
164 VectorScale(colorpants, colorscale, tint);
165 if (ent->colormap >= 0 && texture->skin.pants && VectorLength2(tint) >= 0.001)
167 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
169 m.tex[0] = R_GetTexture(texture->skin.pants);
170 m.pointer_color = NULL;
172 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
173 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
175 m.pointer_color = varray_color4f;
176 if (normal3f == NULL)
178 normal3f = varray_normal3f;
179 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
181 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
184 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
186 c_alias_polys += mesh->num_triangles;
187 GL_LockArrays(0, mesh->num_vertices);
188 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
192 VectorScale(colorshirt, colorscale, tint);
193 if (ent->colormap >= 0 && texture->skin.shirt && VectorLength2(tint) >= 0.001)
195 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
197 m.tex[0] = R_GetTexture(texture->skin.shirt);
198 m.pointer_color = NULL;
200 GL_Color(tint[0], tint[1], tint[2], ent->alpha);
201 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0], tint[1], tint[2], ent->alpha, false))
203 m.pointer_color = varray_color4f;
204 if (normal3f == NULL)
206 normal3f = varray_normal3f;
207 Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
209 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
212 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
214 c_alias_polys += mesh->num_triangles;
215 GL_LockArrays(0, mesh->num_vertices);
216 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
221 m.texrgbscale[0] = 0;
222 m.pointer_color = NULL;
226 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
228 m.tex[0] = R_GetTexture(texture->skin.glow);
229 GL_Color(1, 1, 1, ent->alpha);
231 c_alias_polys += mesh->num_triangles;
232 GL_LockArrays(0, mesh->num_vertices);
233 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
239 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
241 m.tex[0] = R_GetTexture(texture->skin.fog);
242 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], fog * ent->alpha);
244 c_alias_polys += mesh->num_triangles;
245 GL_LockArrays(0, mesh->num_vertices);
246 R_Mesh_Draw(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
251 void R_Model_Alias_Draw(entity_render_t *ent)
256 if (ent->alpha < (1.0f / 64.0f))
257 return; // basically completely transparent
261 for (surfacenum = 0, surface = ent->model->data_surfaces;surfacenum < ent->model->num_surfaces;surfacenum++, surface++)
263 mesh = surface->groupmesh;
264 if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->skin.fog)
265 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : ent->origin, R_DrawAliasModelCallback, ent, surfacenum);
267 R_DrawAliasModelCallback(ent, surfacenum);
271 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)
277 float projectdistance, *vertex3f;
278 if (!(ent->flags & RENDER_SHADOW))
280 // check the box in modelspace, it was already checked in worldspace
281 if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs))
283 projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin));
284 if (projectdistance > 0.1)
286 for (surfacenum = 0, surface = ent->model->data_surfaces;surfacenum < ent->model->num_surfaces;surfacenum++, surface++)
288 mesh = surface->groupmesh;
289 texture = R_FetchAliasSkin(ent, mesh);
290 if (texture->skin.fog)
292 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
293 vertex3f = mesh->data_vertex3f;
296 vertex3f = varray_vertex3f;
297 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
299 // identify lit faces within the bounding box
300 R_Shadow_PrepareShadowMark(mesh->num_triangles);
301 R_Shadow_MarkVolumeFromBox(0, mesh->num_triangles, vertex3f, mesh->data_element3i, relativelightorigin, lightmins, lightmaxs, ent->model->normalmins, ent->model->normalmaxs);
302 R_Shadow_VolumeFromList(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist);
307 void R_Model_Alias_DrawLight(entity_render_t *ent, float *lightcolor, int numsurfaces, const int *surfacelist)
310 float fog, ifog, lightcolorbase[3], lightcolorpants[3], lightcolorshirt[3];
311 float *vertex3f, *svector3f, *tvector3f, *normal3f;
322 VectorSubtract(ent->origin, r_vieworigin, diff);
323 fog = DotProduct(diff,diff);
326 fog = exp(fogdensity/fog);
331 // fog method: darken, additive fog
332 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
333 // 2. render fog as additive
337 VectorScale(lightcolor, ifog, lightcolorbase);
338 if (VectorLength2(lightcolorbase) < 0.001)
340 VectorClear(lightcolorpants);
341 VectorClear(lightcolorshirt);
342 if (ent->colormap >= 0)
344 // 128-224 are backwards ranges
345 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
346 // fullbright passes were already taken care of, so skip them in realtime lighting passes
349 bcolor = (qbyte *) (&palette_complete[c]);
350 lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
351 lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
352 lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
354 // 128-224 are backwards ranges
355 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
356 // fullbright passes were already taken care of, so skip them in realtime lighting passes
359 bcolor = (qbyte *) (&palette_complete[c]);
360 lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
361 lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
362 lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
366 for (surfacenum = 0, surface = ent->model->data_surfaces;surfacenum < ent->model->num_surfaces;surfacenum++, surface++)
368 mesh = surface->groupmesh;
369 texture = R_FetchAliasSkin(ent, mesh);
370 // FIXME: transparent skins need to be lit during the transparent render
371 if (texture->skin.fog)
373 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
375 vertex3f = mesh->data_vertex3f;
376 svector3f = mesh->data_svector3f;
377 tvector3f = mesh->data_tvector3f;
378 normal3f = mesh->data_normal3f;
382 vertex3f = varray_vertex3f;
383 svector3f = varray_svector3f;
384 tvector3f = varray_tvector3f;
385 normal3f = varray_normal3f;
386 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
387 Mod_BuildTextureVectorsAndNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoordtexture2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
389 c_alias_polys += mesh->num_triangles;
390 R_Shadow_RenderLighting(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoordtexture2f, 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);