46 refdef.dynamicLights[
i].radius = radius;
50 color[0], color[1], color[2],
123 for (
i = 0;
i <
refdef.numDynamicLights &&
i < maxLights;
i++) {
132 for (;
i < maxLights ;
i++)
153 vec4_t blackColor = {0.0, 0.0, 0.0, 1.0};
154 const vec4_t whiteColor = {1.0, 1.0, 1.0, 1.0};
155 const vec4_t defaultLight0Position = {0.0, 0.0, 1.0, 0.0};
161 glEnable(GL_LIGHTING);
163 glEnable(GL_COLOR_MATERIAL);
164#ifndef GL_VERSION_ES_CM_1_0
165 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
168 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0);
169 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0);
170 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0);
172 glLightfv(GL_LIGHT0, GL_SPECULAR, blackColor);
173 glLightfv(GL_LIGHT0, GL_AMBIENT,
refdef.modelAmbientColor);
175 glLightfv(GL_LIGHT0, GL_POSITION,
refdef.sunVector);
180 glLightfv(GL_LIGHT0, GL_DIFFUSE, blackColor);
183 glLightfv(GL_LIGHT0, GL_DIFFUSE,
refdef.sunDiffuseColor);
187 glDisable(GL_LIGHTING);
188 glDisable(GL_COLOR_MATERIAL);
190 glLightfv(GL_LIGHT0, GL_POSITION, defaultLight0Position);
191 glLightfv(GL_LIGHT0, GL_AMBIENT, blackColor);
192 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteColor);
193 glLightfv(GL_LIGHT0, GL_SPECULAR, whiteColor);
200 if (!enable || !
r_state.lighting_enabled) {
201 if (
r_state.dynamic_lighting_enabled) {
205 for (
i = 0;
i < maxLights;
i++)
214 r_state.dynamic_lighting_enabled =
false;
219 if (numLights > maxLights)
220 numLights = maxLights;
222 r_state.dynamic_lighting_enabled =
true;
239 for (
i = 0;
i < numLights;
i++) {
248 for (;
i < maxLights;
i++)
264 Com_Printf(
"Failed to add lightsource: MAX_STATIC_LIGHTS exceeded\n");
269 color[0], color[1], color[2],
277 light->
color[3] = 1.0;
284 vec4_t blackColor = {0.0, 0.0, 0.0, 1.0};
288 glLightfv(GL_LIGHT0 +
i, GL_DIFFUSE, blackColor);
289 glLightfv(GL_LIGHT0 +
i, GL_AMBIENT, blackColor);
290 glLightfv(GL_LIGHT0 +
i, GL_SPECULAR, blackColor);
291 glDisable(GL_LIGHT0 +
i);
293 glDisable(GL_LIGHTING);
302 refdef.numStaticLights = 0;
361 if (
i + 1 == maxLights) {
406 for (rootEnt = ent; rootEnt->
tagent; rootEnt = ent->
tagent)
456 for (
i = 0;
i <
refdef.numStaticLights;
i++) {
460 if (distSqr > (diameter + light->
radius) * (diameter + light->
radius))
465 if (
refdef.trace.fraction == 1.0)
480 for (
i = 0;
i <
refdef.numDynamicLights;
i++) {
484 if (distSqr > (diameter + light->
radius) * (diameter + light->
radius))
489 if (
refdef.trace.fraction == 1.0)
void getDiagonal(vec3_t diagonal) const
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
void Com_Printf(const char *const fmt,...)
static light_t * lights[LIGHTMAP_MAX]
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
void VectorMA(const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector)
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb).
void GLPositionTransform(const float m[16], const vec3_t in, vec3_t out)
Transform position (xyz) vector by OpenGL rules.
static sustain_t r_sustainArray[MAX_GL_LIGHTS]
void R_AddSustainedLight(const vec3_t org, float radius, const vec3_t color, float sustain)
void R_AddStaticLight(const vec3_t origin, float radius, const vec3_t color)
Add static light for model lighting (world already got them baked into lightmap).
void R_ClearStaticLights(void)
Remove all static light data.
void R_EnableModelLights(const light_t **lights, int numLights, bool inShadow, bool enable)
Enable or disable realtime dynamic lighting for models.
static void R_AddLightToEntity(const vec_t *pos, lighting_t *ltng, const light_t *light, const float distSqr)
Adds light to the entity's lights list, sorted by distance.
void R_UpdateSustainedLights(void)
Updates state of sustained lights; should be called once per frame right before world rendering.
void R_AddLight(const vec3_t origin, float radius, const vec3_t color)
Create light to be rendered in the current frame (will be removed before the next).
static lighting_t fakeLightingData
void R_DisableLights(void)
void R_UpdateLightList(entity_t *ent)
Recalculate active lights list for the given entity; R_CalcTransform(ent) should be called before thi...
void R_EnableWorldLights(void)
Set up lighting data for the GLSL world shader.
#define MAX_STATIC_LIGHTS
#define CACHE_CLEAR_TRESHOLD
void R_Trace(const Line &trLine, float size, int contentmask)
Moves the given mins/maxs volume through the world from start to end.
local graphics definitions
#define MIN_GL_CONSTANT_ATTENUATION
cvar_t * r_dynamic_lights
material_t defaultMaterial
void R_EnableAttribute(const char *name)
void R_ProgramParameter3fvs(const char *name, GLint size, GLfloat *value)
void R_ProgramParameter4fvs(const char *name, GLint size, GLfloat *value)
void R_DisableAttribute(const char *name)
void R_ProgramParameter3fv(const char *name, GLfloat *value)
void R_UseMaterial(const material_t *material)
lighting structure which contains static and dynamic lighting info for entities
const light_t * cachedLights[MAX_ENTITY_LIGHTS]
const light_t * lights[MAX_ENTITY_LIGHTS]
sustains are light flashes which slowly decay
#define Vector4Set(v, r, g, b, a)
#define VectorCopy(src, dest)
#define VectorDistSqr(a, b)
#define VectorScale(in, scale, out)