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.
23 #include "cl_collision.h"
26 cvar_t r_coronas = {CVAR_SAVE, "r_coronas", "1", "brightness of corona flare effects around certain lights, 0 disables corona effects"};
27 cvar_t gl_flashblend = {CVAR_SAVE, "gl_flashblend", "0", "render bright coronas for dynamic lights instead of actual lighting, fast but ugly"};
29 static rtexture_t *lightcorona;
30 static rtexturepool_t *lighttexturepool;
32 void r_light_start(void)
36 unsigned char pixels[32][32][4];
37 lighttexturepool = R_AllocTexturePool();
38 for (y = 0;y < 32;y++)
40 dy = (y - 15.5f) * (1.0f / 16.0f);
41 for (x = 0;x < 32;x++)
43 dx = (x - 15.5f) * (1.0f / 16.0f);
44 a = (int)(((1.0f / (dx * dx + dy * dy + 0.2f)) - (1.0f / (1.0f + 0.2))) * 32.0f / (1.0f / (1.0f + 0.2)));
49 pixels[y][x][3] = 255;
52 lightcorona = R_LoadTexture2D(lighttexturepool, "lightcorona", 32, 32, &pixels[0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
55 void r_light_shutdown(void)
57 lighttexturepool = NULL;
61 void r_light_newmap(void)
64 for (i = 0;i < 256;i++)
65 r_refdef.lightstylevalue[i] = 264; // normal light value
68 void R_Light_Init(void)
70 Cvar_RegisterVariable(&r_coronas);
71 Cvar_RegisterVariable(&gl_flashblend);
72 R_RegisterModule("R_Light", r_light_start, r_light_shutdown, r_light_newmap);
75 void R_DrawCoronas(void)
78 float cscale, scale, viewdist, dist;
80 if (r_coronas.value < 0.01)
82 R_Mesh_Matrix(&identitymatrix);
83 viewdist = DotProduct(r_vieworigin, r_viewforward);
84 flag = r_rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
85 for (lnum = 0, light = r_shadow_worldlightchain;light;light = light->next, lnum++)
87 if ((light->flags & flag) && light->corona * r_coronas.value > 0 && (r_shadow_debuglight.integer < 0 || r_shadow_debuglight.integer == lnum) && (dist = (DotProduct(light->rtlight.shadoworigin, r_viewforward) - viewdist)) >= 24.0f && CL_TraceBox(light->rtlight.shadoworigin, vec3_origin, vec3_origin, r_vieworigin, true, NULL, SUPERCONTENTS_SOLID, false).fraction == 1)
89 cscale = light->rtlight.corona * r_coronas.value * 0.25f;
90 scale = light->rtlight.radius * light->rtlight.coronasizescale;
91 R_DrawSprite(GL_ONE, GL_ONE, lightcorona, NULL, true, light->rtlight.shadoworigin, r_viewright, r_viewup, scale, -scale, -scale, scale, light->rtlight.color[0] * cscale, light->rtlight.color[1] * cscale, light->rtlight.color[2] * cscale, 1);
94 for (i = 0;i < r_refdef.numlights;i++)
96 light = r_refdef.lights[i];
97 if ((light->flags & flag) && light->corona * r_coronas.value > 0 && (dist = (DotProduct(light->origin, r_viewforward) - viewdist)) >= 24.0f && CL_TraceBox(light->origin, vec3_origin, vec3_origin, r_vieworigin, true, NULL, SUPERCONTENTS_SOLID, false).fraction == 1)
99 cscale = light->corona * r_coronas.value * 0.25f;
100 scale = light->rtlight.radius * light->rtlight.coronasizescale;
101 if (gl_flashblend.integer)
106 R_DrawSprite(GL_ONE, GL_ONE, lightcorona, NULL, true, light->origin, r_viewright, r_viewup, scale, -scale, -scale, scale, light->color[0] * cscale, light->color[1] * cscale, light->color[2] * cscale, 1);
112 =============================================================================
116 =============================================================================
119 void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, int dynamic)
121 VectorClear(diffusecolor);
122 VectorClear(diffusenormal);
124 if (!r_fullbright.integer && r_refdef.worldmodel && r_refdef.worldmodel->brush.LightPoint)
126 ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = r_ambient.value * (2.0f / 128.0f);
127 r_refdef.worldmodel->brush.LightPoint(r_refdef.worldmodel, p, ambientcolor, diffusecolor, diffusenormal);
130 VectorSet(ambientcolor, 1, 1, 1);
137 for (i = 0;i < r_refdef.numlights;i++)
139 light = r_refdef.lights[i];
140 Matrix4x4_Transform(&light->rtlight.matrix_worldtolight, p, v);
141 f = 1 - VectorLength2(v);
142 if (f > 0 && CL_TraceBox(p, vec3_origin, vec3_origin, light->origin, false, NULL, SUPERCONTENTS_SOLID, false).fraction == 1)
143 VectorMA(ambientcolor, f, light->rtlight.currentcolor, ambientcolor);