From 091b714e4c08fa84c638b4360f274bd1b8e99d9e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 3 Jan 2012 20:36:07 +0900 Subject: [PATCH] Implement dynamic lighting. This uses the same calculations as the software renderer. However, as the lightmap calculations are not done yet, if there is no dlight in the vicinity, there will be no light. demo1 is pretty cool to watch :) --- libs/video/renderer/glsl/glsl_alias.c | 35 ++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/libs/video/renderer/glsl/glsl_alias.c b/libs/video/renderer/glsl/glsl_alias.c index d676aec14..34ef30934 100644 --- a/libs/video/renderer/glsl/glsl_alias.c +++ b/libs/video/renderer/glsl/glsl_alias.c @@ -146,6 +146,33 @@ R_InitAlias (void) GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.shadelight); GL_ResolveShaderParam (quake_mdl.program, &quake_mdl.lightvec); } + +static void +calc_lighting (entity_t *ent, float *ambient, float *shadelight, + vec3_t lightvec) +{ + unsigned i; + float add; + vec3_t dist; + + VectorSet ( -1, 0, 0, lightvec); //FIXME + *ambient = max (R_LightPoint (ent->origin), max (ent->model->min_light, + ent->min_light) * 128); + *shadelight = *ambient; + + for (i = 0; i < r_maxdlights; i++) { + if (r_dlights[i].die >= r_realtime) { + VectorSubtract (ent->origin, r_dlights[i].origin, dist); + add = r_dlights[i].radius - VectorLength (dist); + if (add > 0) + *ambient += add; + } + } + if (*ambient >= 128) + *ambient = 128; + if (*shadelight > 192 - *ambient) + *shadelight = 192 - *ambient; +} //#define TETRAHEDRON void R_DrawAlias (void) @@ -165,9 +192,9 @@ R_DrawAlias (void) }; #endif static quat_t color = { 1, 1, 1, 1}; - static vec3_t lightvec = { -1, 0, 0 }; //FIXME - float ambient = 128; //FIXME - float shadelight = 64; //FIXME + static vec3_t lightvec; + float ambient; + float shadelight; float skin_size[2]; entity_t *ent = currententity; model_t *model = ent->model; @@ -180,6 +207,8 @@ R_DrawAlias (void) hdr = Cache_Get (&model->cache); + calc_lighting (ent, &ambient, &shadelight, lightvec); + // we need only the rotation for normals. VectorCopy (ent->transform + 0, norm_mat + 0); VectorCopy (ent->transform + 4, norm_mat + 3);