bmodel shadow volumes
[xonotic/darkplaces.git] / gl_models.c
1
2 #include "quakedef.h"
3 #include "cl_collision.h"
4 #include "r_shadow.h"
5
6 cvar_t r_quickmodels = {0, "r_quickmodels", "1"};
7
8 typedef struct
9 {
10         float m[3][4];
11 } zymbonematrix;
12
13 // LordHavoc: vertex arrays
14
15 float *aliasvertbuf;
16 float *aliasvertcolorbuf;
17 float *aliasvert; // this may point at aliasvertbuf or at vertex arrays in the mesh backend
18 float *aliasvertcolor; // this may point at aliasvertcolorbuf or at vertex arrays in the mesh backend
19
20 float *aliasvertcolor2;
21 float *aliasvertnorm;
22 int *aliasvertusage;
23 zymbonematrix *zymbonepose;
24
25 mempool_t *gl_models_mempool;
26
27 void gl_models_start(void)
28 {
29         // allocate vertex processing arrays
30         gl_models_mempool = Mem_AllocPool("GL_Models");
31         aliasvert = aliasvertbuf = Mem_Alloc(gl_models_mempool, sizeof(float[MD2MAX_VERTS][4]));
32         aliasvertcolor = aliasvertcolorbuf = Mem_Alloc(gl_models_mempool, sizeof(float[MD2MAX_VERTS][4]));
33         aliasvertnorm = Mem_Alloc(gl_models_mempool, sizeof(float[MD2MAX_VERTS][3]));
34         aliasvertcolor2 = Mem_Alloc(gl_models_mempool, sizeof(float[MD2MAX_VERTS][4])); // used temporarily for tinted coloring
35         zymbonepose = Mem_Alloc(gl_models_mempool, sizeof(zymbonematrix[256]));
36         aliasvertusage = Mem_Alloc(gl_models_mempool, sizeof(int[MD2MAX_VERTS]));
37 }
38
39 void gl_models_shutdown(void)
40 {
41         Mem_FreePool(&gl_models_mempool);
42 }
43
44 void gl_models_newmap(void)
45 {
46 }
47
48 void GL_Models_Init(void)
49 {
50         Cvar_RegisterVariable(&r_quickmodels);
51
52         R_RegisterModule("GL_Models", gl_models_start, gl_models_shutdown, gl_models_newmap);
53 }
54
55 /*
56 void R_AliasTransformVerts(int vertcount)
57 {
58         vec3_t point;
59         float *av;
60         av = aliasvert;
61         while (vertcount >= 4)
62         {
63                 VectorCopy(av, point);softwaretransform(point, av);av += 4;
64                 VectorCopy(av, point);softwaretransform(point, av);av += 4;
65                 VectorCopy(av, point);softwaretransform(point, av);av += 4;
66                 VectorCopy(av, point);softwaretransform(point, av);av += 4;
67                 vertcount -= 4;
68         }
69         while(vertcount > 0)
70         {
71                 VectorCopy(av, point);softwaretransform(point, av);av += 4;
72                 vertcount--;
73         }
74 }
75 */
76
77 void R_AliasLerpVerts(int vertcount, float *vertices, float *normals,
78                 float lerp1, const trivertx_t *verts1, const vec3_t fscale1, const vec3_t translate1,
79                 float lerp2, const trivertx_t *verts2, const vec3_t fscale2, const vec3_t translate2,
80                 float lerp3, const trivertx_t *verts3, const vec3_t fscale3, const vec3_t translate3,
81                 float lerp4, const trivertx_t *verts4, const vec3_t fscale4, const vec3_t translate4)
82 {
83         int i;
84         vec3_t scale1, scale2, scale3, scale4, translate;
85         const float *n1, *n2, *n3, *n4;
86         float *av, *avn;
87         av = vertices;
88         avn = normals;
89         VectorScale(fscale1, lerp1, scale1);
90         if (lerp2)
91         {
92                 VectorScale(fscale2, lerp2, scale2);
93                 if (lerp3)
94                 {
95                         VectorScale(fscale3, lerp3, scale3);
96                         if (lerp4)
97                         {
98                                 VectorScale(fscale4, lerp4, scale4);
99                                 translate[0] = translate1[0] * lerp1 + translate2[0] * lerp2 + translate3[0] * lerp3 + translate4[0] * lerp4;
100                                 translate[1] = translate1[1] * lerp1 + translate2[1] * lerp2 + translate3[1] * lerp3 + translate4[1] * lerp4;
101                                 translate[2] = translate1[2] * lerp1 + translate2[2] * lerp2 + translate3[2] * lerp3 + translate4[2] * lerp4;
102                                 // generate vertices
103                                 for (i = 0;i < vertcount;i++)
104                                 {
105                                         av[0] = verts1->v[0] * scale1[0] + verts2->v[0] * scale2[0] + verts3->v[0] * scale3[0] + verts4->v[0] * scale4[0] + translate[0];
106                                         av[1] = verts1->v[1] * scale1[1] + verts2->v[1] * scale2[1] + verts3->v[1] * scale3[1] + verts4->v[1] * scale4[1] + translate[1];
107                                         av[2] = verts1->v[2] * scale1[2] + verts2->v[2] * scale2[2] + verts3->v[2] * scale3[2] + verts4->v[2] * scale4[2] + translate[2];
108                                         n1 = m_bytenormals[verts1->lightnormalindex];
109                                         n2 = m_bytenormals[verts2->lightnormalindex];
110                                         n3 = m_bytenormals[verts3->lightnormalindex];
111                                         n4 = m_bytenormals[verts4->lightnormalindex];
112                                         avn[0] = n1[0] * lerp1 + n2[0] * lerp2 + n3[0] * lerp3 + n4[0] * lerp4;
113                                         avn[1] = n1[1] * lerp1 + n2[1] * lerp2 + n3[1] * lerp3 + n4[1] * lerp4;
114                                         avn[2] = n1[2] * lerp1 + n2[2] * lerp2 + n3[2] * lerp3 + n4[2] * lerp4;
115                                         av += 4;
116                                         avn += 3;
117                                         verts1++;verts2++;verts3++;verts4++;
118                                 }
119                         }
120                         else
121                         {
122                                 translate[0] = translate1[0] * lerp1 + translate2[0] * lerp2 + translate3[0] * lerp3;
123                                 translate[1] = translate1[1] * lerp1 + translate2[1] * lerp2 + translate3[1] * lerp3;
124                                 translate[2] = translate1[2] * lerp1 + translate2[2] * lerp2 + translate3[2] * lerp3;
125                                 // generate vertices
126                                 for (i = 0;i < vertcount;i++)
127                                 {
128                                         av[0] = verts1->v[0] * scale1[0] + verts2->v[0] * scale2[0] + verts3->v[0] * scale3[0] + translate[0];
129                                         av[1] = verts1->v[1] * scale1[1] + verts2->v[1] * scale2[1] + verts3->v[1] * scale3[1] + translate[1];
130                                         av[2] = verts1->v[2] * scale1[2] + verts2->v[2] * scale2[2] + verts3->v[2] * scale3[2] + translate[2];
131                                         n1 = m_bytenormals[verts1->lightnormalindex];
132                                         n2 = m_bytenormals[verts2->lightnormalindex];
133                                         n3 = m_bytenormals[verts3->lightnormalindex];
134                                         avn[0] = n1[0] * lerp1 + n2[0] * lerp2 + n3[0] * lerp3;
135                                         avn[1] = n1[1] * lerp1 + n2[1] * lerp2 + n3[1] * lerp3;
136                                         avn[2] = n1[2] * lerp1 + n2[2] * lerp2 + n3[2] * lerp3;
137                                         av += 4;
138                                         avn += 3;
139                                         verts1++;verts2++;verts3++;
140                                 }
141                         }
142                 }
143                 else
144                 {
145                         translate[0] = translate1[0] * lerp1 + translate2[0] * lerp2;
146                         translate[1] = translate1[1] * lerp1 + translate2[1] * lerp2;
147                         translate[2] = translate1[2] * lerp1 + translate2[2] * lerp2;
148                         // generate vertices
149                         for (i = 0;i < vertcount;i++)
150                         {
151                                 av[0] = verts1->v[0] * scale1[0] + verts2->v[0] * scale2[0] + translate[0];
152                                 av[1] = verts1->v[1] * scale1[1] + verts2->v[1] * scale2[1] + translate[1];
153                                 av[2] = verts1->v[2] * scale1[2] + verts2->v[2] * scale2[2] + translate[2];
154                                 n1 = m_bytenormals[verts1->lightnormalindex];
155                                 n2 = m_bytenormals[verts2->lightnormalindex];
156                                 avn[0] = n1[0] * lerp1 + n2[0] * lerp2;
157                                 avn[1] = n1[1] * lerp1 + n2[1] * lerp2;
158                                 avn[2] = n1[2] * lerp1 + n2[2] * lerp2;
159                                 av += 4;
160                                 avn += 3;
161                                 verts1++;verts2++;
162                         }
163                 }
164         }
165         else
166         {
167                 translate[0] = translate1[0] * lerp1;
168                 translate[1] = translate1[1] * lerp1;
169                 translate[2] = translate1[2] * lerp1;
170                 // generate vertices
171                 if (lerp1 != 1)
172                 {
173                         // general but almost never used case
174                         for (i = 0;i < vertcount;i++)
175                         {
176                                 av[0] = verts1->v[0] * scale1[0] + translate[0];
177                                 av[1] = verts1->v[1] * scale1[1] + translate[1];
178                                 av[2] = verts1->v[2] * scale1[2] + translate[2];
179                                 n1 = m_bytenormals[verts1->lightnormalindex];
180                                 avn[0] = n1[0] * lerp1;
181                                 avn[1] = n1[1] * lerp1;
182                                 avn[2] = n1[2] * lerp1;
183                                 av += 4;
184                                 avn += 3;
185                                 verts1++;
186                         }
187                 }
188                 else
189                 {
190                         // fast normal case
191                         for (i = 0;i < vertcount;i++)
192                         {
193                                 av[0] = verts1->v[0] * scale1[0] + translate[0];
194                                 av[1] = verts1->v[1] * scale1[1] + translate[1];
195                                 av[2] = verts1->v[2] * scale1[2] + translate[2];
196                                 VectorCopy(m_bytenormals[verts1->lightnormalindex], avn);
197                                 av += 4;
198                                 avn += 3;
199                                 verts1++;
200                         }
201                 }
202         }
203 }
204
205 skinframe_t *R_FetchSkinFrame(const entity_render_t *ent)
206 {
207         model_t *model = ent->model;
208         unsigned int s = (unsigned int) ent->skinnum;
209         if (s >= model->numskins)
210                 s = 0;
211         if (model->skinscenes[s].framecount > 1)
212                 return &model->skinframes[model->skinscenes[s].firstframe + (int) (cl.time * 10) % model->skinscenes[s].framecount];
213         else
214                 return &model->skinframes[model->skinscenes[s].firstframe];
215 }
216
217 void R_LerpMDLMD2Vertices(const entity_render_t *ent, float *vertices, float *normals)
218 {
219         const md2frame_t *frame1, *frame2, *frame3, *frame4;
220         const trivertx_t *frame1verts, *frame2verts, *frame3verts, *frame4verts;
221         const model_t *model = ent->model;
222
223         frame1 = &model->mdlmd2data_frames[ent->frameblend[0].frame];
224         frame2 = &model->mdlmd2data_frames[ent->frameblend[1].frame];
225         frame3 = &model->mdlmd2data_frames[ent->frameblend[2].frame];
226         frame4 = &model->mdlmd2data_frames[ent->frameblend[3].frame];
227         frame1verts = &model->mdlmd2data_pose[ent->frameblend[0].frame * model->numverts];
228         frame2verts = &model->mdlmd2data_pose[ent->frameblend[1].frame * model->numverts];
229         frame3verts = &model->mdlmd2data_pose[ent->frameblend[2].frame * model->numverts];
230         frame4verts = &model->mdlmd2data_pose[ent->frameblend[3].frame * model->numverts];
231         R_AliasLerpVerts(model->numverts, vertices, normals,
232                 ent->frameblend[0].lerp, frame1verts, frame1->scale, frame1->translate,
233                 ent->frameblend[1].lerp, frame2verts, frame2->scale, frame2->translate,
234                 ent->frameblend[2].lerp, frame3verts, frame3->scale, frame3->translate,
235                 ent->frameblend[3].lerp, frame4verts, frame4->scale, frame4->translate);
236 }
237
238 void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
239 {
240         int i, c, pantsfullbright, shirtfullbright, colormapped, tex;
241         float pantscolor[3], shirtcolor[3];
242         float fog, colorscale;
243         vec3_t diff;
244         qbyte *bcolor;
245         rmeshstate_t m;
246         model_t *model;
247         skinframe_t *skinframe;
248         const entity_render_t *ent = calldata1;
249         int blendfunc1, blendfunc2;
250
251 //      softwaretransformforentity(ent);
252         R_Mesh_Matrix(&ent->matrix);
253
254         fog = 0;
255         if (fogenabled)
256         {
257                 VectorSubtract(ent->origin, r_origin, diff);
258                 fog = DotProduct(diff,diff);
259                 if (fog < 0.01f)
260                         fog = 0.01f;
261                 fog = exp(fogdensity/fog);
262                 if (fog > 1)
263                         fog = 1;
264                 if (fog < 0.01f)
265                         fog = 0;
266                 // fog method: darken, additive fog
267                 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
268                 // 2. render fog as additive
269         }
270
271         model = ent->model;
272         R_Mesh_ResizeCheck(model->numverts);
273
274         skinframe = R_FetchSkinFrame(ent);
275
276         if (ent->effects & EF_ADDITIVE)
277         {
278                 blendfunc1 = GL_SRC_ALPHA;
279                 blendfunc2 = GL_ONE;
280         }
281         else if (ent->alpha != 1.0 || skinframe->fog != NULL)
282         {
283                 blendfunc1 = GL_SRC_ALPHA;
284                 blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
285         }
286         else
287         {
288                 blendfunc1 = GL_ONE;
289                 blendfunc2 = GL_ZERO;
290         }
291
292         colorscale = r_colorscale;
293         if (gl_combine.integer)
294                 colorscale *= 0.25f;
295
296         if (!skinframe->base && !skinframe->pants && !skinframe->shirt && !skinframe->glow)
297         {
298                 // untextured
299                 memset(&m, 0, sizeof(m));
300                 m.blendfunc1 = blendfunc1;
301                 m.blendfunc2 = blendfunc2;
302                 if (gl_combine.integer)
303                         m.texrgbscale[0] = 4;
304                 m.tex[0] = R_GetTexture(r_notexture);
305                 R_Mesh_State(&m);
306
307                 c_alias_polys += model->numtris;
308                 for (i = 0;i < model->numverts * 2;i++)
309                         varray_texcoord[0][i] = model->mdlmd2data_texcoords[i] * 8.0f;
310                 aliasvert = varray_vertex;
311                 aliasvertcolor = varray_color;
312                 R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
313                 R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
314                 aliasvert = aliasvertbuf;
315                 aliasvertcolor = aliasvertcolorbuf;
316                 GL_UseColorArray();
317                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
318                 return;
319         }
320
321
322         colormapped = !skinframe->merged || (ent->colormap >= 0 && skinframe->base && (skinframe->pants || skinframe->shirt));
323         if (!colormapped && !fog && !skinframe->glow && !skinframe->fog)
324         {
325                 // fastpath for the normal situation (one texture)
326                 memset(&m, 0, sizeof(m));
327                 m.blendfunc1 = blendfunc1;
328                 m.blendfunc2 = blendfunc2;
329                 if (gl_combine.integer)
330                         m.texrgbscale[0] = 4;
331                 m.tex[0] = R_GetTexture(skinframe->merged);
332                 R_Mesh_State(&m);
333
334                 c_alias_polys += model->numtris;
335                 memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
336                 aliasvert = varray_vertex;
337                 aliasvertcolor = varray_color;
338                 R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
339                 R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
340                 aliasvert = aliasvertbuf;
341                 aliasvertcolor = aliasvertcolorbuf;
342                 GL_UseColorArray();
343                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
344                 return;
345         }
346
347         R_LerpMDLMD2Vertices(ent, aliasvert, aliasvertnorm);
348         R_LightModel(ent, model->numverts, colorscale * (1 - fog), colorscale * (1 - fog), colorscale * (1 - fog), false);
349
350         if (colormapped)
351         {
352                 // 128-224 are backwards ranges
353                 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
354                 bcolor = (qbyte *) (&d_8to24table[c]);
355                 pantsfullbright = c >= 224;
356                 VectorScale(bcolor, (1.0f / 255.0f), pantscolor);
357                 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
358                 bcolor = (qbyte *) (&d_8to24table[c]);
359                 shirtfullbright = c >= 224;
360                 VectorScale(bcolor, (1.0f / 255.0f), shirtcolor);
361         }
362         else
363         {
364                 pantscolor[0] = pantscolor[1] = pantscolor[2] = shirtcolor[0] = shirtcolor[1] = shirtcolor[2] = 1;
365                 pantsfullbright = shirtfullbright = false;
366         }
367
368         tex = colormapped ? R_GetTexture(skinframe->base) : R_GetTexture(skinframe->merged);
369         if (tex)
370         {
371                 memset(&m, 0, sizeof(m));
372                 m.blendfunc1 = blendfunc1;
373                 m.blendfunc2 = blendfunc2;
374                 if (gl_combine.integer)
375                         m.texrgbscale[0] = 4;
376                 m.tex[0] = tex;
377                 R_Mesh_State(&m);
378
379                 blendfunc1 = GL_SRC_ALPHA;
380                 blendfunc2 = GL_ONE;
381                 c_alias_polys += model->numtris;
382                 R_ModulateColors(aliasvertcolor, varray_color, model->numverts, colorscale, colorscale, colorscale);
383                 memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
384                 memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
385                 GL_UseColorArray();
386                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
387         }
388
389         if (colormapped)
390         {
391                 if (skinframe->pants)
392                 {
393                         tex = R_GetTexture(skinframe->pants);
394                         if (tex)
395                         {
396                                 memset(&m, 0, sizeof(m));
397                                 m.blendfunc1 = blendfunc1;
398                                 m.blendfunc2 = blendfunc2;
399                                 if (gl_combine.integer)
400                                         m.texrgbscale[0] = 4;
401                                 m.tex[0] = tex;
402                                 R_Mesh_State(&m);
403
404                                 blendfunc1 = GL_SRC_ALPHA;
405                                 blendfunc2 = GL_ONE;
406                                 c_alias_polys += model->numtris;
407                                 if (pantsfullbright)
408                                         GL_Color(pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha);
409                                 else
410                                 {
411                                         GL_UseColorArray();
412                                         R_ModulateColors(aliasvertcolor, varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale);
413                                 }
414                                 memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
415                                 memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
416                                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
417                         }
418                 }
419                 if (skinframe->shirt)
420                 {
421                         tex = R_GetTexture(skinframe->shirt);
422                         if (tex)
423                         {
424                                 memset(&m, 0, sizeof(m));
425                                 m.blendfunc1 = blendfunc1;
426                                 m.blendfunc2 = blendfunc2;
427                                 if (gl_combine.integer)
428                                         m.texrgbscale[0] = 4;
429                                 m.tex[0] = tex;
430                                 R_Mesh_State(&m);
431
432                                 blendfunc1 = GL_SRC_ALPHA;
433                                 blendfunc2 = GL_ONE;
434                                 c_alias_polys += model->numtris;
435                                 if (shirtfullbright)
436                                         GL_Color(shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha);
437                                 else
438                                 {
439                                         GL_UseColorArray();
440                                         R_ModulateColors(aliasvertcolor, varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale);
441                                 }
442                                 memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
443                                 memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
444                                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
445                         }
446                 }
447         }
448         if (skinframe->glow)
449         {
450                 tex = R_GetTexture(skinframe->glow);
451                 if (tex)
452                 {
453                         memset(&m, 0, sizeof(m));
454                         m.blendfunc1 = blendfunc1;
455                         m.blendfunc2 = blendfunc2;
456                         m.tex[0] = tex;
457                         R_Mesh_State(&m);
458
459                         blendfunc1 = GL_SRC_ALPHA;
460                         blendfunc2 = GL_ONE;
461                         c_alias_polys += model->numtris;
462                         memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
463                         memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
464                         GL_Color((1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha);
465                         R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
466                 }
467         }
468         if (fog)
469         {
470                 memset(&m, 0, sizeof(m));
471                 m.blendfunc1 = GL_SRC_ALPHA;
472                 m.blendfunc2 = GL_ONE;
473                 m.tex[0] = R_GetTexture(skinframe->fog);
474                 R_Mesh_State(&m);
475
476                 c_alias_polys += model->numtris;
477                 memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
478                 memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
479                 GL_Color(fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha);
480                 R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
481         }
482 }
483
484 extern cvar_t r_shadows;
485 void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
486 {
487         int i;
488         rmeshstate_t m;
489         model_t *model;
490         float *v, planenormal[3], planedist, dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
491         mlight_t *sl;
492         rdlight_t *rd;
493
494         if (r_shadows.integer > 1)
495         {
496                 float f, lightscale, lightcolor[3];
497                 vec3_t temp;
498                 memset(&m, 0, sizeof(m));
499                 m.blendfunc1 = GL_ONE;
500                 m.blendfunc2 = GL_ONE;
501                 R_Mesh_State(&m);
502                 R_Mesh_Matrix(&ent->matrix);
503                 for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights;i++, sl++)
504                 {
505                         if (d_lightstylevalue[sl->style] > 0)
506                         {
507                                 VectorSubtract(ent->origin, sl->origin, temp);
508                                 f = DotProduct(temp,temp);
509                                 if (f < (ent->model->radius2 + sl->cullradius2))
510                                 {
511                                         model = ent->model;
512                                         R_Mesh_ResizeCheck(model->numverts * 2);
513                                         R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
514                                         Matrix4x4_Transform(&ent->inversematrix, sl->origin, temp);
515                                         GL_Color(0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1);
516                                         R_Shadow_Volume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, sl->cullradius + model->radius - sqrt(f), true);
517                                         GL_UseColorArray();
518                                         lightscale = d_lightstylevalue[sl->style] * (1.0f / 65536.0f);
519                                         VectorScale(sl->light, lightscale, lightcolor);
520                                         R_Shadow_VertexLight(model->numverts, aliasvertnorm, temp, sl->cullradius2, sl->distbias, sl->subtract, lightcolor);
521                                         R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
522                                 }
523                         }
524                 }
525                 for (i = 0, rd = r_dlight;i < r_numdlights;i++, rd++)
526                 {
527                         if (ent != rd->ent)
528                         {
529                                 VectorSubtract(ent->origin, rd->origin, temp);
530                                 f = DotProduct(temp,temp);
531                                 if (f < (ent->model->radius2 + rd->cullradius2))
532                                 {
533                                         model = ent->model;
534                                         R_Mesh_ResizeCheck(model->numverts * 2);
535                                         R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
536                                         Matrix4x4_Transform(&ent->inversematrix, rd->origin, temp);
537                                         GL_Color(0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1);
538                                         R_Shadow_Volume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, rd->cullradius + model->radius - sqrt(f), true);
539                                         GL_UseColorArray();
540                                         R_Shadow_VertexLight(model->numverts, aliasvertnorm, temp, rd->cullradius2, LIGHTOFFSET, rd->subtract, rd->light);
541                                         R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
542                                 }
543                         }
544                 }
545                 return;
546         }
547
548         lightdirection[0] = 0.5;
549         lightdirection[1] = 0.2;
550         lightdirection[2] = -1;
551         VectorNormalizeFast(lightdirection);
552
553         VectorMA(ent->origin, 65536.0f, lightdirection, v2);
554         if (CL_TraceLine(ent->origin, v2, floororigin, surfnormal, 0, false, NULL) == 1)
555                 return;
556
557         R_Mesh_Matrix(&ent->matrix);
558
559         model = ent->model;
560         R_Mesh_ResizeCheck(model->numverts);
561
562         memset(&m, 0, sizeof(m));
563         m.blendfunc1 = GL_SRC_ALPHA;
564         m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
565         R_Mesh_State(&m);
566
567         c_alias_polys += model->numtris;
568         R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
569
570         // put a light direction in the entity's coordinate space
571         Matrix4x4_Transform3x3(&ent->inversematrix, lightdirection, projection);
572         VectorNormalizeFast(projection);
573
574         // put the plane's normal in the entity's coordinate space
575         Matrix4x4_Transform3x3(&ent->inversematrix, surfnormal, planenormal);
576         VectorNormalizeFast(planenormal);
577
578         // put the plane's distance in the entity's coordinate space
579         VectorSubtract(floororigin, ent->origin, floororigin);
580         planedist = DotProduct(floororigin, surfnormal) + 2;
581
582         dist = -1.0f / DotProduct(projection, planenormal);
583         VectorScale(projection, dist, projection);
584         for (i = 0, v = varray_vertex;i < model->numverts;i++, v += 4)
585         {
586                 dist = DotProduct(v, planenormal) - planedist;
587                 if (dist > 0)
588                 //if (i & 1)
589                         VectorMA(v, dist, projection, v);
590         }
591         GL_Color(0, 0, 0, 0.5);
592         R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
593 }
594
595 int ZymoticLerpBones(int count, const zymbonematrix *bonebase, const frameblend_t *blend, const zymbone_t *bone)
596 {
597         int i;
598         float lerp1, lerp2, lerp3, lerp4;
599         zymbonematrix *out, rootmatrix, m;
600         const zymbonematrix *bone1, *bone2, *bone3, *bone4;
601
602         /*
603         // LordHavoc: combine transform from zym coordinate space to quake coordinate space with model to world transform matrix
604         rootmatrix.m[0][0] = softwaretransform_matrix[0][1];
605         rootmatrix.m[0][1] = -softwaretransform_matrix[0][0];
606         rootmatrix.m[0][2] = softwaretransform_matrix[0][2];
607         rootmatrix.m[0][3] = softwaretransform_matrix[0][3];
608         rootmatrix.m[1][0] = softwaretransform_matrix[1][1];
609         rootmatrix.m[1][1] = -softwaretransform_matrix[1][0];
610         rootmatrix.m[1][2] = softwaretransform_matrix[1][2];
611         rootmatrix.m[1][3] = softwaretransform_matrix[1][3];
612         rootmatrix.m[2][0] = softwaretransform_matrix[2][1];
613         rootmatrix.m[2][1] = -softwaretransform_matrix[2][0];
614         rootmatrix.m[2][2] = softwaretransform_matrix[2][2];
615         rootmatrix.m[2][3] = softwaretransform_matrix[2][3];
616         */
617         rootmatrix.m[0][0] = 1;
618         rootmatrix.m[0][1] = 0;
619         rootmatrix.m[0][2] = 0;
620         rootmatrix.m[0][3] = 0;
621         rootmatrix.m[1][0] = 0;
622         rootmatrix.m[1][1] = 1;
623         rootmatrix.m[1][2] = 0;
624         rootmatrix.m[1][3] = 0;
625         rootmatrix.m[2][0] = 0;
626         rootmatrix.m[2][1] = 0;
627         rootmatrix.m[2][2] = 1;
628         rootmatrix.m[2][3] = 0;
629
630         bone1 = bonebase + blend[0].frame * count;
631         lerp1 = blend[0].lerp;
632         if (blend[1].lerp)
633         {
634                 bone2 = bonebase + blend[1].frame * count;
635                 lerp2 = blend[1].lerp;
636                 if (blend[2].lerp)
637                 {
638                         bone3 = bonebase + blend[2].frame * count;
639                         lerp3 = blend[2].lerp;
640                         if (blend[3].lerp)
641                         {
642                                 // 4 poses
643                                 bone4 = bonebase + blend[3].frame * count;
644                                 lerp4 = blend[3].lerp;
645                                 for (i = 0, out = zymbonepose;i < count;i++, out++)
646                                 {
647                                         // interpolate matrices
648                                         m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2 + bone3->m[0][0] * lerp3 + bone4->m[0][0] * lerp4;
649                                         m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2 + bone3->m[0][1] * lerp3 + bone4->m[0][1] * lerp4;
650                                         m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2 + bone3->m[0][2] * lerp3 + bone4->m[0][2] * lerp4;
651                                         m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2 + bone3->m[0][3] * lerp3 + bone4->m[0][3] * lerp4;
652                                         m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2 + bone3->m[1][0] * lerp3 + bone4->m[1][0] * lerp4;
653                                         m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2 + bone3->m[1][1] * lerp3 + bone4->m[1][1] * lerp4;
654                                         m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2 + bone3->m[1][2] * lerp3 + bone4->m[1][2] * lerp4;
655                                         m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2 + bone3->m[1][3] * lerp3 + bone4->m[1][3] * lerp4;
656                                         m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2 + bone3->m[2][0] * lerp3 + bone4->m[2][0] * lerp4;
657                                         m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2 + bone3->m[2][1] * lerp3 + bone4->m[2][1] * lerp4;
658                                         m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2 + bone3->m[2][2] * lerp3 + bone4->m[2][2] * lerp4;
659                                         m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2 + bone3->m[2][3] * lerp3 + bone4->m[2][3] * lerp4;
660                                         if (bone->parent >= 0)
661                                                 R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
662                                         else
663                                                 R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
664                                         bone1++;
665                                         bone2++;
666                                         bone3++;
667                                         bone4++;
668                                         bone++;
669                                 }
670                         }
671                         else
672                         {
673                                 // 3 poses
674                                 for (i = 0, out = zymbonepose;i < count;i++, out++)
675                                 {
676                                         // interpolate matrices
677                                         m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2 + bone3->m[0][0] * lerp3;
678                                         m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2 + bone3->m[0][1] * lerp3;
679                                         m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2 + bone3->m[0][2] * lerp3;
680                                         m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2 + bone3->m[0][3] * lerp3;
681                                         m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2 + bone3->m[1][0] * lerp3;
682                                         m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2 + bone3->m[1][1] * lerp3;
683                                         m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2 + bone3->m[1][2] * lerp3;
684                                         m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2 + bone3->m[1][3] * lerp3;
685                                         m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2 + bone3->m[2][0] * lerp3;
686                                         m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2 + bone3->m[2][1] * lerp3;
687                                         m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2 + bone3->m[2][2] * lerp3;
688                                         m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2 + bone3->m[2][3] * lerp3;
689                                         if (bone->parent >= 0)
690                                                 R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
691                                         else
692                                                 R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
693                                         bone1++;
694                                         bone2++;
695                                         bone3++;
696                                         bone++;
697                                 }
698                         }
699                 }
700                 else
701                 {
702                         // 2 poses
703                         for (i = 0, out = zymbonepose;i < count;i++, out++)
704                         {
705                                 // interpolate matrices
706                                 m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2;
707                                 m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2;
708                                 m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2;
709                                 m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2;
710                                 m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2;
711                                 m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2;
712                                 m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2;
713                                 m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2;
714                                 m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2;
715                                 m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2;
716                                 m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2;
717                                 m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2;
718                                 if (bone->parent >= 0)
719                                         R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
720                                 else
721                                         R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
722                                 bone1++;
723                                 bone2++;
724                                 bone++;
725                         }
726                 }
727         }
728         else
729         {
730                 // 1 pose
731                 if (lerp1 != 1)
732                 {
733                         // lerp != 1.0
734                         for (i = 0, out = zymbonepose;i < count;i++, out++)
735                         {
736                                 // interpolate matrices
737                                 m.m[0][0] = bone1->m[0][0] * lerp1;
738                                 m.m[0][1] = bone1->m[0][1] * lerp1;
739                                 m.m[0][2] = bone1->m[0][2] * lerp1;
740                                 m.m[0][3] = bone1->m[0][3] * lerp1;
741                                 m.m[1][0] = bone1->m[1][0] * lerp1;
742                                 m.m[1][1] = bone1->m[1][1] * lerp1;
743                                 m.m[1][2] = bone1->m[1][2] * lerp1;
744                                 m.m[1][3] = bone1->m[1][3] * lerp1;
745                                 m.m[2][0] = bone1->m[2][0] * lerp1;
746                                 m.m[2][1] = bone1->m[2][1] * lerp1;
747                                 m.m[2][2] = bone1->m[2][2] * lerp1;
748                                 m.m[2][3] = bone1->m[2][3] * lerp1;
749                                 if (bone->parent >= 0)
750                                         R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
751                                 else
752                                         R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
753                                 bone1++;
754                                 bone++;
755                         }
756                 }
757                 else
758                 {
759                         // lerp == 1.0
760                         for (i = 0, out = zymbonepose;i < count;i++, out++)
761                         {
762                                 if (bone->parent >= 0)
763                                         R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &bone1->m[0][0], &out->m[0][0]);
764                                 else
765                                         R_ConcatTransforms(&rootmatrix.m[0][0], &bone1->m[0][0], &out->m[0][0]);
766                                 bone1++;
767                                 bone++;
768                         }
769                 }
770         }
771         return true;
772 }
773
774 void ZymoticTransformVerts(int vertcount, int *bonecounts, zymvertex_t *vert)
775 {
776         int c;
777         float *out = aliasvert;
778         zymbonematrix *matrix;
779         while(vertcount--)
780         {
781                 c = *bonecounts++;
782                 // FIXME: validate bonecounts at load time (must be >= 1)
783                 // FIXME: need 4th component in origin, for how much of the translate to blend in
784                 if (c == 1)
785                 {
786                         matrix = &zymbonepose[vert->bonenum];
787                         out[0] = vert->origin[0] * matrix->m[0][0] + vert->origin[1] * matrix->m[0][1] + vert->origin[2] * matrix->m[0][2] + matrix->m[0][3];
788                         out[1] = vert->origin[0] * matrix->m[1][0] + vert->origin[1] * matrix->m[1][1] + vert->origin[2] * matrix->m[1][2] + matrix->m[1][3];
789                         out[2] = vert->origin[0] * matrix->m[2][0] + vert->origin[1] * matrix->m[2][1] + vert->origin[2] * matrix->m[2][2] + matrix->m[2][3];
790                         vert++;
791                 }
792                 else
793                 {
794                         VectorClear(out);
795                         while(c--)
796                         {
797                                 matrix = &zymbonepose[vert->bonenum];
798                                 out[0] += vert->origin[0] * matrix->m[0][0] + vert->origin[1] * matrix->m[0][1] + vert->origin[2] * matrix->m[0][2] + matrix->m[0][3];
799                                 out[1] += vert->origin[0] * matrix->m[1][0] + vert->origin[1] * matrix->m[1][1] + vert->origin[2] * matrix->m[1][2] + matrix->m[1][3];
800                                 out[2] += vert->origin[0] * matrix->m[2][0] + vert->origin[1] * matrix->m[2][1] + vert->origin[2] * matrix->m[2][2] + matrix->m[2][3];
801                                 vert++;
802                         }
803                 }
804                 out += 4;
805         }
806 }
807
808 void ZymoticCalcNormals(int vertcount, int shadercount, int *renderlist)
809 {
810         int a, b, c, d;
811         float *out, v1[3], v2[3], normal[3], s;
812         int *u;
813         // clear normals
814         memset(aliasvertnorm, 0, sizeof(float) * vertcount * 3);
815         memset(aliasvertusage, 0, sizeof(int) * vertcount);
816         // parse render list and accumulate surface normals
817         while(shadercount--)
818         {
819                 d = *renderlist++;
820                 while (d--)
821                 {
822                         a = renderlist[0]*4;
823                         b = renderlist[1]*4;
824                         c = renderlist[2]*4;
825                         v1[0] = aliasvert[a+0] - aliasvert[b+0];
826                         v1[1] = aliasvert[a+1] - aliasvert[b+1];
827                         v1[2] = aliasvert[a+2] - aliasvert[b+2];
828                         v2[0] = aliasvert[c+0] - aliasvert[b+0];
829                         v2[1] = aliasvert[c+1] - aliasvert[b+1];
830                         v2[2] = aliasvert[c+2] - aliasvert[b+2];
831                         CrossProduct(v1, v2, normal);
832                         VectorNormalizeFast(normal);
833                         // add surface normal to vertices
834                         a = renderlist[0] * 3;
835                         aliasvertnorm[a+0] += normal[0];
836                         aliasvertnorm[a+1] += normal[1];
837                         aliasvertnorm[a+2] += normal[2];
838                         aliasvertusage[renderlist[0]]++;
839                         a = renderlist[1] * 3;
840                         aliasvertnorm[a+0] += normal[0];
841                         aliasvertnorm[a+1] += normal[1];
842                         aliasvertnorm[a+2] += normal[2];
843                         aliasvertusage[renderlist[1]]++;
844                         a = renderlist[2] * 3;
845                         aliasvertnorm[a+0] += normal[0];
846                         aliasvertnorm[a+1] += normal[1];
847                         aliasvertnorm[a+2] += normal[2];
848                         aliasvertusage[renderlist[2]]++;
849                         renderlist += 3;
850                 }
851         }
852         // FIXME: precalc this
853         // average surface normals
854         out = aliasvertnorm;
855         u = aliasvertusage;
856         while(vertcount--)
857         {
858                 if (*u > 1)
859                 {
860                         s = ixtable[*u];
861                         out[0] *= s;
862                         out[1] *= s;
863                         out[2] *= s;
864                 }
865                 u++;
866                 out += 3;
867         }
868 }
869
870 void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
871 {
872         float fog, colorscale;
873         vec3_t diff;
874         int i, *renderlist, *elements;
875         zymtype1header_t *m;
876         rtexture_t *texture;
877         rmeshstate_t mstate;
878         const entity_render_t *ent = calldata1;
879         int shadernum = calldata2;
880         int numverts, numtriangles;
881
882         R_Mesh_Matrix(&ent->matrix);
883
884         // find the vertex index list and texture
885         m = ent->model->zymdata_header;
886         renderlist = (int *)(m->lump_render.start + (int) m);
887         for (i = 0;i < shadernum;i++)
888                 renderlist += renderlist[0] * 3 + 1;
889         texture = ((rtexture_t **)(m->lump_shaders.start + (int) m))[shadernum];
890
891         numverts = m->numverts;
892         numtriangles = *renderlist++;
893         elements = renderlist;
894         R_Mesh_ResizeCheck(numverts);
895
896         fog = 0;
897         if (fogenabled)
898         {
899                 VectorSubtract(ent->origin, r_origin, diff);
900                 fog = DotProduct(diff,diff);
901                 if (fog < 0.01f)
902                         fog = 0.01f;
903                 fog = exp(fogdensity/fog);
904                 if (fog > 1)
905                         fog = 1;
906                 if (fog < 0.01f)
907                         fog = 0;
908                 // fog method: darken, additive fog
909                 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
910                 // 2. render fog as additive
911         }
912
913         ZymoticLerpBones(m->numbones, (zymbonematrix *)(m->lump_poses.start + (int) m), ent->frameblend, (zymbone_t *)(m->lump_bones.start + (int) m));
914         ZymoticTransformVerts(numverts, (int *)(m->lump_vertbonecounts.start + (int) m), (zymvertex_t *)(m->lump_verts.start + (int) m));
915         ZymoticCalcNormals(numverts, m->numshaders, (int *)(m->lump_render.start + (int) m));
916
917         R_LightModel(ent, numverts, 1 - fog, 1 - fog, 1 - fog, false);
918
919         memset(&mstate, 0, sizeof(mstate));
920         if (ent->effects & EF_ADDITIVE)
921         {
922                 mstate.blendfunc1 = GL_SRC_ALPHA;
923                 mstate.blendfunc2 = GL_ONE;
924         }
925         else if (ent->alpha != 1.0 || R_TextureHasAlpha(texture))
926         {
927                 mstate.blendfunc1 = GL_SRC_ALPHA;
928                 mstate.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
929         }
930         else
931         {
932                 mstate.blendfunc1 = GL_ONE;
933                 mstate.blendfunc2 = GL_ZERO;
934         }
935         colorscale = r_colorscale;
936         if (gl_combine.integer)
937         {
938                 mstate.texrgbscale[0] = 4;
939                 colorscale *= 0.25f;
940         }
941         mstate.tex[0] = R_GetTexture(texture);
942         R_Mesh_State(&mstate);
943
944         c_alias_polys += numtriangles;
945         memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
946         R_ModulateColors(aliasvertcolor, varray_color, numverts, colorscale, colorscale, colorscale);
947         memcpy(varray_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
948         GL_UseColorArray();
949         R_Mesh_Draw(numverts, numtriangles, elements);
950
951         if (fog)
952         {
953                 memset(&mstate, 0, sizeof(mstate));
954                 mstate.blendfunc1 = GL_SRC_ALPHA;
955                 mstate.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
956                 // FIXME: need alpha mask for fogging...
957                 //mstate.tex[0] = R_GetTexture(texture);
958                 R_Mesh_State(&mstate);
959
960                 c_alias_polys += numtriangles;
961                 memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
962                 //memcpy(mesh_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
963                 GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog);
964                 R_Mesh_Draw(numverts, numtriangles, elements);
965         }
966 }
967
968 void R_DrawZymoticModel (entity_render_t *ent)
969 {
970         int i;
971         zymtype1header_t *m;
972         rtexture_t *texture;
973
974         if (ent->alpha < (1.0f / 64.0f))
975                 return; // basically completely transparent
976
977         c_models++;
978
979         m = ent->model->zymdata_header;
980         for (i = 0;i < m->numshaders;i++)
981         {
982                 texture = ((rtexture_t **)(m->lump_shaders.start + (int) m))[i];
983                 if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_TextureHasAlpha(texture))
984                         R_MeshQueue_AddTransparent(ent->origin, R_DrawZymoticModelMeshCallback, ent, i);
985                 else
986                         R_DrawZymoticModelMeshCallback(ent, i);
987         }
988 }
989
990 void R_DrawQ1Q2AliasModel(entity_render_t *ent)
991 {
992         if (ent->alpha < (1.0f / 64.0f))
993                 return; // basically completely transparent
994
995         c_models++;
996
997         if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchSkinFrame(ent)->fog != NULL)
998                 R_MeshQueue_AddTransparent(ent->origin, R_DrawQ1Q2AliasModelCallback, ent, 0);
999         else
1000                 R_DrawQ1Q2AliasModelCallback(ent, 0);
1001 }