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.
24 // used for dlight push checking and other things
29 matrix4x4_t r_identitymatrix;
31 int c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
33 // true during envmap command capture
49 // 8.8 fraction of base light value
50 unsigned short d_lightstylevalue[256];
52 cvar_t r_drawentities = {0, "r_drawentities","1"};
53 cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
54 cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "0"};
55 cvar_t r_shadow_staticworldlights = {0, "r_shadow_staticworldlights", "1"};
56 cvar_t r_speeds = {0, "r_speeds","0"};
57 cvar_t r_fullbright = {0, "r_fullbright","0"};
58 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
59 cvar_t r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
60 cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
61 cvar_t r_shadow_cull = {0, "r_shadow_cull", "1"};
63 cvar_t gl_fogenable = {0, "gl_fogenable", "0"};
64 cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25"};
65 cvar_t gl_fogred = {0, "gl_fogred","0.3"};
66 cvar_t gl_foggreen = {0, "gl_foggreen","0.3"};
67 cvar_t gl_fogblue = {0, "gl_fogblue","0.3"};
68 cvar_t gl_fogstart = {0, "gl_fogstart", "0"};
69 cvar_t gl_fogend = {0, "gl_fogend","0"};
71 cvar_t r_textureunits = {0, "r_textureunits", "32"};
73 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
76 for (i = 0;i < verts;i++)
87 void R_FillColors(float *out, int verts, float r, float g, float b, float a)
90 for (i = 0;i < verts;i++)
104 For program optimization
107 qboolean intimerefresh = 0;
108 static void R_TimeRefresh_f (void)
111 float start, stop, time;
114 start = Sys_DoubleTime ();
115 for (i = 0;i < 128;i++)
117 r_refdef.viewangles[0] = 0;
118 r_refdef.viewangles[1] = i/128.0*360.0;
119 r_refdef.viewangles[2] = 0;
123 stop = Sys_DoubleTime ();
126 Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
131 float fog_density, fog_red, fog_green, fog_blue;
133 qboolean oldgl_fogenable;
134 void R_SetupFog(void)
136 if (gamemode == GAME_NEHAHRA)
138 if (gl_fogenable.integer)
140 oldgl_fogenable = true;
141 fog_density = gl_fogdensity.value;
142 fog_red = gl_fogred.value;
143 fog_green = gl_foggreen.value;
144 fog_blue = gl_fogblue.value;
146 else if (oldgl_fogenable)
148 oldgl_fogenable = false;
157 fogcolor[0] = fog_red = bound(0.0f, fog_red , 1.0f);
158 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
159 fogcolor[2] = fog_blue = bound(0.0f, fog_blue , 1.0f);
164 fogdensity = -4000.0f / (fog_density * fog_density);
165 // fog color was already set
171 // FIXME: move this to client?
174 if (gamemode == GAME_NEHAHRA)
176 Cvar_Set("gl_fogenable", "0");
177 Cvar_Set("gl_fogdensity", "0.2");
178 Cvar_Set("gl_fogred", "0.3");
179 Cvar_Set("gl_foggreen", "0.3");
180 Cvar_Set("gl_fogblue", "0.3");
182 fog_density = fog_red = fog_green = fog_blue = 0.0f;
185 // FIXME: move this to client?
186 void FOG_registercvars(void)
188 if (gamemode == GAME_NEHAHRA)
190 Cvar_RegisterVariable (&gl_fogenable);
191 Cvar_RegisterVariable (&gl_fogdensity);
192 Cvar_RegisterVariable (&gl_fogred);
193 Cvar_RegisterVariable (&gl_foggreen);
194 Cvar_RegisterVariable (&gl_fogblue);
195 Cvar_RegisterVariable (&gl_fogstart);
196 Cvar_RegisterVariable (&gl_fogend);
200 void gl_main_start(void)
204 void gl_main_shutdown(void)
208 extern void CL_ParseEntityLump(char *entitystring);
209 void gl_main_newmap(void)
211 if (cl.worldmodel && cl.worldmodel->entities)
212 CL_ParseEntityLump(cl.worldmodel->entities);
216 void GL_Main_Init(void)
218 Matrix4x4_CreateIdentity(&r_identitymatrix);
219 // FIXME: move this to client?
221 Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
222 Cvar_RegisterVariable (&r_drawentities);
223 Cvar_RegisterVariable (&r_drawviewmodel);
224 Cvar_RegisterVariable (&r_shadows);
225 Cvar_RegisterVariable (&r_shadow_staticworldlights);
226 Cvar_RegisterVariable (&r_speeds);
227 Cvar_RegisterVariable (&r_fullbrights);
228 Cvar_RegisterVariable (&r_wateralpha);
229 Cvar_RegisterVariable (&r_dynamic);
230 Cvar_RegisterVariable (&r_fullbright);
231 Cvar_RegisterVariable (&r_textureunits);
232 Cvar_RegisterVariable (&r_shadow_cull);
233 if (gamemode == GAME_NEHAHRA || gamemode == GAME_NEXIUZ)
234 Cvar_SetValue("r_fullbrights", 0);
235 R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
238 vec3_t r_farclip_origin;
239 vec3_t r_farclip_direction;
240 vec_t r_farclip_directiondist;
241 vec_t r_farclip_meshfarclip;
242 int r_farclip_directionbit0;
243 int r_farclip_directionbit1;
244 int r_farclip_directionbit2;
246 // start a farclip measuring session
247 void R_FarClip_Start(vec3_t origin, vec3_t direction, vec_t startfarclip)
249 VectorCopy(origin, r_farclip_origin);
250 VectorCopy(direction, r_farclip_direction);
251 r_farclip_directiondist = DotProduct(r_farclip_origin, r_farclip_direction);
252 r_farclip_directionbit0 = r_farclip_direction[0] < 0;
253 r_farclip_directionbit1 = r_farclip_direction[1] < 0;
254 r_farclip_directionbit2 = r_farclip_direction[2] < 0;
255 r_farclip_meshfarclip = r_farclip_directiondist + startfarclip;
258 // enlarge farclip to accomodate box
259 void R_FarClip_Box(vec3_t mins, vec3_t maxs)
262 d = (r_farclip_directionbit0 ? mins[0] : maxs[0]) * r_farclip_direction[0]
263 + (r_farclip_directionbit1 ? mins[1] : maxs[1]) * r_farclip_direction[1]
264 + (r_farclip_directionbit2 ? mins[2] : maxs[2]) * r_farclip_direction[2];
265 if (r_farclip_meshfarclip < d)
266 r_farclip_meshfarclip = d;
269 // return farclip value
270 float R_FarClip_Finish(void)
272 return r_farclip_meshfarclip - r_farclip_directiondist;
285 extern void R_Textures_Init(void);
286 extern void Mod_RenderInit(void);
287 extern void GL_Draw_Init(void);
288 extern void GL_Main_Init(void);
289 extern void R_Shadow_Init(void);
290 extern void GL_Models_Init(void);
291 extern void R_Sky_Init(void);
292 extern void GL_Surf_Init(void);
293 extern void R_Crosshairs_Init(void);
294 extern void R_Light_Init(void);
295 extern void R_Particles_Init(void);
296 extern void R_Explosion_Init(void);
297 extern void ui_init(void);
298 extern void gl_backend_init(void);
299 extern void Sbar_Init(void);
301 void Render_Init(void)
326 extern char *ENGINE_EXTENSIONS;
329 VID_CheckExtensions();
331 // LordHavoc: report supported extensions
332 Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
335 int R_CullBox(const vec3_t mins, const vec3_t maxs)
339 for (i = 0;i < 4;i++)
346 if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist)
350 if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist)
354 if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist)
358 if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist)
362 if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist)
366 if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist)
370 if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist)
374 if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist)
382 int PVS_CullBox(const vec3_t mins, const vec3_t maxs)
385 mnode_t *node, *stack[4096];
386 if (cl.worldmodel == NULL)
389 stack[stackpos++] = cl.worldmodel->nodes;
392 node = stack[--stackpos];
393 if (node->contents < 0)
395 if (((mleaf_t *)node)->pvsframe == cl.worldmodel->pvsframecount)
400 sides = BoxOnPlaneSide(mins, maxs, node->plane);
401 if (sides & 2 && stackpos < 4096)
402 stack[stackpos++] = node->children[1];
403 if (sides & 1 && stackpos < 4096)
404 stack[stackpos++] = node->children[0];
410 int VIS_CullBox(const vec3_t mins, const vec3_t maxs)
413 mnode_t *node, *stack[4096];
414 if (R_CullBox(mins, maxs))
416 if (cl.worldmodel == NULL)
419 stack[stackpos++] = cl.worldmodel->nodes;
422 node = stack[--stackpos];
423 if (node->contents < 0)
425 if (((mleaf_t *)node)->visframe == r_framecount)
430 sides = BoxOnPlaneSide(mins, maxs, node->plane);
431 if (sides & 2 && stackpos < 4096)
432 stack[stackpos++] = node->children[1];
433 if (sides & 1 && stackpos < 4096)
434 stack[stackpos++] = node->children[0];
440 int R_CullSphere(const vec3_t origin, vec_t radius)
442 return (DotProduct(frustum[0].normal, origin) + radius < frustum[0].dist
443 || DotProduct(frustum[1].normal, origin) + radius < frustum[1].dist
444 || DotProduct(frustum[2].normal, origin) + radius < frustum[2].dist
445 || DotProduct(frustum[3].normal, origin) + radius < frustum[3].dist);
448 int PVS_CullSphere(const vec3_t origin, vec_t radius)
451 mnode_t *node, *stack[4096];
453 if (cl.worldmodel == NULL)
456 stack[stackpos++] = cl.worldmodel->nodes;
459 node = stack[--stackpos];
460 if (node->contents < 0)
462 if (((mleaf_t *)node)->pvsframe == cl.worldmodel->pvsframecount)
467 dist = PlaneDiff(origin, node->plane);
469 stack[stackpos++] = node->children[1];
471 stack[stackpos++] = node->children[0];
477 int VIS_CullSphere(const vec3_t origin, vec_t radius)
480 mnode_t *node, *stack[4096];
482 if (R_CullSphere(origin, radius))
484 if (cl.worldmodel == NULL)
487 stack[stackpos++] = cl.worldmodel->nodes;
490 node = stack[--stackpos];
491 if (node->contents < 0)
493 if (((mleaf_t *)node)->visframe == r_framecount)
498 dist = PlaneDiff(origin, node->plane);
500 stack[stackpos++] = node->children[1];
502 stack[stackpos++] = node->children[0];
509 //==================================================================================
511 static void R_MarkEntities (void)
515 entity_render_t *ent;
517 ent = &cl_entities[0].render;
518 Matrix4x4_CreateIdentity(&ent->matrix);
519 Matrix4x4_CreateIdentity(&ent->inversematrix);
522 R_FarClip_Box(cl.worldmodel->normalmins, cl.worldmodel->normalmaxs);
524 if (!r_drawentities.integer)
527 for (i = 0;i < r_refdef.numentities;i++)
529 ent = r_refdef.entities[i];
530 Mod_CheckLoaded(ent->model);
532 // move view-relative models to where they should be
533 if (ent->flags & RENDER_VIEWMODEL)
535 // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
536 ent->flags -= RENDER_VIEWMODEL;
538 VectorCopy(ent->origin, v);
539 ent->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
540 ent->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
541 ent->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
543 VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
546 VectorCopy(ent->angles, v);
547 if (!ent->model || ent->model->type != mod_brush)
549 Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], v[0], v[1], v[2], ent->scale);
550 Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
551 R_LerpAnimation(ent);
552 R_UpdateEntLights(ent);
553 if ((chase_active.integer || !(ent->flags & RENDER_EXTERIORMODEL))
554 && !VIS_CullSphere(ent->origin, (ent->model != NULL ? ent->model->radius : 16) * ent->scale)
555 && !VIS_CullBox(ent->mins, ent->maxs))
557 ent->visframe = r_framecount;
558 R_FarClip_Box(ent->mins, ent->maxs);
563 // only used if skyrendermasked, and normally returns false
564 int R_DrawBrushModelsSky (void)
567 entity_render_t *ent;
569 if (!r_drawentities.integer)
573 for (i = 0;i < r_refdef.numentities;i++)
575 ent = r_refdef.entities[i];
576 if (ent->visframe == r_framecount && ent->model && ent->model->DrawSky)
578 ent->model->DrawSky(ent);
591 void R_DrawViewModel (void)
593 entity_render_t *ent;
595 // FIXME: move these checks to client
596 if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
599 ent = &cl.viewent.render;
600 Mod_CheckLoaded(ent->model);
601 R_LerpAnimation(ent);
602 Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], -ent->angles[0], ent->angles[1], ent->angles[2], ent->scale);
603 Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
604 R_UpdateEntLights(ent);
605 ent->model->Draw(ent);
609 void R_DrawNoModel(entity_render_t *ent);
613 entity_render_t *ent;
615 if (!r_drawentities.integer)
618 for (i = 0;i < r_refdef.numentities;i++)
620 ent = r_refdef.entities[i];
621 if (ent->visframe == r_framecount)
623 if (ent->model && ent->model->Draw != NULL)
624 ent->model->Draw(ent);
631 void R_DrawFakeShadows (void)
634 entity_render_t *ent;
636 ent = &cl_entities[0].render;
637 if (ent->model && ent->model->DrawFakeShadow)
638 ent->model->DrawFakeShadow(ent);
640 if (!r_drawentities.integer)
642 for (i = 0;i < r_refdef.numentities;i++)
644 ent = r_refdef.entities[i];
645 if ((ent->flags & RENDER_SHADOW) && ent->model && ent->model->DrawFakeShadow)
646 ent->model->DrawFakeShadow(ent);
650 #include "r_shadow.h"
652 int shadowframecount = 0;
654 int Light_CullBox(const vec3_t mins, const vec3_t maxs)
657 mnode_t *node, *stack[4096];
658 if (cl.worldmodel == NULL)
661 stack[stackpos++] = cl.worldmodel->nodes;
664 node = stack[--stackpos];
665 if (node->contents < 0)
667 if (((mleaf_t *)node)->worldnodeframe == shadowframecount)
672 sides = BoxOnPlaneSide(mins, maxs, node->plane);
673 if (sides & 2 && stackpos < 4096)
674 stack[stackpos++] = node->children[1];
675 if (sides & 1 && stackpos < 4096)
676 stack[stackpos++] = node->children[0];
682 int LightAndVis_CullBox(const vec3_t mins, const vec3_t maxs)
685 mnode_t *node, *stack[4096];
686 if (R_CullBox(mins, maxs))
688 if (cl.worldmodel == NULL)
691 stack[stackpos++] = cl.worldmodel->nodes;
694 node = stack[--stackpos];
695 if (node->contents < 0)
697 if (((mleaf_t *)node)->visframe == r_framecount && ((mleaf_t *)node)->worldnodeframe == shadowframecount)
702 sides = BoxOnPlaneSide(mins, maxs, node->plane);
703 if (sides & 2 && stackpos < 4096)
704 stack[stackpos++] = node->children[1];
705 if (sides & 1 && stackpos < 4096)
706 stack[stackpos++] = node->children[0];
712 int LightAndVis_CullPointCloud(int numpoints, const float *points)
717 mnode_t *node, *stack[4096];
718 //if (R_CullBox(mins, maxs))
720 if (cl.worldmodel == NULL)
723 stack[stackpos++] = cl.worldmodel->nodes;
726 node = stack[--stackpos];
727 if (node->contents < 0)
729 if (((mleaf_t *)node)->visframe == r_framecount && ((mleaf_t *)node)->worldnodeframe == shadowframecount)
735 for (i = 0, p = points;i < numpoints && sides != 3;i++, p += 3)
737 if (DotProduct(p, node->plane->normal) < node->plane->dist)
742 if (sides & 2 && stackpos < 4096)
743 stack[stackpos++] = node->children[1];
744 if (sides & 1 && stackpos < 4096)
745 stack[stackpos++] = node->children[0];
752 void R_TestAndDrawShadowVolume(entity_render_t *ent, vec3_t lightorigin, float cullradius, float lightradius, vec3_t lightmins, vec3_t lightmaxs, vec3_t clipmins, vec3_t clipmaxs)
754 vec3_t relativelightorigin;
758 float dist, projectdistance;
762 if (!(ent->flags & RENDER_SHADOW) || ent->model == NULL || ent->model->DrawShadowVolume == NULL)
764 if (r_shadow_cull.integer)
766 if (ent->maxs[0] < lightmins[0] || ent->mins[0] > lightmaxs[0]
767 || ent->maxs[1] < lightmins[1] || ent->mins[1] > lightmaxs[1]
768 || ent->maxs[2] < lightmins[2] || ent->mins[2] > lightmaxs[2]
769 || Light_CullBox(ent->mins, ent->maxs))
773 if (r_shadow_cull.integer)
775 projectdistance = cullradius;
776 // calculate projected bounding box and decide if it is on-screen
777 for (i = 0;i < 8;i++)
779 temp[0] = i & 1 ? ent->model->normalmaxs[0] : ent->model->normalmins[0];
780 temp[1] = i & 2 ? ent->model->normalmaxs[1] : ent->model->normalmins[1];
781 temp[2] = i & 4 ? ent->model->normalmaxs[2] : ent->model->normalmins[2];
782 Matrix4x4_Transform(&ent->matrix, temp, points[i]);
783 VectorSubtract(points[i], lightorigin, temp);
784 dist = projectdistance / sqrt(DotProduct(temp, temp));
785 VectorMA(points[i], dist, temp, points[i+8]);
787 if (LightAndVis_CullPointCloud(16, points[0]))
790 for (i = 0;i < 8;i++)
792 p2[0] = i & 1 ? ent->model->normalmaxs[0] : ent->model->normalmins[0];
793 p2[1] = i & 2 ? ent->model->normalmaxs[1] : ent->model->normalmins[1];
794 p2[2] = i & 4 ? ent->model->normalmaxs[2] : ent->model->normalmins[2];
795 Matrix4x4_Transform(&ent->matrix, p2, p);
796 VectorSubtract(p, lightorigin, temp);
797 dist = projectdistance / sqrt(DotProduct(temp, temp));
798 VectorMA(p, dist, temp, p2);
801 if (mins[0] > p[0]) mins[0] = p[0];if (maxs[0] < p[0]) maxs[0] = p[0];
802 if (mins[1] > p[1]) mins[1] = p[1];if (maxs[1] < p[1]) maxs[1] = p[1];
803 if (mins[2] > p[2]) mins[2] = p[2];if (maxs[2] < p[2]) maxs[2] = p[2];
810 if (mins[0] > p2[0]) mins[0] = p2[0];if (maxs[0] < p2[0]) maxs[0] = p2[0];
811 if (mins[1] > p2[1]) mins[1] = p2[1];if (maxs[1] < p2[1]) maxs[1] = p2[1];
812 if (mins[2] > p2[2]) mins[2] = p2[2];if (maxs[2] < p2[2]) maxs[2] = p2[2];
814 if (mins[0] >= clipmaxs[0] || maxs[0] <= clipmins[0]
815 || mins[1] >= clipmaxs[1] || maxs[1] <= clipmins[1]
816 || mins[2] >= clipmaxs[2] || maxs[2] <= clipmins[2]
817 || LightAndVis_CullBox(mins, maxs))
822 Matrix4x4_Transform(&ent->inversematrix, lightorigin, relativelightorigin);
823 ent->model->DrawShadowVolume (ent, relativelightorigin, lightradius);
826 void R_Shadow_DrawWorldLightShadowVolume(matrix4x4_t *matrix, worldlight_t *light);
828 extern 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);
829 void R_ShadowVolumeLighting (int visiblevolumes)
832 entity_render_t *ent;
834 float f, lightradius, cullradius;
835 vec3_t relativelightorigin, relativeeyeorigin, lightcolor, clipmins, clipmaxs;
841 matrix4x4_t matrix_worldtofilter, matrix_worldtoattenuationxyz, matrix_worldtoattenuationz;
842 matrix4x4_t matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz;
846 memset(&m, 0, sizeof(m));
847 m.blendfunc1 = GL_ONE;
848 m.blendfunc2 = GL_ONE;
849 if (r_shadow_realtime.integer >= 3)
850 m.depthdisable = true;
852 qglDisable(GL_CULL_FACE);
853 GL_Color(0.0 * r_colorscale, 0.0125 * r_colorscale, 0.1 * r_colorscale, 1);
856 R_Shadow_Stage_Begin();
858 for (lnum = 0, wl = r_shadow_worldlightchain;wl;wl = wl->next, lnum++)
860 if (d_lightstylevalue[wl->style] <= 0)
862 if (R_CullBox(wl->mins, wl->maxs))
863 //if (R_CullSphere(wl->origin, cullradius))
865 //if (R_CullBox(wl->mins, wl->maxs) || R_CullSphere(wl->origin, lightradius))
867 //if (VIS_CullBox(wl->mins, wl->maxs) || VIS_CullSphere(wl->origin, lightradius))
869 if (r_shadow_debuglight.integer >= 0 && lnum != r_shadow_debuglight.integer)
872 cullradius = wl->cullradius;
873 lightradius = wl->lightradius;
875 if (cl.worldmodel != NULL)
877 for (i = 0;i < wl->numleafs;i++)
878 if (wl->leafs[i]->visframe == r_framecount)
880 if (i == wl->numleafs)
882 leaf = wl->leafs[i++];
883 VectorCopy(leaf->mins, clipmins);
884 VectorCopy(leaf->maxs, clipmaxs);
885 for (;i < wl->numleafs;i++)
888 if (leaf->visframe == r_framecount)
890 if (clipmins[0] > leaf->mins[0]) clipmins[0] = leaf->mins[0];
891 if (clipmaxs[0] < leaf->maxs[0]) clipmaxs[0] = leaf->maxs[0];
892 if (clipmins[1] > leaf->mins[1]) clipmins[1] = leaf->mins[1];
893 if (clipmaxs[1] < leaf->maxs[1]) clipmaxs[1] = leaf->maxs[1];
894 if (clipmins[2] > leaf->mins[2]) clipmins[2] = leaf->mins[2];
895 if (clipmaxs[2] < leaf->maxs[2]) clipmaxs[2] = leaf->maxs[2];
898 if (clipmins[0] < wl->mins[0]) clipmins[0] = wl->mins[0];
899 if (clipmaxs[0] > wl->maxs[0]) clipmaxs[0] = wl->maxs[0];
900 if (clipmins[1] < wl->mins[1]) clipmins[1] = wl->mins[1];
901 if (clipmaxs[1] > wl->maxs[1]) clipmaxs[1] = wl->maxs[1];
902 if (clipmins[2] < wl->mins[2]) clipmins[2] = wl->mins[2];
903 if (clipmaxs[2] > wl->maxs[2]) clipmaxs[2] = wl->maxs[2];
907 VectorCopy(wl->mins, clipmins);
908 VectorCopy(wl->maxs, clipmaxs);
911 //if (R_Shadow_ScissorForBBoxAndSphere(clipmins, clipmaxs, wl->origin, wl->cullradius))
912 if (R_CullBox(clipmins, clipmaxs) || R_Shadow_ScissorForBBox(clipmins, clipmaxs))
915 // mark the leafs we care about so only things in those leafs will matter
916 if (cl.worldmodel != NULL)
917 for (i = 0;i < wl->numleafs;i++)
918 wl->leafs[i]->worldnodeframe = shadowframecount;
920 f = d_lightstylevalue[wl->style] * (1.0f / 256.0f);
921 VectorScale(wl->light, f, lightcolor);
924 f = 2 + sin(realtime * M_PI * 4.0);
925 VectorScale(lightcolor, f, lightcolor);
931 R_Shadow_Stage_ShadowVolumes();
932 ent = &cl_entities[0].render;
933 if (wl->shadowvolume && r_shadow_staticworldlights.integer)
934 R_Shadow_DrawWorldLightShadowVolume(&ent->matrix, wl);
936 R_TestAndDrawShadowVolume(ent, wl->origin, cullradius, lightradius, wl->mins, wl->maxs, clipmins, clipmaxs);
937 if (r_drawentities.integer)
938 for (i = 0;i < r_refdef.numentities;i++)
939 R_TestAndDrawShadowVolume(r_refdef.entities[i], wl->origin, cullradius, lightradius, wl->mins, wl->maxs, clipmins, clipmaxs);
945 R_Shadow_Stage_LightWithShadows();
947 R_Shadow_Stage_LightWithoutShadows();
949 // calculate world to filter matrix
950 Matrix4x4_CreateFromQuakeEntity(&matrix, wl->origin[0], wl->origin[1], wl->origin[2], wl->angles[0], wl->angles[1], wl->angles[2], lightradius);
951 Matrix4x4_Invert_Simple(&matrix_worldtofilter, &matrix);
952 // calculate world to attenuationxyz/xy matrix
953 Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5, 0.5, 0.5, 0, 0, 0, 0.5);
954 Matrix4x4_Concat(&matrix_worldtoattenuationxyz, &matrix, &matrix_worldtofilter);
955 // calculate world to attenuationz matrix
956 matrix.m[0][0] = 0;matrix.m[0][1] = 0;matrix.m[0][2] = 0.5;matrix.m[0][3] = 0.5;
957 matrix.m[1][0] = 0;matrix.m[1][1] = 0;matrix.m[1][2] = 0 ;matrix.m[1][3] = 0.5;
958 matrix.m[2][0] = 0;matrix.m[2][1] = 0;matrix.m[2][2] = 0 ;matrix.m[2][3] = 0.5;
959 matrix.m[3][0] = 0;matrix.m[3][1] = 0;matrix.m[3][2] = 0 ;matrix.m[3][3] = 1;
960 Matrix4x4_Concat(&matrix_worldtoattenuationz, &matrix, &matrix_worldtofilter);
962 ent = &cl_entities[0].render;
963 if (ent->model && ent->model->DrawLight)
965 Matrix4x4_Transform(&ent->inversematrix, wl->origin, relativelightorigin);
966 Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
967 Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
968 Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
969 Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
971 R_Model_Brush_DrawLightForSurfaceList(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, wl->surfaces, wl->numsurfaces, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
973 ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
975 if (r_drawentities.integer)
977 for (i = 0;i < r_refdef.numentities;i++)
979 ent = r_refdef.entities[i];
980 if (ent->visframe == r_framecount && ent->model && ent->model->DrawLight
981 && ent->maxs[0] >= clipmins[0] && ent->mins[0] <= clipmaxs[0]
982 && ent->maxs[1] >= clipmins[1] && ent->mins[1] <= clipmaxs[1]
983 && ent->maxs[2] >= clipmins[2] && ent->mins[2] <= clipmaxs[2]
984 && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
986 Matrix4x4_Transform(&ent->inversematrix, wl->origin, relativelightorigin);
987 Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
988 Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
989 Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
990 Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
991 ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
997 for (lnum = 0, rd = r_dlight;lnum < r_numdlights;lnum++, rd++)
999 lightradius = rd->cullradius;
1000 clipmins[0] = rd->origin[0] - lightradius;
1001 clipmins[1] = rd->origin[1] - lightradius;
1002 clipmins[2] = rd->origin[2] - lightradius;
1003 clipmaxs[0] = rd->origin[0] + lightradius;
1004 clipmaxs[1] = rd->origin[1] + lightradius;
1005 clipmaxs[2] = rd->origin[2] + lightradius;
1006 if (VIS_CullBox(clipmins, clipmaxs))
1009 //if (R_Shadow_ScissorForBBoxAndSphere(clipmins, clipmaxs, rd->origin, cullradius))
1010 if (R_Shadow_ScissorForBBox(clipmins, clipmaxs))
1013 if (!visiblevolumes)
1014 R_Shadow_Stage_ShadowVolumes();
1016 cullradius = RadiusFromBoundsAndOrigin(clipmins, clipmaxs, rd->origin);
1017 VectorScale(rd->light, (1.0f / 4096.0f), lightcolor);
1019 ent = &cl_entities[0].render;
1020 R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs, clipmins, clipmaxs);
1021 if (r_drawentities.integer)
1023 for (i = 0;i < r_refdef.numentities;i++)
1025 ent = r_refdef.entities[i];
1027 R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs, clipmins, clipmaxs);
1031 if (!visiblevolumes)
1033 R_Shadow_Stage_LightWithShadows();
1035 // calculate world to filter matrix
1036 Matrix4x4_CreateFromQuakeEntity(&matrix, rd->origin[0], rd->origin[1], rd->origin[2], 0, 0, 0, lightradius);
1037 Matrix4x4_Invert_Simple(&matrix_worldtofilter, &matrix);
1038 // calculate world to attenuationxyz/xy matrix
1039 Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5, 0.5, 0.5, 0, 0, 0, 0.5);
1040 Matrix4x4_Concat(&matrix_worldtoattenuationxyz, &matrix, &matrix_worldtofilter);
1041 // calculate world to attenuationz matrix
1042 matrix.m[0][0] = 0;matrix.m[0][1] = 0;matrix.m[0][2] = 0.5;matrix.m[0][3] = 0.5;
1043 matrix.m[1][0] = 0;matrix.m[1][1] = 0;matrix.m[1][2] = 0 ;matrix.m[1][3] = 0.5;
1044 matrix.m[2][0] = 0;matrix.m[2][1] = 0;matrix.m[2][2] = 0 ;matrix.m[2][3] = 0.5;
1045 matrix.m[3][0] = 0;matrix.m[3][1] = 0;matrix.m[3][2] = 0 ;matrix.m[3][3] = 1;
1046 Matrix4x4_Concat(&matrix_worldtoattenuationz, &matrix, &matrix_worldtofilter);
1048 ent = &cl_entities[0].render;
1049 if (ent->model && ent->model->DrawLight)
1051 Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
1052 Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
1053 Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
1054 Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
1055 Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
1056 ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
1058 if (r_drawentities.integer)
1060 for (i = 0;i < r_refdef.numentities;i++)
1062 ent = r_refdef.entities[i];
1063 if (ent->visframe == r_framecount && ent->model && ent->model->DrawLight
1064 && ent->maxs[0] >= clipmins[0] && ent->mins[0] <= clipmaxs[0]
1065 && ent->maxs[1] >= clipmins[1] && ent->mins[1] <= clipmaxs[1]
1066 && ent->maxs[2] >= clipmins[2] && ent->mins[2] <= clipmaxs[2]
1067 && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
1069 Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
1070 Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
1071 Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
1072 Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
1073 Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
1074 ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
1081 if (!visiblevolumes)
1082 R_Shadow_Stage_End();
1083 qglEnable(GL_CULL_FACE);
1084 qglDisable(GL_SCISSOR_TEST);
1087 static void R_SetFrustum (void)
1089 // LordHavoc: note to all quake engine coders, the special case for 90
1090 // degrees assumed a square view (wrong), so I removed it, Quake2 has it
1091 // disabled as well.
1093 // rotate VPN right by FOV_X/2 degrees
1094 RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
1095 frustum[0].dist = DotProduct (r_origin, frustum[0].normal);
1096 PlaneClassify(&frustum[0]);
1098 // rotate VPN left by FOV_X/2 degrees
1099 RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
1100 frustum[1].dist = DotProduct (r_origin, frustum[1].normal);
1101 PlaneClassify(&frustum[1]);
1103 // rotate VPN up by FOV_X/2 degrees
1104 RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
1105 frustum[2].dist = DotProduct (r_origin, frustum[2].normal);
1106 PlaneClassify(&frustum[2]);
1108 // rotate VPN down by FOV_X/2 degrees
1109 RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
1110 frustum[3].dist = DotProduct (r_origin, frustum[3].normal);
1111 PlaneClassify(&frustum[3]);
1119 static void R_SetupFrame (void)
1121 // don't allow cheats in multiplayer
1122 if (cl.maxclients > 1)
1124 if (r_fullbright.integer != 0)
1125 Cvar_Set ("r_fullbright", "0");
1126 if (r_ambient.value != 0)
1127 Cvar_Set ("r_ambient", "0");
1132 // build the transformation matrix for the given view angles
1133 VectorCopy (r_refdef.vieworg, r_origin);
1135 AngleVectors (r_refdef.viewangles, vpn, vright, vup);
1141 static void R_BlendView(void)
1146 if (r_refdef.viewblend[3] < 0.01f)
1149 memset(&m, 0, sizeof(m));
1150 m.blendfunc1 = GL_SRC_ALPHA;
1151 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
1152 m.depthdisable = true; // magic
1153 R_Mesh_Matrix(&r_identitymatrix);
1157 varray_vertex[0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
1158 varray_vertex[1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
1159 varray_vertex[2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
1161 varray_vertex[4] = varray_vertex[0] + vup[0] * r;
1162 varray_vertex[5] = varray_vertex[1] + vup[1] * r;
1163 varray_vertex[6] = varray_vertex[2] + vup[2] * r;
1164 varray_vertex[8] = varray_vertex[0] + vright[0] * r;
1165 varray_vertex[9] = varray_vertex[1] + vright[1] * r;
1166 varray_vertex[10] = varray_vertex[2] + vright[2] * r;
1167 GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
1168 R_Mesh_Draw(3, 1, polygonelements);
1175 r_refdef must be set before the first call
1178 extern void R_DrawLightningBeams (void);
1179 void R_RenderView (void)
1181 entity_render_t *world;
1182 if (!r_refdef.entities/* || !cl.worldmodel*/)
1183 return; //Host_Error ("R_RenderView: NULL worldmodel");
1185 if (r_shadow_realtime.integer == 1)
1187 if (!gl_texturecubemap)
1189 Con_Printf("Cubemap texture support not detected, turning off r_shadow_realtime\n");
1190 Cvar_SetValueQuick(&r_shadow_realtime, 0);
1192 else if (!gl_dot3arb)
1194 Con_Printf("Bumpmapping support not detected, turning off r_shadow_realtime\n");
1195 Cvar_SetValueQuick(&r_shadow_realtime, 0);
1197 else if (!gl_stencil)
1199 Con_Printf("Stencil not enabled, turning off r_shadow_realtime, please type vid_stencil 1;vid_bitsperpixel 32;vid_restart and try again\n");
1200 Cvar_SetValueQuick(&r_shadow_realtime, 0);
1202 else if (!gl_combine.integer)
1204 Con_Printf("Combine disabled, please turn on gl_combine, turning off r_shadow_realtime\n");
1205 Cvar_SetValueQuick(&r_shadow_realtime, 0);
1209 R_Shadow_UpdateLightingMode();
1211 world = &cl_entities[0].render;
1213 // FIXME: move to client
1215 R_TimeReport("mexplosion");
1223 R_TimeReport("setup");
1225 R_WorldVisibility(world);
1226 R_TimeReport("worldvis");
1228 R_FarClip_Start(r_origin, vpn, 768.0f);
1230 r_farclip = R_FarClip_Finish() + 256.0f;
1231 R_TimeReport("markentity");
1233 GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
1234 if (r_shadow_lightingmode > 0)
1235 GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.fov_x, r_refdef.fov_y, 1.0f);
1237 GL_SetupView_Mode_Perspective(r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
1238 GL_SetupView_Orientation_FromEntity (r_refdef.vieworg, r_refdef.viewangles);
1239 qglDepthFunc(GL_LEQUAL);
1242 R_MeshQueue_BeginScene();
1244 R_Shadow_UpdateWorldLightSelection();
1246 if (R_DrawBrushModelsSky())
1247 R_TimeReport("bmodelsky");
1249 // must occur early because it can draw sky
1251 R_TimeReport("world");
1253 // don't let sound skip if going slow
1254 if (!intimerefresh && !r_speeds.integer)
1257 R_DrawModels(r_shadow_lightingmode > 0);
1258 R_TimeReport("models");
1260 if (r_shadows.integer == 1 && r_shadow_lightingmode <= 0)
1262 R_DrawFakeShadows();
1263 R_TimeReport("fakeshadow");
1266 if (r_shadow_lightingmode > 0)
1268 R_ShadowVolumeLighting(false);
1269 R_TimeReport("dynlight");
1272 R_DrawLightningBeams();
1273 R_TimeReport("lightning");
1276 R_TimeReport("particles");
1279 R_TimeReport("explosions");
1281 R_MeshQueue_RenderTransparent();
1282 R_TimeReport("drawtrans");
1285 R_TimeReport("coronas");
1287 R_DrawWorldCrosshair();
1288 R_TimeReport("crosshair");
1291 R_TimeReport("blendview");
1293 R_MeshQueue_Render();
1294 R_MeshQueue_EndScene();
1295 if (r_shadow_realtime.integer >= 2)
1297 R_ShadowVolumeLighting(true);
1298 R_TimeReport("shadowvolume");
1301 R_TimeReport("meshfinish");
1305 void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
1308 float *v, *c, f1, f2, diff[3];
1310 m.blendfunc1 = GL_SRC_ALPHA;
1311 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
1312 R_Mesh_Matrix(&r_identitymatrix);
1315 varray_vertex[ 0] = mins[0];varray_vertex[ 1] = mins[1];varray_vertex[ 2] = mins[2];
1316 varray_vertex[ 4] = maxs[0];varray_vertex[ 5] = mins[1];varray_vertex[ 6] = mins[2];
1317 varray_vertex[ 8] = mins[0];varray_vertex[ 9] = maxs[1];varray_vertex[10] = mins[2];
1318 varray_vertex[12] = maxs[0];varray_vertex[13] = maxs[1];varray_vertex[14] = mins[2];
1319 varray_vertex[16] = mins[0];varray_vertex[17] = mins[1];varray_vertex[18] = maxs[2];
1320 varray_vertex[20] = maxs[0];varray_vertex[21] = mins[1];varray_vertex[22] = maxs[2];
1321 varray_vertex[24] = mins[0];varray_vertex[25] = maxs[1];varray_vertex[26] = maxs[2];
1322 varray_vertex[28] = maxs[0];varray_vertex[29] = maxs[1];varray_vertex[30] = maxs[2];
1323 R_FillColors(varray_color, 8, cr * r_colorscale, cg * r_colorscale, cb * r_colorscale, ca);
1326 for (i = 0, v = varray_vertex, c = varray_color;i < 8;i++, v += 4, c += 4)
1328 VectorSubtract(v, r_origin, diff);
1329 f2 = exp(fogdensity/DotProduct(diff, diff));
1332 c[0] = c[0] * f1 + fogcolor[0] * f2;
1333 c[1] = c[1] * f1 + fogcolor[1] * f2;
1334 c[2] = c[2] * f1 + fogcolor[2] * f2;
1342 void R_DrawNoModelCallback(const void *calldata1, int calldata2)
1344 const entity_render_t *ent = calldata1;
1346 float f1, f2, *c, diff[3];
1348 memset(&m, 0, sizeof(m));
1349 if (ent->flags & EF_ADDITIVE)
1351 m.blendfunc1 = GL_SRC_ALPHA;
1352 m.blendfunc2 = GL_ONE;
1354 else if (ent->alpha < 1)
1356 m.blendfunc1 = GL_SRC_ALPHA;
1357 m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
1361 m.blendfunc1 = GL_ONE;
1362 m.blendfunc2 = GL_ZERO;
1364 R_Mesh_Matrix(&ent->matrix);
1367 element[ 0] = 5;element[ 1] = 2;element[ 2] = 0;
1368 element[ 3] = 5;element[ 4] = 1;element[ 5] = 2;
1369 element[ 6] = 5;element[ 7] = 0;element[ 8] = 3;
1370 element[ 9] = 5;element[10] = 3;element[11] = 1;
1371 element[12] = 0;element[13] = 2;element[14] = 4;
1372 element[15] = 2;element[16] = 1;element[17] = 4;
1373 element[18] = 3;element[19] = 0;element[20] = 4;
1374 element[21] = 1;element[22] = 3;element[23] = 4;
1375 varray_vertex[ 0] = -16;varray_vertex[ 1] = 0;varray_vertex[ 2] = 0;
1376 varray_vertex[ 4] = 16;varray_vertex[ 5] = 0;varray_vertex[ 6] = 0;
1377 varray_vertex[ 8] = 0;varray_vertex[ 9] = -16;varray_vertex[10] = 0;
1378 varray_vertex[12] = 0;varray_vertex[13] = 16;varray_vertex[14] = 0;
1379 varray_vertex[16] = 0;varray_vertex[17] = 0;varray_vertex[18] = -16;
1380 varray_vertex[20] = 0;varray_vertex[21] = 0;varray_vertex[22] = 16;
1381 varray_color[ 0] = 0.00f * r_colorscale;varray_color[ 1] = 0.00f * r_colorscale;varray_color[ 2] = 0.50f * r_colorscale;varray_color[ 3] = ent->alpha;
1382 varray_color[ 4] = 0.00f * r_colorscale;varray_color[ 5] = 0.00f * r_colorscale;varray_color[ 6] = 0.50f * r_colorscale;varray_color[ 7] = ent->alpha;
1383 varray_color[ 8] = 0.00f * r_colorscale;varray_color[ 9] = 0.50f * r_colorscale;varray_color[10] = 0.00f * r_colorscale;varray_color[11] = ent->alpha;
1384 varray_color[12] = 0.00f * r_colorscale;varray_color[13] = 0.50f * r_colorscale;varray_color[14] = 0.00f * r_colorscale;varray_color[15] = ent->alpha;
1385 varray_color[16] = 0.50f * r_colorscale;varray_color[17] = 0.00f * r_colorscale;varray_color[18] = 0.00f * r_colorscale;varray_color[19] = ent->alpha;
1386 varray_color[20] = 0.50f * r_colorscale;varray_color[21] = 0.00f * r_colorscale;varray_color[22] = 0.00f * r_colorscale;varray_color[23] = ent->alpha;
1389 VectorSubtract(ent->origin, r_origin, diff);
1390 f2 = exp(fogdensity/DotProduct(diff, diff));
1392 for (i = 0, c = varray_color;i < 6;i++, c += 4)
1394 c[0] = (c[0] * f1 + fogcolor[0] * f2) * r_colorscale;
1395 c[1] = (c[1] * f1 + fogcolor[1] * f2) * r_colorscale;
1396 c[2] = (c[2] * f1 + fogcolor[2] * f2) * r_colorscale;
1401 for (i = 0, c = varray_color;i < 6;i++, c += 4)
1403 c[0] *= r_colorscale;
1404 c[1] *= r_colorscale;
1405 c[2] *= r_colorscale;
1409 R_Mesh_Draw(6, 8, element);
1412 void R_DrawNoModel(entity_render_t *ent)
1414 //if ((ent->effects & EF_ADDITIVE) || (ent->alpha < 1))
1415 R_MeshQueue_AddTransparent(ent->origin, R_DrawNoModelCallback, ent, 0);
1417 // R_DrawNoModelCallback(ent, 0);
1420 void R_CalcBeamVerts (float *vert, const vec3_t org1, const vec3_t org2, float width)
1422 vec3_t right1, right2, diff, normal;
1424 VectorSubtract (org2, org1, normal);
1425 VectorNormalizeFast (normal);
1427 // calculate 'right' vector for start
1428 VectorSubtract (r_origin, org1, diff);
1429 VectorNormalizeFast (diff);
1430 CrossProduct (normal, diff, right1);
1432 // calculate 'right' vector for end
1433 VectorSubtract (r_origin, org2, diff);
1434 VectorNormalizeFast (diff);
1435 CrossProduct (normal, diff, right2);
1437 vert[ 0] = org1[0] + width * right1[0];
1438 vert[ 1] = org1[1] + width * right1[1];
1439 vert[ 2] = org1[2] + width * right1[2];
1440 vert[ 4] = org1[0] - width * right1[0];
1441 vert[ 5] = org1[1] - width * right1[1];
1442 vert[ 6] = org1[2] - width * right1[2];
1443 vert[ 8] = org2[0] - width * right2[0];
1444 vert[ 9] = org2[1] - width * right2[1];
1445 vert[10] = org2[2] - width * right2[2];
1446 vert[12] = org2[0] + width * right2[0];
1447 vert[13] = org2[1] + width * right2[1];
1448 vert[14] = org2[2] + width * right2[2];