2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // r_surf.c: surface-related refresh code
25 #define MAX_LIGHTMAP_SIZE 256
27 static unsigned int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
28 static float floatblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
30 static qbyte templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
32 cvar_t r_ambient = {0, "r_ambient", "0"};
33 cvar_t r_drawportals = {0, "r_drawportals", "0"};
34 cvar_t r_testvis = {0, "r_testvis", "0"};
35 cvar_t r_floatbuildlightmap = {0, "r_floatbuildlightmap", "0"};
36 cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
37 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "1"};
38 cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "-4"};
40 static int dlightdivtable[32768];
42 static int R_IntAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surf)
44 int sdtable[256], lnum, td, maxdist, maxdist2, maxdist3, i, s, t, smax, tmax, smax3, red, green, blue, lit, dist2, impacts, impactt, subtract, k;
46 float dist, impact[3], local[3];
50 smax = (surf->extents[0] >> 4) + 1;
51 tmax = (surf->extents[1] >> 4) + 1;
54 for (lnum = 0; lnum < r_numdlights; lnum++)
56 if (!(surf->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
57 continue; // not lit by this light
59 Matrix4x4_Transform(matrix, r_dlight[lnum].origin, local);
60 dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
62 // for comparisons to minimum acceptable light
63 // compensate for LIGHTOFFSET
64 maxdist = (int) r_dlight[lnum].cullradius2 + LIGHTOFFSET;
71 if (surf->plane->type < 3)
73 VectorCopy(local, impact);
74 impact[surf->plane->type] -= dist;
78 impact[0] = local[0] - surf->plane->normal[0] * dist;
79 impact[1] = local[1] - surf->plane->normal[1] * dist;
80 impact[2] = local[2] - surf->plane->normal[2] * dist;
83 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
84 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
86 s = bound(0, impacts, smax * 16) - impacts;
87 t = bound(0, impactt, tmax * 16) - impactt;
88 i = s * s + t * t + dist2;
92 // reduce calculations
93 for (s = 0, i = impacts; s < smax; s++, i -= 16)
94 sdtable[s] = i * i + dist2;
96 maxdist3 = maxdist - dist2;
98 // convert to 8.8 blocklights format
99 red = r_dlight[lnum].light[0] * (1.0f / 128.0f);
100 green = r_dlight[lnum].light[1] * (1.0f / 128.0f);
101 blue = r_dlight[lnum].light[2] * (1.0f / 128.0f);
102 subtract = (int) (r_dlight[lnum].subtract * 4194304.0f);
106 for (t = 0;t < tmax;t++, i -= 16)
109 // make sure some part of it is visible on this line
112 maxdist2 = maxdist - td;
113 for (s = 0;s < smax;s++)
115 if (sdtable[s] < maxdist2)
117 k = dlightdivtable[(sdtable[s] + td) >> 7] - subtract;
121 bl[1] += (green * k);
136 static int R_FloatAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surf)
138 int lnum, s, t, smax, tmax, smax3, lit, impacts, impactt;
139 float sdtable[256], *bl, k, dist, dist2, maxdist, maxdist2, maxdist3, td1, td, red, green, blue, impact[3], local[3], subtract;
143 smax = (surf->extents[0] >> 4) + 1;
144 tmax = (surf->extents[1] >> 4) + 1;
147 for (lnum = 0; lnum < r_numdlights; lnum++)
149 if (!(surf->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
150 continue; // not lit by this light
152 Matrix4x4_Transform(matrix, r_dlight[lnum].origin, local);
153 dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
155 // for comparisons to minimum acceptable light
156 // compensate for LIGHTOFFSET
157 maxdist = (int) r_dlight[lnum].cullradius2 + LIGHTOFFSET;
160 dist2 += LIGHTOFFSET;
161 if (dist2 >= maxdist)
164 if (surf->plane->type < 3)
166 VectorCopy(local, impact);
167 impact[surf->plane->type] -= dist;
171 impact[0] = local[0] - surf->plane->normal[0] * dist;
172 impact[1] = local[1] - surf->plane->normal[1] * dist;
173 impact[2] = local[2] - surf->plane->normal[2] * dist;
176 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
177 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
179 td = bound(0, impacts, smax * 16) - impacts;
180 td1 = bound(0, impactt, tmax * 16) - impactt;
181 td = td * td + td1 * td1 + dist2;
185 // reduce calculations
186 for (s = 0, td1 = impacts; s < smax; s++, td1 -= 16.0f)
187 sdtable[s] = td1 * td1 + dist2;
189 maxdist3 = maxdist - dist2;
191 // convert to 8.8 blocklights format
192 red = r_dlight[lnum].light[0];
193 green = r_dlight[lnum].light[1];
194 blue = r_dlight[lnum].light[2];
195 subtract = r_dlight[lnum].subtract * 32768.0f;
196 bl = floatblocklights;
199 for (t = 0;t < tmax;t++, td1 -= 16.0f)
202 // make sure some part of it is visible on this line
205 maxdist2 = maxdist - td;
206 for (s = 0;s < smax;s++)
208 if (sdtable[s] < maxdist2)
210 k = (32768.0f / (sdtable[s] + td)) - subtract;
230 Combine and scale multiple lightmaps into the 8.8 format in blocklights
233 static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
235 if (!r_floatbuildlightmap.integer)
237 int smax, tmax, i, j, size, size3, shift, maps, stride, l;
238 unsigned int *bl, scale;
239 qbyte *lightmap, *out, *stain;
241 // update cached lighting info
242 surf->cached_dlight = 0;
244 smax = (surf->extents[0]>>4)+1;
245 tmax = (surf->extents[1]>>4)+1;
248 lightmap = surf->samples;
250 // set to full bright if no light data
252 if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
254 for (i = 0;i < size3;i++)
260 j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style
263 for (i = 0;i < size3;i++)
267 memset(bl, 0, size*3*sizeof(unsigned int));
269 if (surf->dlightframe == r_framecount)
271 surf->cached_dlight = R_IntAddDynamicLights(&ent->inversematrix, surf);
272 if (surf->cached_dlight)
276 // add all the lightmaps
280 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
281 for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
282 bl[i] += lightmap[i] * scale;
286 stain = surf->stainsamples;
289 // deal with lightmap brightness scale
290 shift = 7 + r_lightmapscalebit + 8;
291 if (ent->model->brushq1.lightmaprgba)
293 stride = (surf->lightmaptexturestride - smax) * 4;
294 for (i = 0;i < tmax;i++, out += stride)
296 for (j = 0;j < smax;j++)
298 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
299 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
300 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
307 stride = (surf->lightmaptexturestride - smax) * 3;
308 for (i = 0;i < tmax;i++, out += stride)
310 for (j = 0;j < smax;j++)
312 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
313 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
314 l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
319 R_UpdateTexture(surf->lightmaptexture, templight);
323 int smax, tmax, i, j, size, size3, maps, stride, l;
325 qbyte *lightmap, *out, *stain;
327 // update cached lighting info
328 surf->cached_dlight = 0;
330 smax = (surf->extents[0]>>4)+1;
331 tmax = (surf->extents[1]>>4)+1;
334 lightmap = surf->samples;
336 // set to full bright if no light data
337 bl = floatblocklights;
338 if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
341 j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style
346 for (i = 0;i < size3;i++)
350 memset(bl, 0, size*3*sizeof(float));
352 if (surf->dlightframe == r_framecount)
354 surf->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surf);
355 if (surf->cached_dlight)
359 // add all the lightmaps
362 bl = floatblocklights;
363 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
364 for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
365 bl[i] += lightmap[i] * scale;
368 stain = surf->stainsamples;
369 bl = floatblocklights;
371 // deal with lightmap brightness scale
372 scale = 1.0f / (1 << (7 + r_lightmapscalebit + 8));
373 if (ent->model->brushq1.lightmaprgba)
375 stride = (surf->lightmaptexturestride - smax) * 4;
376 for (i = 0;i < tmax;i++, out += stride)
378 for (j = 0;j < smax;j++)
380 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
381 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
382 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
389 stride = (surf->lightmaptexturestride - smax) * 3;
390 for (i = 0;i < tmax;i++, out += stride)
392 for (j = 0;j < smax;j++)
394 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
395 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
396 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
401 R_UpdateTexture(surf->lightmaptexture, templight);
405 void R_StainNode (mnode_t *node, model_t *model, const vec3_t origin, float radius, const float fcolor[8])
407 float ndist, a, ratio, maxdist, maxdist2, maxdist3, invradius, sdtable[256], td, dist2;
408 msurface_t *surf, *endsurf;
409 int i, s, t, smax, tmax, smax3, impacts, impactt, stained;
413 maxdist = radius * radius;
414 invradius = 1.0f / radius;
417 if (node->contents < 0)
419 ndist = PlaneDiff(origin, node->plane);
422 node = node->children[0];
427 node = node->children[1];
431 dist2 = ndist * ndist;
432 maxdist3 = maxdist - dist2;
434 if (node->plane->type < 3)
436 VectorCopy(origin, impact);
437 impact[node->plane->type] -= ndist;
441 impact[0] = origin[0] - node->plane->normal[0] * ndist;
442 impact[1] = origin[1] - node->plane->normal[1] * ndist;
443 impact[2] = origin[2] - node->plane->normal[2] * ndist;
446 for (surf = model->brushq1.surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
448 if (surf->stainsamples)
450 smax = (surf->extents[0] >> 4) + 1;
451 tmax = (surf->extents[1] >> 4) + 1;
453 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
454 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
456 s = bound(0, impacts, smax * 16) - impacts;
457 t = bound(0, impactt, tmax * 16) - impactt;
458 i = s * s + t * t + dist2;
462 // reduce calculations
463 for (s = 0, i = impacts; s < smax; s++, i -= 16)
464 sdtable[s] = i * i + dist2;
466 bl = surf->stainsamples;
471 for (t = 0;t < tmax;t++, i -= 16)
474 // make sure some part of it is visible on this line
477 maxdist2 = maxdist - td;
478 for (s = 0;s < smax;s++)
480 if (sdtable[s] < maxdist2)
482 ratio = lhrandom(0.0f, 1.0f);
483 a = (fcolor[3] + ratio * fcolor[7]) * (1.0f - sqrt(sdtable[s] + td) * invradius);
484 if (a >= (1.0f / 64.0f))
488 bl[0] = (qbyte) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
489 bl[1] = (qbyte) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
490 bl[2] = (qbyte) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
500 // force lightmap upload
502 surf->cached_dlight = true;
506 if (node->children[0]->contents >= 0)
508 if (node->children[1]->contents >= 0)
510 R_StainNode(node->children[0], model, origin, radius, fcolor);
511 node = node->children[1];
516 node = node->children[0];
520 else if (node->children[1]->contents >= 0)
522 node = node->children[1];
527 void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2)
531 entity_render_t *ent;
534 if (cl.worldmodel == NULL || !cl.worldmodel->brushq1.nodes)
539 fcolor[3] = ca1 * (1.0f / 64.0f);
540 fcolor[4] = cr2 - cr1;
541 fcolor[5] = cg2 - cg1;
542 fcolor[6] = cb2 - cb1;
543 fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
545 R_StainNode(cl.worldmodel->brushq1.nodes + cl.worldmodel->brushq1.hulls[0].firstclipnode, cl.worldmodel, origin, radius, fcolor);
547 // look for embedded bmodels
548 for (n = 0;n < cl_num_brushmodel_entities;n++)
550 ent = cl_brushmodel_entities[n];
552 if (model && model->name[0] == '*')
554 Mod_CheckLoaded(model);
555 if (model->brushq1.nodes)
557 Matrix4x4_Transform(&ent->inversematrix, origin, org);
558 R_StainNode(model->brushq1.nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
566 =============================================================
570 =============================================================
573 static void RSurf_AddLightmapToVertexColors_Color4f(const int *lightmapoffsets, float *c, int numverts, const qbyte *samples, int size3, const qbyte *styles)
578 if (styles[0] != 255)
580 for (i = 0;i < numverts;i++, c += 4)
582 lm = samples + lightmapoffsets[i];
583 scale = d_lightstylevalue[styles[0]] * (1.0f / 32768.0f);
584 VectorMA(c, scale, lm, c);
585 if (styles[1] != 255)
588 scale = d_lightstylevalue[styles[1]] * (1.0f / 32768.0f);
589 VectorMA(c, scale, lm, c);
590 if (styles[2] != 255)
593 scale = d_lightstylevalue[styles[2]] * (1.0f / 32768.0f);
594 VectorMA(c, scale, lm, c);
595 if (styles[3] != 255)
598 scale = d_lightstylevalue[styles[3]] * (1.0f / 32768.0f);
599 VectorMA(c, scale, lm, c);
607 static void RSurf_FogColors_Vertex3f_Color4f(const float *v, float *c, float colorscale, int numverts, const float *modelorg)
613 for (i = 0;i < numverts;i++, v += 3, c += 4)
615 VectorSubtract(v, modelorg, diff);
616 f = colorscale * (1 - exp(fogdensity/DotProduct(diff, diff)));
617 VectorScale(c, f, c);
620 else if (colorscale != 1)
621 for (i = 0;i < numverts;i++, c += 4)
622 VectorScale(c, colorscale, c);
625 static void RSurf_FoggedColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
634 for (i = 0;i < numverts;i++, v += 3, c += 4)
636 VectorSubtract(v, modelorg, diff);
637 f = 1 - exp(fogdensity/DotProduct(diff, diff));
646 for (i = 0;i < numverts;i++, c += 4)
656 static void RSurf_FogPassColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
663 for (i = 0;i < numverts;i++, v += 3, c += 4)
665 VectorSubtract(v, modelorg, diff);
666 f = exp(fogdensity/DotProduct(diff, diff));
674 static int RSurf_LightSeparate_Vertex3f_Color4f(const matrix4x4_t *matrix, const int *dlightbits, int numverts, const float *vert, float *color, float scale)
679 int i, l, lit = false;
682 for (l = 0;l < r_numdlights;l++)
684 if (dlightbits[l >> 5] & (1 << (l & 31)))
687 Matrix4x4_Transform(matrix, rd->origin, lightorigin);
688 for (i = 0, v = vert, c = color;i < numverts;i++, v += 3, c += 4)
690 f = VectorDistance2(v, lightorigin) + LIGHTOFFSET;
691 if (f < rd->cullradius2)
693 f = ((1.0f / f) - rd->subtract) * scale;
694 VectorMA(c, f, rd->light, c);
703 static void RSurfShader_Sky(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
705 const msurface_t *surf;
708 // LordHavoc: HalfLife maps have freaky skypolys...
709 if (ent->model->brush.ishlbsp)
714 skyrendernow = false;
719 R_Mesh_Matrix(&ent->matrix);
721 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
724 // depth-only (masking)
725 qglColorMask(0,0,0,0);
726 // just to make sure that braindead drivers don't draw anything
727 // despite that colormask...
728 GL_BlendFunc(GL_ZERO, GL_ONE);
733 GL_BlendFunc(GL_ONE, GL_ZERO);
738 memset(&m, 0, sizeof(m));
739 R_Mesh_State_Texture(&m);
741 while((surf = *surfchain++) != NULL)
743 if (surf->visframe == r_framecount)
745 GL_VertexPointer(surf->mesh.data_vertex3f);
746 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
749 qglColorMask(1,1,1,1);
752 static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
754 const entity_render_t *ent = calldata1;
755 const msurface_t *surf = ent->model->brushq1.surfaces + calldata2;
760 matrix4x4_t tempmatrix;
761 float args[4] = {0.05f,0,0,0.04f};
763 if (gl_textureshader && r_watershader.value && !fogenabled)
765 Matrix4x4_CreateTranslate(&tempmatrix, sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
766 R_Mesh_TextureMatrix(1, &tempmatrix);
767 Matrix4x4_CreateFromQuakeEntity(&tempmatrix, 0, 0, 0, 0, 0, 0, r_watershader.value);
768 R_Mesh_TextureMatrix(0, &tempmatrix);
770 else if (r_waterscroll.value)
772 // scrolling in texture matrix
773 Matrix4x4_CreateTranslate(&tempmatrix, sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
774 R_Mesh_TextureMatrix(0, &tempmatrix);
777 R_Mesh_Matrix(&ent->matrix);
778 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
780 memset(&m, 0, sizeof(m));
781 texture = surf->texinfo->texture->currentframe;
782 alpha = texture->currentalpha;
783 if (texture->rendertype == SURFRENDER_ADD)
785 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
788 else if (texture->rendertype == SURFRENDER_ALPHA)
790 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
795 GL_BlendFunc(GL_ONE, GL_ZERO);
798 if (gl_textureshader && r_watershader.value && !fogenabled)
800 m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(cl.time * 16)&63]);
801 m.tex[1] = R_GetTexture(texture->skin.base);
804 m.tex[0] = R_GetTexture(texture->skin.base);
807 GL_ColorPointer(varray_color4f);
809 GL_Color(1, 1, 1, alpha);
810 if (gl_textureshader && r_watershader.value && !fogenabled)
812 GL_ActiveTexture (0);
813 qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
814 GL_ActiveTexture (1);
815 qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
816 qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
817 qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
818 qglTexEnvfv (GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
819 qglEnable (GL_TEXTURE_SHADER_NV);
822 GL_VertexPointer(surf->mesh.data_vertex3f);
823 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
824 m.pointer_texcoord[1] = surf->mesh.data_texcoordtexture2f;
825 m.texcombinergb[1] = GL_REPLACE;
826 R_Mesh_State_Texture(&m);
829 R_FillColors(varray_color4f, surf->mesh.num_vertices, 1, 1, 1, alpha);
830 RSurf_FogColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, 1, surf->mesh.num_vertices, modelorg);
832 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
834 if (gl_textureshader && r_watershader.value && !fogenabled)
836 qglDisable (GL_TEXTURE_SHADER_NV);
837 GL_ActiveTexture (0);
842 memset(&m, 0, sizeof(m));
843 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
846 m.tex[0] = R_GetTexture(texture->skin.fog);
847 GL_VertexPointer(surf->mesh.data_vertex3f);
848 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
849 GL_ColorPointer(varray_color4f);
850 R_Mesh_State_Texture(&m);
851 RSurf_FogPassColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], alpha, 1, surf->mesh.num_vertices, modelorg);
852 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
855 if ((gl_textureshader && r_watershader.value && !fogenabled) || r_waterscroll.value)
857 Matrix4x4_CreateIdentity(&tempmatrix);
858 R_Mesh_TextureMatrix(0, &tempmatrix);
859 R_Mesh_TextureMatrix(1, &tempmatrix);
863 static void RSurfShader_Water(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
865 const msurface_t *surf;
868 if (texture->rendertype != SURFRENDER_OPAQUE)
870 for (chain = surfchain;(surf = *chain) != NULL;chain++)
872 if (surf->visframe == r_framecount)
874 Matrix4x4_Transform(&ent->matrix, surf->poly_center, center);
875 R_MeshQueue_AddTransparent(center, RSurfShader_Water_Callback, ent, surf - ent->model->brushq1.surfaces);
880 for (chain = surfchain;(surf = *chain) != NULL;chain++)
881 if (surf->visframe == r_framecount)
882 RSurfShader_Water_Callback(ent, surf - ent->model->brushq1.surfaces);
885 static void RSurfShader_Wall_Pass_BaseVertex(const entity_render_t *ent, const msurface_t *surf, const texture_t *texture, int rendertype, float currentalpha)
887 float base, colorscale;
890 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
891 memset(&m, 0, sizeof(m));
892 if (rendertype == SURFRENDER_ADD)
894 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
897 else if (rendertype == SURFRENDER_ALPHA)
899 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
904 GL_BlendFunc(GL_ONE, GL_ZERO);
907 m.tex[0] = R_GetTexture(texture->skin.base);
909 if (gl_combine.integer)
911 m.texrgbscale[0] = 4;
914 base = ent->effects & EF_FULLBRIGHT ? 2.0f : r_ambient.value * (1.0f / 64.0f);
916 GL_ColorPointer(varray_color4f);
918 GL_VertexPointer(surf->mesh.data_vertex3f);
919 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
920 R_Mesh_State_Texture(&m);
921 R_FillColors(varray_color4f, surf->mesh.num_vertices, base, base, base, currentalpha);
922 if (!(ent->effects & EF_FULLBRIGHT))
924 if (surf->dlightframe == r_framecount)
925 RSurf_LightSeparate_Vertex3f_Color4f(&ent->inversematrix, surf->dlightbits, surf->mesh.num_vertices, surf->mesh.data_vertex3f, varray_color4f, 1);
926 if (surf->flags & SURF_LIGHTMAP)
927 RSurf_AddLightmapToVertexColors_Color4f(surf->mesh.data_lightmapoffsets, varray_color4f,surf->mesh.num_vertices, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles);
929 RSurf_FogColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, colorscale, surf->mesh.num_vertices, modelorg);
930 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
933 static void RSurfShader_Wall_Pass_Glow(const entity_render_t *ent, const msurface_t *surf, const texture_t *texture, int rendertype, float currentalpha)
937 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
938 memset(&m, 0, sizeof(m));
939 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
942 m.tex[0] = R_GetTexture(texture->skin.glow);
943 GL_ColorPointer(varray_color4f);
945 GL_VertexPointer(surf->mesh.data_vertex3f);
947 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
948 R_Mesh_State_Texture(&m);
949 RSurf_FoggedColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, 1, 1, 1, currentalpha, 1, surf->mesh.num_vertices, modelorg);
950 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
953 static void RSurfShader_Wall_Pass_Fog(const entity_render_t *ent, const msurface_t *surf, const texture_t *texture, int rendertype, float currentalpha)
957 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
958 memset(&m, 0, sizeof(m));
959 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
962 m.tex[0] = R_GetTexture(texture->skin.fog);
963 GL_ColorPointer(varray_color4f);
965 GL_VertexPointer(surf->mesh.data_vertex3f);
967 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
968 R_Mesh_State_Texture(&m);
969 RSurf_FogPassColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], currentalpha, 1, surf->mesh.num_vertices, modelorg);
970 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
973 static void RSurfShader_OpaqueWall_Pass_BaseTripleTexCombine(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
975 const msurface_t *surf;
977 int lightmaptexturenum;
979 memset(&m, 0, sizeof(m));
980 GL_BlendFunc(GL_ONE, GL_ZERO);
983 m.tex[0] = R_GetTexture(texture->skin.base);
984 m.tex[1] = R_GetTexture((**surfchain).lightmaptexture);
985 m.tex[2] = R_GetTexture(texture->skin.detail);
986 m.texrgbscale[0] = 1;
987 m.texrgbscale[1] = 4;
988 m.texrgbscale[2] = 2;
989 cl = (float) (1 << r_lightmapscalebit);
990 GL_Color(cl, cl, cl, 1);
992 while((surf = *surfchain++) != NULL)
994 if (surf->visframe == r_framecount)
996 lightmaptexturenum = R_GetTexture(surf->lightmaptexture);
997 //if (m.tex[1] != lightmaptexturenum)
999 m.tex[1] = lightmaptexturenum;
1000 // R_Mesh_State_Texture(&m);
1002 GL_VertexPointer(surf->mesh.data_vertex3f);
1003 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1004 m.pointer_texcoord[1] = surf->mesh.data_texcoordlightmap2f;
1005 m.pointer_texcoord[2] = surf->mesh.data_texcoorddetail2f;
1006 R_Mesh_State_Texture(&m);
1007 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1012 static void RSurfShader_OpaqueWall_Pass_BaseDoubleTex(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1014 const msurface_t *surf;
1016 int lightmaptexturenum;
1017 memset(&m, 0, sizeof(m));
1018 GL_BlendFunc(GL_ONE, GL_ZERO);
1021 m.tex[0] = R_GetTexture(texture->skin.base);
1022 m.tex[1] = R_GetTexture((**surfchain).lightmaptexture);
1023 if (gl_combine.integer)
1024 m.texrgbscale[1] = 4;
1025 GL_Color(1, 1, 1, 1);
1026 while((surf = *surfchain++) != NULL)
1028 if (surf->visframe == r_framecount)
1030 lightmaptexturenum = R_GetTexture(surf->lightmaptexture);
1031 //if (m.tex[1] != lightmaptexturenum)
1033 m.tex[1] = lightmaptexturenum;
1034 // R_Mesh_State_Texture(&m);
1036 GL_VertexPointer(surf->mesh.data_vertex3f);
1037 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1038 m.pointer_texcoord[1] = surf->mesh.data_texcoordlightmap2f;
1039 R_Mesh_State_Texture(&m);
1040 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1045 static void RSurfShader_OpaqueWall_Pass_BaseTexture(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1047 const msurface_t *surf;
1049 memset(&m, 0, sizeof(m));
1052 GL_BlendFunc(GL_ONE, GL_ZERO);
1053 m.tex[0] = R_GetTexture(texture->skin.base);
1054 GL_Color(1, 1, 1, 1);
1055 while((surf = *surfchain++) != NULL)
1057 if (surf->visframe == r_framecount)
1059 GL_VertexPointer(surf->mesh.data_vertex3f);
1060 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1061 R_Mesh_State_Texture(&m);
1062 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1067 static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1069 const msurface_t *surf;
1071 int lightmaptexturenum;
1072 memset(&m, 0, sizeof(m));
1073 GL_BlendFunc(GL_ZERO, GL_SRC_COLOR);
1074 GL_DepthMask(false);
1076 m.tex[0] = R_GetTexture((**surfchain).lightmaptexture);
1077 if (gl_combine.integer)
1078 m.texrgbscale[0] = 4;
1079 GL_Color(1, 1, 1, 1);
1080 while((surf = *surfchain++) != NULL)
1082 if (surf->visframe == r_framecount)
1084 lightmaptexturenum = R_GetTexture(surf->lightmaptexture);
1085 //if (m.tex[0] != lightmaptexturenum)
1087 m.tex[0] = lightmaptexturenum;
1088 // R_Mesh_State_Texture(&m);
1090 GL_VertexPointer(surf->mesh.data_vertex3f);
1091 m.pointer_texcoord[0] = surf->mesh.data_texcoordlightmap2f;
1092 R_Mesh_State_Texture(&m);
1093 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1098 static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1100 const msurface_t *surf;
1103 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1104 memset(&m, 0, sizeof(m));
1105 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1106 GL_DepthMask(false);
1108 GL_ColorPointer(varray_color4f);
1109 while((surf = *surfchain++) != NULL)
1111 if (surf->visframe == r_framecount)
1113 GL_VertexPointer(surf->mesh.data_vertex3f);
1115 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1116 R_Mesh_State_Texture(&m);
1117 RSurf_FogPassColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surf->mesh.num_vertices, modelorg);
1118 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1123 static void RSurfShader_OpaqueWall_Pass_BaseDetail(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1125 const msurface_t *surf;
1127 memset(&m, 0, sizeof(m));
1128 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1129 GL_DepthMask(false);
1131 m.tex[0] = R_GetTexture(texture->skin.detail);
1132 GL_Color(1, 1, 1, 1);
1133 while((surf = *surfchain++) != NULL)
1135 if (surf->visframe == r_framecount)
1137 GL_VertexPointer(surf->mesh.data_vertex3f);
1138 m.pointer_texcoord[0] = surf->mesh.data_texcoorddetail2f;
1139 R_Mesh_State_Texture(&m);
1140 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1145 static void RSurfShader_OpaqueWall_Pass_Glow(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1147 const msurface_t *surf;
1149 memset(&m, 0, sizeof(m));
1150 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1151 GL_DepthMask(false);
1153 m.tex[0] = R_GetTexture(texture->skin.glow);
1154 GL_Color(1, 1, 1, 1);
1155 while((surf = *surfchain++) != NULL)
1157 if (surf->visframe == r_framecount)
1159 GL_VertexPointer(surf->mesh.data_vertex3f);
1160 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1161 R_Mesh_State_Texture(&m);
1162 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1167 static void RSurfShader_OpaqueWall_Pass_OpaqueGlow(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1169 const msurface_t *surf;
1171 memset(&m, 0, sizeof(m));
1172 GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
1174 m.tex[0] = R_GetTexture(texture->skin.glow);
1176 GL_Color(1, 1, 1, 1);
1178 GL_Color(0, 0, 0, 1);
1179 while((surf = *surfchain++) != NULL)
1181 if (surf->visframe == r_framecount)
1183 GL_VertexPointer(surf->mesh.data_vertex3f);
1184 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
1185 R_Mesh_State_Texture(&m);
1186 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
1191 static void RSurfShader_Wall_Vertex_Callback(const void *calldata1, int calldata2)
1193 const entity_render_t *ent = calldata1;
1194 const msurface_t *surf = ent->model->brushq1.surfaces + calldata2;
1198 R_Mesh_Matrix(&ent->matrix);
1200 texture = surf->texinfo->texture;
1201 if (texture->animated)
1202 texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (cl.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
1204 currentalpha = ent->alpha;
1205 if (ent->effects & EF_ADDITIVE)
1206 rendertype = SURFRENDER_ADD;
1207 else if (currentalpha < 1 || texture->skin.fog != NULL)
1208 rendertype = SURFRENDER_ALPHA;
1210 rendertype = SURFRENDER_OPAQUE;
1212 RSurfShader_Wall_Pass_BaseVertex(ent, surf, texture, rendertype, currentalpha);
1213 if (texture->skin.glow)
1214 RSurfShader_Wall_Pass_Glow(ent, surf, texture, rendertype, currentalpha);
1216 RSurfShader_Wall_Pass_Fog(ent, surf, texture, rendertype, currentalpha);
1219 static void RSurfShader_Wall_Lightmap(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain)
1221 const msurface_t *surf;
1224 if (texture->rendertype != SURFRENDER_OPAQUE)
1226 // transparent vertex shaded from lightmap
1227 for (chain = surfchain;(surf = *chain) != NULL;chain++)
1229 if (surf->visframe == r_framecount)
1231 Matrix4x4_Transform(&ent->matrix, surf->poly_center, center);
1232 R_MeshQueue_AddTransparent(center, RSurfShader_Wall_Vertex_Callback, ent, surf - ent->model->brushq1.surfaces);
1236 else if (r_shadow_realtime_world.integer)
1238 // opaque base lighting
1239 RSurfShader_OpaqueWall_Pass_OpaqueGlow(ent, texture, surfchain);
1241 RSurfShader_OpaqueWall_Pass_Fog(ent, texture, surfchain);
1245 // opaque lightmapped
1246 if (r_textureunits.integer >= 3 && gl_combine.integer && r_detailtextures.integer)
1247 RSurfShader_OpaqueWall_Pass_BaseTripleTexCombine(ent, texture, surfchain);
1248 else if (r_textureunits.integer >= 2)
1250 RSurfShader_OpaqueWall_Pass_BaseDoubleTex(ent, texture, surfchain);
1251 if (r_detailtextures.integer)
1252 RSurfShader_OpaqueWall_Pass_BaseDetail(ent, texture, surfchain);
1256 RSurfShader_OpaqueWall_Pass_BaseTexture(ent, texture, surfchain);
1257 RSurfShader_OpaqueWall_Pass_BaseLightmap(ent, texture, surfchain);
1258 if (r_detailtextures.integer)
1259 RSurfShader_OpaqueWall_Pass_BaseDetail(ent, texture, surfchain);
1261 if (texture->skin.glow)
1262 RSurfShader_OpaqueWall_Pass_Glow(ent, texture, surfchain);
1264 RSurfShader_OpaqueWall_Pass_Fog(ent, texture, surfchain);
1268 Cshader_t Cshader_wall_lightmap = {{NULL, RSurfShader_Wall_Lightmap}, SHADERFLAGS_NEEDLIGHTMAP};
1269 Cshader_t Cshader_water = {{NULL, RSurfShader_Water}, 0};
1270 Cshader_t Cshader_sky = {{RSurfShader_Sky, NULL}, 0};
1272 int Cshader_count = 3;
1273 Cshader_t *Cshaders[3] =
1275 &Cshader_wall_lightmap,
1280 void R_UpdateTextureInfo(entity_render_t *ent)
1282 int i, texframe, alttextures;
1288 alttextures = ent->frame != 0;
1289 texframe = (int)(cl.time * 5.0f);
1290 for (i = 0;i < ent->model->brushq1.numtextures;i++)
1292 t = ent->model->brushq1.textures + i;
1293 t->currentalpha = ent->alpha;
1294 if (t->flags & SURF_WATERALPHA)
1295 t->currentalpha *= r_wateralpha.value;
1296 if (ent->effects & EF_ADDITIVE)
1297 t->rendertype = SURFRENDER_ADD;
1298 else if (t->currentalpha < 1 || t->skin.fog != NULL)
1299 t->rendertype = SURFRENDER_ALPHA;
1301 t->rendertype = SURFRENDER_OPAQUE;
1302 // we don't need to set currentframe if t->animated is false because
1303 // it was already set up by the texture loader for non-animating
1305 t->currentframe = t->anim_frames[alttextures][(t->anim_total[alttextures] >= 2) ? (texframe % t->anim_total[alttextures]) : 0];
1309 void R_PrepareSurfaces(entity_render_t *ent)
1311 int i, numsurfaces, *surfacevisframes;
1313 msurface_t *surf, *surfaces, **surfchain;
1320 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1321 numsurfaces = model->brushq1.nummodelsurfaces;
1322 surfaces = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
1323 surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
1325 R_UpdateTextureInfo(ent);
1327 if (r_dynamic.integer && !r_shadow_realtime_dlight.integer)
1330 if (model->brushq1.light_ambient != r_ambient.value || model->brushq1.light_scalebit != r_lightmapscalebit)
1332 model->brushq1.light_ambient = r_ambient.value;
1333 model->brushq1.light_scalebit = r_lightmapscalebit;
1334 for (i = 0;i < model->brushq1.nummodelsurfaces;i++)
1335 model->brushq1.surfaces[i + model->brushq1.firstmodelsurface].cached_dlight = true;
1339 for (i = 0;i < model->brushq1.light_styles;i++)
1341 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1343 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1344 for (surfchain = model->brushq1.light_styleupdatechains[i];*surfchain;surfchain++)
1345 (**surfchain).cached_dlight = true;
1350 for (i = 0, surf = surfaces;i < numsurfaces;i++, surf++)
1352 if (surfacevisframes[i] == r_framecount)
1354 #if !WORLDNODECULLBACKFACES
1355 // mark any backface surfaces as not visible
1356 if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
1358 if (!(surf->flags & SURF_PLANEBACK))
1359 surfacevisframes[i] = -1;
1363 if ((surf->flags & SURF_PLANEBACK))
1364 surfacevisframes[i] = -1;
1366 if (surfacevisframes[i] == r_framecount)
1370 surf->visframe = r_framecount;
1371 if (surf->cached_dlight && surf->lightmaptexture != NULL)
1372 R_BuildLightMap(ent, surf);
1378 void R_DrawSurfaces(entity_render_t *ent, int type, msurface_t ***chains)
1382 if (ent->model == NULL)
1384 R_Mesh_Matrix(&ent->matrix);
1385 for (i = 0, t = ent->model->brushq1.textures;i < ent->model->brushq1.numtextures;i++, t++)
1386 if (t->shader->shaderfunc[type] && t->currentframe && chains[i] != NULL)
1387 t->shader->shaderfunc[type](ent, t->currentframe, chains[i]);
1390 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1395 const entity_render_t *ent = calldata1;
1396 const mportal_t *portal = ent->model->brushq1.portals + calldata2;
1397 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1398 GL_DepthMask(false);
1400 R_Mesh_Matrix(&ent->matrix);
1401 GL_VertexPointer(varray_vertex3f);
1403 memset(&m, 0, sizeof(m));
1404 R_Mesh_State_Texture(&m);
1406 i = portal - ent->model->brushq1.portals;
1407 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1408 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1409 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1411 if (PlaneDiff(r_origin, (&portal->plane)) < 0)
1413 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1414 VectorCopy(portal->points[i].position, v);
1417 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1418 VectorCopy(portal->points[i].position, v);
1419 R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
1422 // LordHavoc: this is just a nice debugging tool, very slow
1423 static void R_DrawPortals(entity_render_t *ent)
1426 mportal_t *portal, *endportal;
1427 float temp[3], center[3], f;
1428 if (ent->model == NULL)
1430 for (portal = ent->model->brushq1.portals, endportal = portal + ent->model->brushq1.numportals;portal < endportal;portal++)
1432 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1435 for (i = 0;i < portal->numpoints;i++)
1436 VectorAdd(temp, portal->points[i].position, temp);
1437 f = ixtable[portal->numpoints];
1438 VectorScale(temp, f, temp);
1439 Matrix4x4_Transform(&ent->matrix, temp, center);
1440 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, ent, portal - ent->model->brushq1.portals);
1445 void R_PrepareBrushModel(entity_render_t *ent)
1447 int i, numsurfaces, *surfacevisframes, *surfacepvsframes;
1450 #if WORLDNODECULLBACKFACES
1454 // because bmodels can be reused, we have to decide which things to render
1455 // from scratch every time
1459 #if WORLDNODECULLBACKFACES
1460 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1462 numsurfaces = model->brushq1.nummodelsurfaces;
1463 surf = model->brushq1.surfaces + model->brushq1.firstmodelsurface;
1464 surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
1465 surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
1466 for (i = 0;i < numsurfaces;i++, surf++)
1468 #if WORLDNODECULLBACKFACES
1469 // mark any backface surfaces as not visible
1470 if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
1472 if ((surf->flags & SURF_PLANEBACK))
1473 surfacevisframes[i] = r_framecount;
1475 else if (!(surf->flags & SURF_PLANEBACK))
1476 surfacevisframes[i] = r_framecount;
1478 surfacevisframes[i] = r_framecount;
1480 surf->dlightframe = -1;
1482 R_PrepareSurfaces(ent);
1485 void R_SurfaceWorldNode (entity_render_t *ent)
1487 int i, *surfacevisframes, *surfacepvsframes, surfnum;
1493 // equivilant to quake's RecursiveWorldNode but faster and more effective
1497 surfacevisframes = model->brushq1.surfacevisframes + model->brushq1.firstmodelsurface;
1498 surfacepvsframes = model->brushq1.surfacepvsframes + model->brushq1.firstmodelsurface;
1499 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1501 for (leaf = model->brushq1.pvsleafchain;leaf;leaf = leaf->pvschain)
1503 if (!R_CullBox (leaf->mins, leaf->maxs))
1506 leaf->visframe = r_framecount;
1510 for (i = 0;i < model->brushq1.pvssurflistlength;i++)
1512 surfnum = model->brushq1.pvssurflist[i];
1513 surf = model->brushq1.surfaces + surfnum;
1514 #if WORLDNODECULLBACKFACES
1515 if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
1517 if ((surf->flags & SURF_PLANEBACK) && !R_CullBox (surf->poly_mins, surf->poly_maxs))
1518 surfacevisframes[surfnum] = r_framecount;
1522 if (!(surf->flags & SURF_PLANEBACK) && !R_CullBox (surf->poly_mins, surf->poly_maxs))
1523 surfacevisframes[surfnum] = r_framecount;
1526 if (!R_CullBox (surf->poly_mins, surf->poly_maxs))
1527 surfacevisframes[surfnum] = r_framecount;
1532 static void R_PortalWorldNode(entity_render_t *ent, mleaf_t *viewleaf)
1534 int c, leafstackpos, *mark, *surfacevisframes, bitnum;
1535 #if WORLDNODECULLBACKFACES
1539 mleaf_t *leaf, *leafstack[8192];
1542 msurface_t *surfaces;
1543 if (ent->model == NULL)
1545 // LordHavoc: portal-passage worldnode with PVS;
1546 // follows portals leading outward from viewleaf, does not venture
1547 // offscreen or into leafs that are not visible, faster than Quake's
1548 // RecursiveWorldNode
1549 surfaces = ent->model->brushq1.surfaces;
1550 surfacevisframes = ent->model->brushq1.surfacevisframes;
1551 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1552 viewleaf->worldnodeframe = r_framecount;
1553 leafstack[0] = viewleaf;
1555 while (leafstackpos)
1558 leaf = leafstack[--leafstackpos];
1559 leaf->visframe = r_framecount;
1560 // draw any surfaces bounding this leaf
1561 if (leaf->nummarksurfaces)
1563 for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--)
1565 #if WORLDNODECULLBACKFACES
1567 if (surfacevisframes[n] != r_framecount)
1569 surf = surfaces + n;
1570 if (PlaneDist(modelorg, surf->plane) < surf->plane->dist)
1572 if ((surf->flags & SURF_PLANEBACK))
1573 surfacevisframes[n] = r_framecount;
1577 if (!(surf->flags & SURF_PLANEBACK))
1578 surfacevisframes[n] = r_framecount;
1582 surfacevisframes[*mark++] = r_framecount;
1586 // follow portals into other leafs
1587 for (p = leaf->portals;p;p = p->next)
1589 // LordHavoc: this DotProduct hurts less than a cache miss
1590 // (which is more likely to happen if backflowing through leafs)
1591 if (DotProduct(modelorg, p->plane.normal) < (p->plane.dist + 1))
1594 if (leaf->worldnodeframe != r_framecount)
1596 leaf->worldnodeframe = r_framecount;
1597 // FIXME: R_CullBox is absolute, should be done relative
1598 bitnum = (leaf - ent->model->brushq1.leafs) - 1;
1599 if ((r_pvsbits[bitnum >> 3] & (1 << (bitnum & 7))) && !R_CullBox(leaf->mins, leaf->maxs))
1600 leafstack[leafstackpos++] = leaf;
1607 void R_PVSUpdate (entity_render_t *ent, mleaf_t *viewleaf)
1609 int j, c, *surfacepvsframes, *mark;
1614 if (model && (model->brushq1.pvsviewleaf != viewleaf || model->brushq1.pvsviewleafnovis != r_novis.integer))
1616 model->brushq1.pvsframecount++;
1617 model->brushq1.pvsviewleaf = viewleaf;
1618 model->brushq1.pvsviewleafnovis = r_novis.integer;
1619 model->brushq1.pvsleafchain = NULL;
1620 model->brushq1.pvssurflistlength = 0;
1623 surfacepvsframes = model->brushq1.surfacepvsframes;
1624 for (j = 0;j < model->brushq1.visleafs;j++)
1626 if (r_pvsbits[j >> 3] & (1 << (j & 7)))
1628 leaf = model->brushq1.leafs + j + 1;
1629 leaf->pvsframe = model->brushq1.pvsframecount;
1630 leaf->pvschain = model->brushq1.pvsleafchain;
1631 model->brushq1.pvsleafchain = leaf;
1632 // mark surfaces bounding this leaf as visible
1633 for (c = leaf->nummarksurfaces, mark = leaf->firstmarksurface;c;c--, mark++)
1634 surfacepvsframes[*mark] = model->brushq1.pvsframecount;
1637 model->brushq1.BuildPVSTextureChains(model);
1642 void R_WorldVisibility(entity_render_t *ent)
1647 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1648 viewleaf = (ent->model && ent->model->brushq1.PointInLeaf) ? ent->model->brushq1.PointInLeaf(ent->model, modelorg) : NULL;
1649 R_PVSUpdate(ent, viewleaf);
1654 if (r_surfaceworldnode.integer || viewleaf->contents == CONTENTS_SOLID)
1655 R_SurfaceWorldNode (ent);
1657 R_PortalWorldNode (ent, viewleaf);
1660 void R_DrawWorld(entity_render_t *ent)
1662 if (ent->model == NULL)
1664 if (!ent->model->brushq1.numleafs)
1666 if (ent->model->DrawSky)
1667 ent->model->DrawSky(ent);
1668 if (ent->model->Draw)
1669 ent->model->Draw(ent);
1673 R_PrepareSurfaces(ent);
1674 R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->brushq1.pvstexturechains);
1675 R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->brushq1.pvstexturechains);
1676 if (r_drawportals.integer)
1681 void R_Model_Brush_DrawSky(entity_render_t *ent)
1683 if (ent->model == NULL)
1685 if (ent != &cl_entities[0].render)
1686 R_PrepareBrushModel(ent);
1687 R_DrawSurfaces(ent, SHADERSTAGE_SKY, ent->model->brushq1.pvstexturechains);
1690 void R_Model_Brush_Draw(entity_render_t *ent)
1692 if (ent->model == NULL)
1695 if (ent != &cl_entities[0].render)
1696 R_PrepareBrushModel(ent);
1697 R_DrawSurfaces(ent, SHADERSTAGE_NORMAL, ent->model->brushq1.pvstexturechains);
1700 void R_Model_Brush_DrawShadowVolume (entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
1704 float projectdistance, f, temp[3], lightradius2;
1705 if (ent->model == NULL)
1707 R_Mesh_Matrix(&ent->matrix);
1708 lightradius2 = lightradius * lightradius;
1709 R_UpdateTextureInfo(ent);
1710 projectdistance = 1000000000.0f;//lightradius + ent->model->radius;
1711 for (i = 0, surf = ent->model->brushq1.surfaces + ent->model->brushq1.firstmodelsurface;i < ent->model->brushq1.nummodelsurfaces;i++, surf++)
1713 if (surf->texinfo->texture->rendertype == SURFRENDER_OPAQUE && surf->flags & SURF_SHADOWCAST)
1715 f = PlaneDiff(relativelightorigin, surf->plane);
1716 if (surf->flags & SURF_PLANEBACK)
1718 // draw shadows only for frontfaces and only if they are close
1719 if (f >= 0.1 && f < lightradius)
1721 temp[0] = bound(surf->poly_mins[0], relativelightorigin[0], surf->poly_maxs[0]) - relativelightorigin[0];
1722 temp[1] = bound(surf->poly_mins[1], relativelightorigin[1], surf->poly_maxs[1]) - relativelightorigin[1];
1723 temp[2] = bound(surf->poly_mins[2], relativelightorigin[2], surf->poly_maxs[2]) - relativelightorigin[2];
1724 if (DotProduct(temp, temp) < lightradius2)
1725 R_Shadow_Volume(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_vertex3f, surf->mesh.data_element3i, surf->mesh.data_neighbor3i, relativelightorigin, lightradius, projectdistance);
1731 void R_Model_Brush_DrawLightForSurfaceList(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, msurface_t **surflist, int numsurfaces, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
1736 if (ent->model == NULL)
1738 R_Mesh_Matrix(&ent->matrix);
1739 R_UpdateTextureInfo(ent);
1740 for (surfnum = 0;surfnum < numsurfaces;surfnum++)
1742 surf = surflist[surfnum];
1743 if (surf->visframe == r_framecount)
1745 t = surf->texinfo->texture->currentframe;
1746 if (t->rendertype == SURFRENDER_OPAQUE && t->flags & SURF_SHADOWLIGHT)
1748 R_Shadow_DiffuseLighting(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i, surf->mesh.data_vertex3f, surf->mesh.data_svector3f, surf->mesh.data_tvector3f, surf->mesh.data_normal3f, surf->mesh.data_texcoordtexture2f, relativelightorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, NULL);
1749 R_Shadow_SpecularLighting(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i, surf->mesh.data_vertex3f, surf->mesh.data_svector3f, surf->mesh.data_tvector3f, surf->mesh.data_normal3f, surf->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.gloss, t->skin.nmap, NULL);
1755 void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
1760 float f, lightmins[3], lightmaxs[3];
1761 if (ent->model == NULL)
1763 R_Mesh_Matrix(&ent->matrix);
1764 lightmins[0] = relativelightorigin[0] - lightradius;
1765 lightmins[1] = relativelightorigin[1] - lightradius;
1766 lightmins[2] = relativelightorigin[2] - lightradius;
1767 lightmaxs[0] = relativelightorigin[0] + lightradius;
1768 lightmaxs[1] = relativelightorigin[1] + lightradius;
1769 lightmaxs[2] = relativelightorigin[2] + lightradius;
1770 R_UpdateTextureInfo(ent);
1771 for (surfnum = 0, surf = ent->model->brushq1.surfaces + ent->model->brushq1.firstmodelsurface;surfnum < ent->model->brushq1.nummodelsurfaces;surfnum++, surf++)
1773 if ((ent != &cl_entities[0].render || surf->visframe == r_framecount) && BoxesOverlap(surf->poly_mins, surf->poly_maxs, lightmins, lightmaxs))
1775 f = PlaneDiff(relativelightorigin, surf->plane);
1776 if (surf->flags & SURF_PLANEBACK)
1778 if (f >= -0.1 && f < lightradius)
1780 t = surf->texinfo->texture->currentframe;
1781 if (t->rendertype == SURFRENDER_OPAQUE && t->flags & SURF_SHADOWLIGHT)
1783 R_Shadow_DiffuseLighting(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i, surf->mesh.data_vertex3f, surf->mesh.data_svector3f, surf->mesh.data_tvector3f, surf->mesh.data_normal3f, surf->mesh.data_texcoordtexture2f, relativelightorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, NULL);
1784 R_Shadow_SpecularLighting(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i, surf->mesh.data_vertex3f, surf->mesh.data_svector3f, surf->mesh.data_tvector3f, surf->mesh.data_normal3f, surf->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.gloss, t->skin.nmap, NULL);
1791 void R_DrawCollisionBrush(colbrushf_t *brush)
1794 i = ((int)brush) / sizeof(colbrushf_t);
1795 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1796 GL_VertexPointer(brush->points->v);
1797 R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
1800 void R_Q3BSP_DrawSkyFace(entity_render_t *ent, q3mface_t *face)
1803 if (!face->num_triangles)
1807 skyrendernow = false;
1808 if (skyrendermasked)
1812 R_Mesh_Matrix(&ent->matrix);
1814 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1815 if (skyrendermasked)
1817 // depth-only (masking)
1818 qglColorMask(0,0,0,0);
1819 // just to make sure that braindead drivers don't draw anything
1820 // despite that colormask...
1821 GL_BlendFunc(GL_ZERO, GL_ONE);
1826 GL_BlendFunc(GL_ONE, GL_ZERO);
1831 memset(&m, 0, sizeof(m));
1832 R_Mesh_State_Texture(&m);
1834 GL_VertexPointer(face->data_vertex3f);
1835 R_Mesh_Draw(face->num_vertices, face->num_triangles, face->data_element3i);
1836 qglColorMask(1,1,1,1);
1839 void R_Q3BSP_DrawFace(entity_render_t *ent, q3mface_t *face)
1842 if (!face->num_triangles)
1844 if (face->texture->renderflags)
1846 if (face->texture->renderflags & Q3MTEXTURERENDERFLAGS_SKY)
1848 if (face->texture->renderflags & Q3MTEXTURERENDERFLAGS_NODRAW)
1851 R_Mesh_Matrix(&ent->matrix);
1852 face->visframe = r_framecount;
1853 memset(&m, 0, sizeof(m));
1854 GL_BlendFunc(GL_ONE, GL_ZERO);
1857 m.tex[0] = R_GetTexture(face->texture->skin.base);
1858 m.pointer_texcoord[0] = face->data_texcoordtexture2f;
1859 if (face->lightmaptexture)
1861 m.tex[1] = R_GetTexture(face->lightmaptexture);
1862 m.pointer_texcoord[1] = face->data_texcoordlightmap2f;
1863 m.texrgbscale[1] = 2;
1864 GL_Color(1, 1, 1, 1);
1868 m.texrgbscale[0] = 2;
1869 GL_ColorPointer(face->data_color4f);
1871 R_Mesh_State_Texture(&m);
1872 GL_VertexPointer(face->data_vertex3f);
1873 R_Mesh_Draw(face->num_vertices, face->num_triangles, face->data_element3i);
1876 void R_Q3BSP_RecursiveWorldNode(entity_render_t *ent, q3mnode_t *node, const vec3_t modelorg, qbyte *pvs, int markframe)
1880 while (node->isnode)
1882 if (R_CullBox(node->mins, node->maxs))
1884 R_Q3BSP_RecursiveWorldNode(ent, node->children[0], modelorg, pvs, markframe);
1885 node = node->children[1];
1887 if (R_CullBox(node->mins, node->maxs))
1889 leaf = (q3mleaf_t *)node;
1890 if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7)))
1891 for (i = 0;i < leaf->numleaffaces;i++)
1892 leaf->firstleafface[i]->markframe = markframe;
1895 static int r_q3bsp_framecount = -1;
1897 void R_Q3BSP_DrawSky(entity_render_t *ent)
1904 R_Mesh_Matrix(&ent->matrix);
1906 if (r_drawcollisionbrushes.integer < 2)
1908 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1909 if (ent == &cl_entities[0].render && model->brushq3.num_pvsclusters && !r_novis.integer && (pvs = model->brush.GetPVS(model, modelorg)))
1911 if (r_q3bsp_framecount != r_framecount)
1913 r_q3bsp_framecount = r_framecount;
1914 R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount);
1916 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
1917 if (face->markframe == r_framecount && (face->texture->renderflags & Q3MTEXTURERENDERFLAGS_SKY) && !R_CullBox(face->mins, face->maxs))
1918 R_Q3BSP_DrawSkyFace(ent, face);
1921 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
1922 if ((face->texture->renderflags & Q3MTEXTURERENDERFLAGS_SKY))
1923 R_Q3BSP_DrawSkyFace(ent, face);
1927 void R_Q3BSP_Draw(entity_render_t *ent)
1934 R_Mesh_Matrix(&ent->matrix);
1936 if (r_drawcollisionbrushes.integer < 2)
1938 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1939 if (ent == &cl_entities[0].render && model->brushq3.num_pvsclusters && !r_novis.integer && (pvs = model->brush.GetPVS(model, modelorg)))
1941 if (r_q3bsp_framecount != r_framecount)
1943 r_q3bsp_framecount = r_framecount;
1944 R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount);
1946 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
1947 if (face->markframe == r_framecount && !R_CullBox(face->mins, face->maxs))
1948 R_Q3BSP_DrawFace(ent, face);
1951 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
1952 R_Q3BSP_DrawFace(ent, face);
1954 if (r_drawcollisionbrushes.integer >= 1)
1957 memset(&m, 0, sizeof(m));
1958 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1959 GL_DepthMask(false);
1961 R_Mesh_State_Texture(&m);
1962 for (i = 0;i < model->brushq3.data_thismodel->numbrushes;i++)
1963 if (model->brushq3.data_thismodel->firstbrush[i].colbrushf && model->brushq3.data_thismodel->firstbrush[i].colbrushf->numtriangles)
1964 R_DrawCollisionBrush(model->brushq3.data_thismodel->firstbrush[i].colbrushf);
1968 void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
1972 vec3_t modelorg, lightmins, lightmaxs;
1974 float projectdistance;
1975 projectdistance = 1000000000.0f;//lightradius + ent->model->radius;
1976 if (r_drawcollisionbrushes.integer < 2)
1979 R_Mesh_Matrix(&ent->matrix);
1980 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
1981 lightmins[0] = relativelightorigin[0] - lightradius;
1982 lightmins[1] = relativelightorigin[1] - lightradius;
1983 lightmins[2] = relativelightorigin[2] - lightradius;
1984 lightmaxs[0] = relativelightorigin[0] + lightradius;
1985 lightmaxs[1] = relativelightorigin[1] + lightradius;
1986 lightmaxs[2] = relativelightorigin[2] + lightradius;
1987 //if (ent == &cl_entities[0].render && model->brushq3.num_pvsclusters && !r_novis.integer && (pvs = model->brush.GetPVS(model, modelorg)))
1988 // R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, ++markframe);
1990 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
1991 if (BoxesOverlap(lightmins, lightmaxs, face->mins, face->maxs))
1992 R_Shadow_Volume(face->num_vertices, face->num_triangles, face->data_vertex3f, face->data_element3i, face->data_neighbor3i, relativelightorigin, lightradius, projectdistance);
1996 void R_Q3BSP_DrawFaceLight(entity_render_t *ent, q3mface_t *face, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
1998 if ((face->texture->renderflags & Q3MTEXTURERENDERFLAGS_NODRAW) || !face->num_triangles)
2000 R_Shadow_DiffuseLighting(face->num_vertices, face->num_triangles, face->data_element3i, face->data_vertex3f, face->data_svector3f, face->data_tvector3f, face->data_normal3f, face->data_texcoordtexture2f, relativelightorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, face->texture->skin.base, face->texture->skin.nmap, NULL);
2001 R_Shadow_SpecularLighting(face->num_vertices, face->num_triangles, face->data_element3i, face->data_vertex3f, face->data_svector3f, face->data_tvector3f, face->data_normal3f, face->data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, face->texture->skin.gloss, face->texture->skin.nmap, NULL);
2004 void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
2008 vec3_t modelorg, lightmins, lightmaxs;
2011 //static int markframe = 0;
2012 if (r_drawcollisionbrushes.integer < 2)
2015 R_Mesh_Matrix(&ent->matrix);
2016 Matrix4x4_Transform(&ent->inversematrix, r_origin, modelorg);
2017 lightmins[0] = relativelightorigin[0] - lightradius;
2018 lightmins[1] = relativelightorigin[1] - lightradius;
2019 lightmins[2] = relativelightorigin[2] - lightradius;
2020 lightmaxs[0] = relativelightorigin[0] + lightradius;
2021 lightmaxs[1] = relativelightorigin[1] + lightradius;
2022 lightmaxs[2] = relativelightorigin[2] + lightradius;
2023 //if (ent == &cl_entities[0].render && model->brushq3.num_pvsclusters && !r_novis.integer && (pvs = model->brush.GetPVS(model, modelorg)))
2024 // R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, ++markframe);
2026 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
2027 if ((ent != &cl_entities[0].render || face->visframe == r_framecount) && BoxesOverlap(lightmins, lightmaxs, face->mins, face->maxs))
2028 R_Q3BSP_DrawFaceLight(ent, face, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz);
2032 static void gl_surf_start(void)
2036 static void gl_surf_shutdown(void)
2040 static void gl_surf_newmap(void)
2044 void GL_Surf_Init(void)
2047 dlightdivtable[0] = 4194304;
2048 for (i = 1;i < 32768;i++)
2049 dlightdivtable[i] = 4194304 / (i << 7);
2051 Cvar_RegisterVariable(&r_ambient);
2052 Cvar_RegisterVariable(&r_drawportals);
2053 Cvar_RegisterVariable(&r_testvis);
2054 Cvar_RegisterVariable(&r_floatbuildlightmap);
2055 Cvar_RegisterVariable(&r_detailtextures);
2056 Cvar_RegisterVariable(&r_surfaceworldnode);
2057 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
2059 R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);