5 void GL_Models_Init(void)
9 aliaslayer_t r_aliasnoskinlayers[2] = {{ALIASLAYER_DIFFUSE, NULL, NULL}, {ALIASLAYER_FOG | ALIASLAYER_FORCEDRAW_IF_FIRSTPASS, NULL, NULL}};
10 aliasskin_t r_aliasnoskin = {0, 2, r_aliasnoskinlayers};
11 aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mesh)
13 model_t *model = ent->model;
17 if ((unsigned int)s >= (unsigned int)model->numskins)
19 if (model->skinscenes[s].framecount > 1)
20 s = model->skinscenes[s].firstframe + (int) (cl.time * model->skinscenes[s].framerate) % model->skinscenes[s].framecount;
22 s = model->skinscenes[s].firstframe;
23 if (s >= mesh->num_skins)
25 return mesh->data_skins + s;
29 r_aliasnoskinlayers[0].texture = r_notexture;
30 return &r_aliasnoskin;
34 void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
36 int c, fullbright, layernum, firstpass;
37 float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
38 float *vertex3f, *normal3f;
42 const entity_render_t *ent = calldata1;
43 aliasmesh_t *mesh = ent->model->alias.aliasdata_meshes + calldata2;
47 R_Mesh_Matrix(&ent->matrix);
52 VectorSubtract(ent->origin, r_vieworigin, diff);
53 fog = DotProduct(diff,diff);
56 fog = exp(fogdensity/fog);
61 // fog method: darken, additive fog
62 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
63 // 2. render fog as additive
68 skin = R_FetchAliasSkin(ent, mesh);
70 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
72 vertex3f = mesh->data_basevertex3f;
73 normal3f = mesh->data_basenormal3f;
77 vertex3f = varray_vertex3f;
78 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
81 for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
83 if (!(layer->flags & ALIASLAYER_FORCEDRAW_IF_FIRSTPASS) || !firstpass)
85 if (((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
86 || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0)
87 || ((layer->flags & ALIASLAYER_FOG) && !fogenabled)
88 || (layer->flags & ALIASLAYER_SPECULAR)
89 || ((layer->flags & ALIASLAYER_DIFFUSE) && (ent->flags & RENDER_LIGHT) && r_lightmapintensity <= 0 && !(ent->flags & RENDER_TRANSPARENT) && r_ambient.integer <= 0))
92 if (!firstpass || (ent->effects & EF_ADDITIVE))
94 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
97 else if ((skin->flags & ALIASSKIN_TRANSPARENT) || ent->alpha != 1.0)
99 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
104 GL_BlendFunc(GL_ONE, GL_ZERO);
111 memset(&m, 0, sizeof(m));
112 if (layer->texture != NULL)
114 m.tex[0] = R_GetTexture(layer->texture);
115 m.pointer_texcoord[0] = mesh->data_texcoord2f;
116 if (gl_combine.integer && layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
119 m.texrgbscale[0] = 4;
122 m.pointer_vertex = vertex3f;
124 c_alias_polys += mesh->num_triangles;
125 if (layer->flags & ALIASLAYER_FOG)
128 GL_Color(fogcolor[0] * colorscale, fogcolor[1] * colorscale, fogcolor[2] * colorscale, ent->alpha);
132 fullbright = !(layer->flags & ALIASLAYER_DIFFUSE) || !(ent->flags & RENDER_LIGHT);
133 if (layer->flags & (ALIASLAYER_COLORMAP_PANTS | ALIASLAYER_COLORMAP_SHIRT))
135 // 128-224 are backwards ranges
136 if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
137 c = (ent->colormap & 0xF) << 4;
138 else //if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
139 c = (ent->colormap & 0xF0);
140 c += (c >= 128 && c < 224) ? 4 : 12;
141 bcolor = (qbyte *) (&palette_complete[c]);
142 fullbright = fullbright || c >= 224;
143 VectorScale(bcolor, (1.0f / 255.0f), tint);
146 tint[0] = tint[1] = tint[2] = 1;
147 if (!fullbright && !(ent->flags & RENDER_TRANSPARENT))
148 colorscale *= r_lightmapintensity;
151 GL_Color(tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha);
152 else if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false))
154 m.pointer_color = varray_color4f;
155 if (normal3f == NULL)
157 normal3f = varray_normal3f;
158 Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
160 R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
163 GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
166 GL_LockArrays(0, mesh->num_vertices);
167 R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
172 void R_Model_Alias_Draw(entity_render_t *ent)
176 if (ent->alpha < (1.0f / 64.0f))
177 return; // basically completely transparent
181 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
183 if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_FetchAliasSkin(ent, mesh)->flags & ALIASSKIN_TRANSPARENT)
184 R_MeshQueue_AddTransparent(ent->origin, R_DrawAliasModelCallback, ent, meshnum);
186 R_DrawAliasModelCallback(ent, meshnum);
190 void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
195 float projectdistance, *vertex3f;
196 if (!(ent->flags & RENDER_SHADOW))
198 projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin));
199 if (projectdistance > 0.1)
201 R_Mesh_Matrix(&ent->matrix);
202 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
204 skin = R_FetchAliasSkin(ent, mesh);
205 if (skin->flags & ALIASSKIN_TRANSPARENT)
207 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
208 vertex3f = mesh->data_basevertex3f;
211 vertex3f = varray_vertex3f;
212 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
214 R_Shadow_VolumeFromSphere(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, lightradius);
219 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)
221 int c, meshnum, layernum;
222 float fog, ifog, lightcolor2[3];
223 float *vertex3f, *svector3f, *tvector3f, *normal3f;
230 R_Mesh_Matrix(&ent->matrix);
235 VectorSubtract(ent->origin, r_vieworigin, diff);
236 fog = DotProduct(diff,diff);
239 fog = exp(fogdensity/fog);
244 // fog method: darken, additive fog
245 // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
246 // 2. render fog as additive
250 for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++, mesh++)
252 skin = R_FetchAliasSkin(ent, mesh);
253 // FIXME: transparent skins need to be lit during the transparent render
254 if (skin->flags & ALIASSKIN_TRANSPARENT)
256 if (ent->frameblend[0].frame == 0 && ent->frameblend[0].lerp == 1)
258 vertex3f = mesh->data_basevertex3f;
259 svector3f = mesh->data_basesvector3f;
260 tvector3f = mesh->data_basetvector3f;
261 normal3f = mesh->data_basenormal3f;
265 vertex3f = varray_vertex3f;
266 svector3f = varray_svector3f;
267 tvector3f = varray_tvector3f;
268 normal3f = varray_normal3f;
269 Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
270 Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
272 for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
274 if (!(layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
275 || ((layer->flags & ALIASLAYER_NODRAW_IF_NOTCOLORMAPPED) && ent->colormap < 0)
276 || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0))
278 lightcolor2[0] = lightcolor[0] * ifog;
279 lightcolor2[1] = lightcolor[1] * ifog;
280 lightcolor2[2] = lightcolor[2] * ifog;
281 if (layer->flags & ALIASLAYER_SPECULAR)
283 c_alias_polys += mesh->num_triangles;
284 R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_SPECULAR);
286 else if (layer->flags & ALIASLAYER_DIFFUSE)
288 if (layer->flags & ALIASLAYER_COLORMAP_PANTS)
290 // 128-224 are backwards ranges
291 c = (ent->colormap & 0xF) << 4;c += (c >= 128 && c < 224) ? 4 : 12;
292 // fullbright passes were already taken care of, so skip them in realtime lighting passes
295 bcolor = (qbyte *) (&palette_complete[c]);
296 lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
297 lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
298 lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
300 else if (layer->flags & ALIASLAYER_COLORMAP_SHIRT)
302 // 128-224 are backwards ranges
303 c = (ent->colormap & 0xF0);c += (c >= 128 && c < 224) ? 4 : 12;
304 // fullbright passes were already taken care of, so skip them in realtime lighting passes
307 bcolor = (qbyte *) (&palette_complete[c]);
308 lightcolor2[0] *= bcolor[0] * (1.0f / 255.0f);
309 lightcolor2[1] *= bcolor[1] * (1.0f / 255.0f);
310 lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
312 c_alias_polys += mesh->num_triangles;
313 R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_DIFFUSE);