5 mempool_t *r_shadow_mempool;
9 int maxtrianglefacinglight;
10 qbyte *trianglefacinglight;
12 rtexturepool_t *r_shadow_texturepool;
13 rtexture_t *r_shadow_normalsattenuationtexture;
14 rtexture_t *r_shadow_normalscubetexture;
15 rtexture_t *r_shadow_attenuation2dtexture;
16 rtexture_t *r_shadow_blankbumptexture;
18 cvar_t r_shadow1 = {0, "r_shadow1", "16"};
19 cvar_t r_shadow2 = {0, "r_shadow2", "2"};
20 cvar_t r_shadow3 = {0, "r_shadow3", "65536"};
21 cvar_t r_shadow4 = {0, "r_shadow4", "1"};
22 cvar_t r_shadow5 = {0, "r_shadow5", "0"};
23 cvar_t r_shadow6 = {0, "r_shadow6", "1"};
24 cvar_t r_light_realtime = {0, "r_light_realtime", "0"};
25 cvar_t r_light_quality = {0, "r_light_quality", "1"};
26 cvar_t r_light_gloss = {0, "r_light_gloss", "0"};
27 cvar_t r_light_debuglight = {0, "r_light_debuglight", "-1"};
29 void r_shadow_start(void)
31 // allocate vertex processing arrays
32 r_shadow_mempool = Mem_AllocPool("R_Shadow");
33 maxshadowelements = 0;
34 shadowelements = NULL;
35 maxtrianglefacinglight = 0;
36 trianglefacinglight = NULL;
37 r_shadow_normalsattenuationtexture = NULL;
38 r_shadow_normalscubetexture = NULL;
39 r_shadow_attenuation2dtexture = NULL;
40 r_shadow_blankbumptexture = NULL;
41 r_shadow_texturepool = NULL;
44 void r_shadow_shutdown(void)
46 r_shadow_normalsattenuationtexture = NULL;
47 r_shadow_normalscubetexture = NULL;
48 r_shadow_attenuation2dtexture = NULL;
49 r_shadow_blankbumptexture = NULL;
50 R_FreeTexturePool(&r_shadow_texturepool);
51 maxshadowelements = 0;
52 shadowelements = NULL;
53 maxtrianglefacinglight = 0;
54 trianglefacinglight = NULL;
55 Mem_FreePool(&r_shadow_mempool);
58 void r_shadow_newmap(void)
62 void R_Shadow_Init(void)
64 Cvar_RegisterVariable(&r_shadow1);
65 Cvar_RegisterVariable(&r_shadow2);
66 Cvar_RegisterVariable(&r_shadow3);
67 Cvar_RegisterVariable(&r_shadow4);
68 Cvar_RegisterVariable(&r_shadow5);
69 Cvar_RegisterVariable(&r_shadow6);
70 Cvar_RegisterVariable(&r_light_realtime);
71 Cvar_RegisterVariable(&r_light_quality);
72 Cvar_RegisterVariable(&r_light_gloss);
73 Cvar_RegisterVariable(&r_light_debuglight);
74 R_RegisterModule("R_Shadow", r_shadow_start, r_shadow_shutdown, r_shadow_newmap);
77 void R_Shadow_Volume(int numverts, int numtris, float *vertex, int *elements, int *neighbors, vec3_t relativelightorigin, float lightradius, float projectdistance, int visiblevolume)
79 int i, *e, *n, *out, tris;
80 float *v0, *v1, *v2, temp[3], f;
81 if (projectdistance < 0.1)
83 Con_Printf("R_Shadow_Volume: projectdistance %f\n");
89 // a triangle facing the light source
92 // a triangle not facing the light source
95 // an extrusion of the backfaces, beginning at the original geometry and
96 // ending further from the light source than the original geometry
97 // (presumably at least as far as the light's radius, if the light has a
98 // radius at all), capped at both front and back to avoid any problems
101 // draws the shadow volumes of the model.
103 // vertex loations must already be in vertex before use.
104 // vertex must have capacity for numverts * 2.
106 // make sure trianglefacinglight is big enough for this volume
107 if (maxtrianglefacinglight < numtris)
109 maxtrianglefacinglight = numtris;
110 if (trianglefacinglight)
111 Mem_Free(trianglefacinglight);
112 trianglefacinglight = Mem_Alloc(r_shadow_mempool, maxtrianglefacinglight);
115 // make sure shadowelements is big enough for this volume
116 if (maxshadowelements < numtris * 24)
118 maxshadowelements = numtris * 24;
120 Mem_Free(shadowelements);
121 shadowelements = Mem_Alloc(r_shadow_mempool, maxshadowelements * sizeof(int));
124 // make projected vertices
125 // by clever use of elements we'll construct the whole shadow from
126 // the unprojected vertices and these projected vertices
127 for (i = 0, v0 = vertex, v1 = vertex + numverts * 4;i < numverts;i++, v0 += 4, v1 += 4)
130 v1[0] = v0[0] + 50.0f * (v0[0] - relativelightorigin[0]);
131 v1[1] = v0[1] + 50.0f * (v0[1] - relativelightorigin[1]);
132 v1[2] = v0[2] + 50.0f * (v0[2] - relativelightorigin[2]);
134 VectorSubtract(v0, relativelightorigin, temp);
135 f = lightradius / sqrt(DotProduct(temp,temp));
138 VectorMA(relativelightorigin, f, temp, v1);
140 VectorSubtract(v0, relativelightorigin, temp);
141 f = projectdistance / sqrt(DotProduct(temp,temp));
142 VectorMA(v0, f, temp, v1);
146 // check which triangles are facing the light
147 for (i = 0, e = elements;i < numtris;i++, e += 3)
149 // calculate triangle facing flag
150 v0 = vertex + e[0] * 4;
151 v1 = vertex + e[1] * 4;
152 v2 = vertex + e[2] * 4;
153 // we do not need to normalize the surface normal because both sides
154 // of the comparison use it, therefore they are both multiplied the
155 // same amount... furthermore the subtract can be done on the
156 // vectors, saving a little bit of math in the dotproducts
159 // subtracts v1 from v0 and v2, combined into a crossproduct,
160 // combined with a dotproduct of the light location relative to the
161 // first point of the triangle (any point works, since the triangle
162 // is obviously flat), and finally a comparison to determine if the
163 // light is infront of the triangle (the goal of this statement)
164 trianglefacinglight[i] =
165 (relativelightorigin[0] - v0[0]) * ((v0[1] - v1[1]) * (v2[2] - v1[2]) - (v0[2] - v1[2]) * (v2[1] - v1[1]))
166 + (relativelightorigin[1] - v0[1]) * ((v0[2] - v1[2]) * (v2[0] - v1[0]) - (v0[0] - v1[0]) * (v2[2] - v1[2]))
167 + (relativelightorigin[2] - v0[2]) * ((v0[0] - v1[0]) * (v2[1] - v1[1]) - (v0[1] - v1[1]) * (v2[0] - v1[0])) > 0;
171 float dir0[3], dir1[3];
173 // calculate two mostly perpendicular edge directions
174 VectorSubtract(v0, v1, dir0);
175 VectorSubtract(v2, v1, dir1);
177 // we have two edge directions, we can calculate a third vector from
178 // them, which is the direction of the surface normal (it's magnitude
180 CrossProduct(dir0, dir1, temp);
182 // this is entirely unnecessary, but kept for clarity
183 //VectorNormalize(temp);
185 // compare distance of light along normal, with distance of any point
186 // of the triangle along the same normal (the triangle is planar,
187 // I.E. flat, so all points give the same answer)
188 // the normal is not normalized because it is used on both sides of
189 // the comparison, so it's magnitude does not matter
190 //trianglefacinglight[i] = DotProduct(relativelightorigin, temp) >= DotProduct(v0, temp);
191 f = DotProduct(relativelightorigin, temp) - DotProduct(v0, temp);
192 trianglefacinglight[i] = f > 0 && f < lightradius * sqrt(DotProduct(temp, temp));
197 // output triangle elements
198 out = shadowelements;
201 // check each backface for bordering frontfaces,
202 // and cast shadow polygons from those edges,
203 // also create front and back caps for shadow volume
204 for (i = 0, e = elements, n = neighbors;i < numtris;i++, e += 3, n += 3)
206 if (!trianglefacinglight[i])
208 // triangle is backface and therefore casts shadow,
209 // output front and back caps for shadow volume
211 // front cap (with flipped winding order)
216 out[3] = e[0] + numverts;
217 out[4] = e[1] + numverts;
218 out[5] = e[2] + numverts;
223 out[0] = e[0] + numverts;
224 out[1] = e[1] + numverts;
225 out[2] = e[2] + numverts;
230 if (n[0] < 0 || trianglefacinglight[n[0]])
234 out[2] = e[1] + numverts;
236 out[4] = e[1] + numverts;
237 out[5] = e[0] + numverts;
241 if (n[1] < 0 || trianglefacinglight[n[1]])
245 out[2] = e[2] + numverts;
247 out[4] = e[2] + numverts;
248 out[5] = e[1] + numverts;
252 if (n[2] < 0 || trianglefacinglight[n[2]])
256 out[2] = e[0] + numverts;
258 out[4] = e[0] + numverts;
259 out[5] = e[2] + numverts;
265 R_Shadow_RenderVolume(numverts * 2, tris, shadowelements, visiblevolume);
268 void R_Shadow_RenderVolume(int numverts, int numtris, int *elements, int visiblevolume)
273 //qglDisable(GL_CULL_FACE);
274 R_Mesh_Draw(numverts, numtris, elements);
275 //qglEnable(GL_CULL_FACE);
279 // increment stencil if backface is behind depthbuffer
280 qglCullFace(GL_BACK); // quake is backwards, this culls front faces
281 qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
282 R_Mesh_Draw(numverts, numtris, elements);
283 // decrement stencil if frontface is behind depthbuffer
284 qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
285 qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
286 R_Mesh_Draw(numverts, numtris, elements);
290 float r_shadow_atten1, r_shadow_atten2, r_shadow_atten5;
291 #define ATTEN3DSIZE 64
292 static void R_Shadow_Make3DTextures(void)
295 float v[3], intensity, ilen, length, bordercolor[4];
296 qbyte data[ATTEN3DSIZE][ATTEN3DSIZE][ATTEN3DSIZE][4];
297 if (r_light_quality.integer != 1 || !gl_texture3d)
299 for (z = 0;z < ATTEN3DSIZE;z++)
301 for (y = 0;y < ATTEN3DSIZE;y++)
303 for (x = 0;x < ATTEN3DSIZE;x++)
305 v[0] = (x + 0.5f) * (2.0f / (float) ATTEN3DSIZE) - 1.0f;
306 v[1] = (y + 0.5f) * (2.0f / (float) ATTEN3DSIZE) - 1.0f;
307 v[2] = (z + 0.5f) * (2.0f / (float) ATTEN3DSIZE) - 1.0f;
308 length = sqrt(DotProduct(v, v));
309 if (DotProduct(v, v) < 1)
310 intensity = (((r_shadow_atten1 / (length*length + r_shadow_atten5)) - (r_shadow_atten1 * r_shadow_atten2))) / 256.0f;
313 ilen = 127.0f * bound(0, intensity, 1) / length;
314 data[z][y][x][0] = 128.0f + ilen * v[0];
315 data[z][y][x][1] = 128.0f + ilen * v[1];
316 data[z][y][x][2] = 128.0f + ilen * v[2];
317 data[z][y][x][3] = 255;
321 r_shadow_normalsattenuationtexture = R_LoadTexture3D(r_shadow_texturepool, "normalsattenuation", ATTEN3DSIZE, ATTEN3DSIZE, ATTEN3DSIZE, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP | TEXF_ALWAYSPRECACHE, NULL);
322 bordercolor[0] = 0.5f;
323 bordercolor[1] = 0.5f;
324 bordercolor[2] = 0.5f;
325 bordercolor[3] = 1.0f;
326 qglTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, bordercolor);
329 static void R_Shadow_MakeTextures(void)
331 int x, y, z, d, side;
332 float v[3], s, t, intensity;
333 qbyte data[6][128][128][4];
334 R_FreeTexturePool(&r_shadow_texturepool);
335 r_shadow_texturepool = R_AllocTexturePool();
336 r_shadow_atten1 = r_shadow1.value;
337 r_shadow_atten2 = r_shadow2.value;
338 r_shadow_atten5 = r_shadow5.value;
339 for (y = 0;y < 128;y++)
341 for (x = 0;x < 128;x++)
343 data[0][y][x][0] = 128;
344 data[0][y][x][1] = 128;
345 data[0][y][x][2] = 255;
346 data[0][y][x][3] = 255;
349 r_shadow_blankbumptexture = R_LoadTexture2D(r_shadow_texturepool, "blankbump", 128, 128, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
350 for (side = 0;side < 6;side++)
352 for (y = 0;y < 128;y++)
354 for (x = 0;x < 128;x++)
356 s = (x + 0.5f) * (2.0f / 128.0f) - 1.0f;
357 t = (y + 0.5f) * (2.0f / 128.0f) - 1.0f;
391 intensity = 127.0f / sqrt(DotProduct(v, v));
392 data[side][y][x][0] = 128.0f + intensity * v[0];
393 data[side][y][x][1] = 128.0f + intensity * v[1];
394 data[side][y][x][2] = 128.0f + intensity * v[2];
395 data[side][y][x][3] = 255;
399 r_shadow_normalscubetexture = R_LoadTextureCubeMap(r_shadow_texturepool, "normalscube", 128, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
400 for (y = 0;y < 128;y++)
402 for (x = 0;x < 128;x++)
404 v[0] = (x + 0.5f) * (2.0f / 128.0f) - 1.0f;
405 v[1] = (y + 0.5f) * (2.0f / 128.0f) - 1.0f;
407 if (DotProduct(v, v) < 1)
408 intensity = (((r_shadow_atten1 / (DotProduct(v, v)+r_shadow_atten5)) - (r_shadow_atten1 * r_shadow_atten2))) / 256.0f;
411 d = bound(0, intensity, 255) / sqrt(DotProduct(v, v));
412 data[0][y][x][0] = d;
413 data[0][y][x][1] = d;
414 data[0][y][x][2] = d;
415 data[0][y][x][3] = 255;
418 r_shadow_attenuation2dtexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation2d", 128, 128, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_CLAMP, NULL);
419 R_Shadow_Make3DTextures();
422 void R_Shadow_Stage_Begin(void)
426 if (r_light_quality.integer == 1 && !gl_texture3d)
428 Con_Printf("3D texture support not detected, falling back on slower 2D + 1D + normalization lighting\n");
429 Cvar_SetValueQuick(&r_light_quality, 0);
431 //cl.worldmodel->numlights = min(cl.worldmodel->numlights, 1);
432 if (!r_shadow_attenuation2dtexture
433 || (r_light_quality.integer == 1 && !r_shadow_normalsattenuationtexture)
434 || r_shadow1.value != r_shadow_atten1
435 || r_shadow2.value != r_shadow_atten2
436 || r_shadow5.value != r_shadow_atten5)
437 R_Shadow_MakeTextures();
439 memset(&m, 0, sizeof(m));
440 m.blendfunc1 = GL_ONE;
441 m.blendfunc2 = GL_ZERO;
443 GL_Color(0, 0, 0, 1);
446 void R_Shadow_Stage_ShadowVolumes(void)
449 memset(&m, 0, sizeof(m));
450 R_Mesh_TextureState(&m);
451 GL_Color(1, 1, 1, 1);
452 qglColorMask(0, 0, 0, 0);
453 qglDisable(GL_BLEND);
455 qglDepthFunc(GL_LESS);
457 qglClear(GL_STENCIL_BUFFER_BIT);
458 qglEnable(GL_STENCIL_TEST);
459 qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
460 qglStencilFunc(GL_ALWAYS, 0, 0xFF);
463 void R_Shadow_Stage_Light(void)
466 memset(&m, 0, sizeof(m));
467 R_Mesh_TextureState(&m);
468 qglActiveTexture(GL_TEXTURE0_ARB);
471 qglBlendFunc(GL_ONE, GL_ONE);
472 GL_Color(1, 1, 1, 1);
473 qglColorMask(1, 1, 1, 1);
475 qglDepthFunc(GL_EQUAL);
476 qglEnable(GL_STENCIL_TEST);
477 qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
478 // only draw light where this geometry was already rendered AND the
479 // stencil is 0 (non-zero means shadow)
480 qglStencilFunc(GL_EQUAL, 0, 0xFF);
483 void R_Shadow_Stage_End(void)
486 // attempt to restore state to what Mesh_State thinks it is
487 qglDisable(GL_BLEND);
488 qglBlendFunc(GL_ONE, GL_ZERO);
490 // now restore the rest of the state to normal
491 GL_Color(1, 1, 1, 1);
492 qglColorMask(1, 1, 1, 1);
493 qglDepthFunc(GL_LEQUAL);
494 qglDisable(GL_STENCIL_TEST);
495 qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
496 qglStencilFunc(GL_ALWAYS, 0, 0xFF);
499 void R_Shadow_GenTexCoords_Attenuation2D(float *out, int numverts, const float *vertex, const float *svectors, const float *tvectors, const vec3_t relativelightorigin, float lightradius)
502 float lightvec[3], iradius;
503 iradius = 0.5f / lightradius;
504 for (i = 0;i < numverts;i++, vertex += 4, svectors += 4, tvectors += 4, out += 4)
506 VectorSubtract(vertex, relativelightorigin, lightvec);
507 out[0] = 0.5f + DotProduct(svectors, lightvec) * iradius;
508 out[1] = 0.5f + DotProduct(tvectors, lightvec) * iradius;
512 void R_Shadow_GenTexCoords_Attenuation1D(float *out, int numverts, const float *vertex, const float *normals, const vec3_t relativelightorigin, float lightradius)
515 float lightvec[3], iradius;
516 iradius = 0.5f / lightradius;
517 for (i = 0;i < numverts;i++, vertex += 4, normals += 4, out += 4)
519 VectorSubtract(vertex, relativelightorigin, lightvec);
520 out[0] = 0.5f + DotProduct(normals, lightvec) * iradius;
525 void R_Shadow_GenTexCoords_Diffuse_Attenuation3D(float *out, int numverts, const float *vertex, const float *svectors, const float *tvectors, const float *normals, const vec3_t relativelightorigin, float lightradius)
528 float lightvec[3], iradius;
529 iradius = 0.5f / lightradius;
530 for (i = 0;i < numverts;i++, vertex += 4, svectors += 4, tvectors += 4, normals += 4, out += 4)
532 VectorSubtract(vertex, relativelightorigin, lightvec);
533 if (r_shadow6.integer != 0)
535 VectorClear(lightvec);
536 if (r_shadow6.integer > 0)
537 lightvec[(r_shadow6.integer - 1) % 3] = 64;
539 lightvec[((-r_shadow6.integer) - 1) % 3] = -64;
541 if (r_shadow4.integer & 8)
542 lightvec[0] = -lightvec[0];
543 if (r_shadow4.integer & 16)
544 lightvec[1] = -lightvec[1];
545 if (r_shadow4.integer & 32)
546 lightvec[2] = -lightvec[2];
547 if (r_shadow4.integer & 1)
548 out[0] = 0.5f - DotProduct(svectors, lightvec) * iradius;
550 out[0] = 0.5f + DotProduct(svectors, lightvec) * iradius;
551 if (r_shadow4.integer & 2)
552 out[1] = 0.5f - DotProduct(tvectors, lightvec) * iradius;
554 out[2] = 0.5f + DotProduct(tvectors, lightvec) * iradius;
555 if (r_shadow4.integer & 4)
556 out[2] = 0.5f - DotProduct(normals, lightvec) * iradius;
558 out[2] = 0.5f + DotProduct(normals, lightvec) * iradius;
562 void R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(float *out, int numverts, const float *vertex, const float *svectors, const float *tvectors, const float *normals, const vec3_t relativelightorigin, float lightradius)
565 float lightdir[3], iradius;
566 iradius = 0.5f / lightradius;
567 for (i = 0;i < numverts;i++, vertex += 4, svectors += 4, tvectors += 4, normals += 4, out += 4)
569 VectorSubtract(vertex, relativelightorigin, lightdir);
570 // the cubemap normalizes this for us
571 out[0] = DotProduct(svectors, lightdir);
572 out[1] = DotProduct(tvectors, lightdir);
573 out[2] = DotProduct(normals, lightdir);
577 void R_Shadow_GenTexCoords_Specular_Attenuation3D(float *out, int numverts, const float *vertex, const float *svectors, const float *tvectors, const float *normals, const vec3_t relativelightorigin, const vec3_t relativeeyeorigin, float lightradius)
580 float lightdir[3], eyedir[3], halfdir[3], lightdirlen, ilen, iradius;
581 iradius = 0.5f / lightradius;
582 for (i = 0;i < numverts;i++, vertex += 4, svectors += 4, tvectors += 4, normals += 4, out += 4)
584 VectorSubtract(vertex, relativelightorigin, lightdir);
585 // this is used later to make the attenuation correct
586 lightdirlen = sqrt(DotProduct(lightdir, lightdir)) * iradius;
587 VectorNormalizeFast(lightdir);
588 VectorSubtract(vertex, relativeeyeorigin, eyedir);
589 VectorNormalizeFast(eyedir);
590 VectorAdd(lightdir, eyedir, halfdir);
591 VectorNormalizeFast(halfdir);
592 out[0] = 0.5f + DotProduct(svectors, halfdir) * lightdirlen;
593 out[1] = 0.5f + DotProduct(tvectors, halfdir) * lightdirlen;
594 out[2] = 0.5f + DotProduct(normals, halfdir) * lightdirlen;
598 void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out, int numverts, const float *vertex, const float *svectors, const float *tvectors, const float *normals, const vec3_t relativelightorigin, const vec3_t relativeeyeorigin, float lightradius)
601 float lightdir[3], eyedir[3], halfdir[3], lightdirlen, ilen, iradius;
602 iradius = 0.5f / lightradius;
603 for (i = 0;i < numverts;i++, vertex += 4, svectors += 4, tvectors += 4, normals += 4, out += 4)
605 VectorSubtract(vertex, relativelightorigin, lightdir);
606 VectorNormalizeFast(lightdir);
607 VectorSubtract(vertex, relativeeyeorigin, eyedir);
608 VectorNormalizeFast(eyedir);
609 VectorAdd(lightdir, eyedir, halfdir);
610 // the cubemap normalizes this for us
611 out[0] = DotProduct(svectors, halfdir);
612 out[1] = DotProduct(tvectors, halfdir);
613 out[2] = DotProduct(normals, halfdir);
617 void R_Shadow_GenTexCoords_LightCubeMap(float *out, int numverts, const float *vertex, const vec3_t relativelightorigin)
620 for (i = 0;i < numverts;i++, vertex += 4, out += 4)
621 VectorSubtract(vertex, relativelightorigin, out);
624 void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements, const float *svectors, const float *tvectors, const float *normals, const float *texcoords, const float *relativelightorigin, const float *relativeeyeorigin, float lightradius, const float *lightcolor, rtexture_t *basetexture, rtexture_t *glosstexture, rtexture_t *bumptexture, rtexture_t *lightcubemap)
628 memset(&m, 0, sizeof(m));
630 bumptexture = r_shadow_blankbumptexture;
631 f = 1.0f / r_shadow3.value;
632 if (r_light_quality.integer == 1)
634 // 4 texture 3D path, two pass
636 //lightcolor[0] * f, lightcolor[1] * f, lightcolor[2] * f, 1);
637 memcpy(varray_texcoord[0], texcoords, numverts * sizeof(float[4]));
638 memcpy(varray_texcoord[2], texcoords, numverts * sizeof(float[4]));
639 if (r_light_gloss.integer != 2)
641 m.tex[0] = R_GetTexture(bumptexture);
642 m.tex3d[1] = R_GetTexture(r_shadow_normalsattenuationtexture);
643 m.tex[2] = R_GetTexture(basetexture);
644 m.texcubemap[3] = R_GetTexture(lightcubemap);
645 m.texcombinergb[0] = GL_REPLACE;
646 m.texcombinergb[1] = GL_DOT3_RGB_ARB;
647 m.texcombinergb[2] = GL_MODULATE;
648 m.texcombinergb[3] = GL_MODULATE;
649 m.texrgbscale[2] = 2;
650 R_Mesh_TextureState(&m);
651 R_Shadow_GenTexCoords_Diffuse_Attenuation3D(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin, lightradius);
653 R_Shadow_GenTexCoords_LightCubeMap(varray_texcoord[3], numverts, varray_vertex, relativelightorigin);
654 R_Mesh_Draw(numverts, numtriangles, elements);
656 if (r_light_gloss.integer && glosstexture)
658 m.tex[0] = R_GetTexture(bumptexture);
659 m.tex3d[1] = R_GetTexture(r_shadow_normalsattenuationtexture);
660 m.tex[2] = R_GetTexture(glosstexture);
661 m.texcubemap[3] = R_GetTexture(lightcubemap);
662 m.texcombinergb[0] = GL_REPLACE;
663 m.texcombinergb[1] = GL_DOT3_RGB_ARB;
664 m.texcombinergb[2] = GL_MODULATE;
665 m.texcombinergb[3] = GL_MODULATE;
666 m.texrgbscale[2] = 2;
667 R_Mesh_TextureState(&m);
668 R_Shadow_GenTexCoords_Specular_Attenuation3D(varray_texcoord[1], numverts, varray_vertex, svectors, tvectors, normals, relativelightorigin, relativeeyeorigin, lightradius);
669 R_Mesh_Draw(numverts, numtriangles, elements);
674 //R_Mesh_TextureState(&m);