From b36569eb9f1f89af054d082505ff1502ee4ef49e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 11 Jul 2004 00:37:48 +0000 Subject: [PATCH] grievre's patch to make entity minlight and fullbright fields work properly --- libs/video/renderer/gl/gl_mod_alias.c | 23 +++++++++++++++++------ libs/video/renderer/sw/sw_rmain.c | 14 ++++++++++---- libs/video/renderer/sw32/sw32_rmain.c | 14 ++++++++++---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index 18ce003a0..507f7ad42 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -537,11 +537,26 @@ R_DrawAliasModel (entity_t *e) qfglColor4fv (e->colormod); if (!is_fullbright) { + float lightadj; + // get lighting information R_LightPoint (e->origin); + + lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0; + + // Do minlight stuff here since that's how software does it :) + + if (lightadj > 0) { + if (lightadj < minlight) + lightadj = minlight / lightadj; + else + lightadj = 1.0; - // 256 is fullbright, NOT 200 (was 1 / 200 or 0.005) -Grievre - VectorScale (ambientcolor, 1.0 / 256.0, ambientcolor); + // 255 is fullbright + VectorScale (ambientcolor, lightadj / 255.0, ambientcolor); + } else { + ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = minlight; + } if (gl_vector_light->int_val) { for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) { @@ -589,8 +604,6 @@ R_DrawAliasModel (entity_t *e) // 1.5 to allow some pastelization (curb darkness from dlight) if (d > 1.5) { VectorScale (emission, 1.5 / d, emission); - } else if (d < minlight) { // had !used_lights (wtf) - emission[2] = emission[1] = emission[0] = minlight; } qfglMaterialfv (GL_FRONT, GL_EMISSION, emission); @@ -619,8 +632,6 @@ R_DrawAliasModel (entity_t *e) // 1.5 to allow some fading (curb emission making stuff dark) if (d > 1.5) { VectorScale (emission, 1.5 / d, emission); - } else if (d < minlight) { - emission[2] = emission[1] = emission[0] = minlight; } emission[0] *= e->colormod[0]; diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index d444cca5a..5d0872e3c 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -53,6 +53,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/sound.h" #include "QF/sys.h" +#include "compat.h" #include "r_cvar.h" #include "r_dynamic.h" #include "r_local.h" @@ -414,6 +415,7 @@ R_DrawEntitiesOnList (void) float lightvec[3] = { -1, 0, 0 }; vec3_t dist; float add; + float minlight = 0; if (!r_drawentities->int_val) return; @@ -432,10 +434,13 @@ R_DrawEntitiesOnList (void) VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); + minlight = max (currententity->model->min_light, currententity->min_light); + // see if the bounding box lets us trivially reject, also // sets trivial accept status if (R_AliasCheckBBox ()) { - j = R_LightPoint (currententity->origin); + // 128 instead of 255 due to clamping below + j = max (R_LightPoint (currententity->origin), minlight * 128); lighting.ambientlight = j; lighting.shadelight = j; @@ -479,6 +484,7 @@ R_DrawViewModel (void) unsigned int lnum; vec3_t dist; float add; + float minlight; dlight_t *dl; if (r_inhibit_viewmodel @@ -496,10 +502,10 @@ R_DrawViewModel (void) VectorCopy (vup, viewlightvec); VectorInverse (viewlightvec); - j = R_LightPoint (currententity->origin); + minlight = max (currententity->min_light, currententity->model->min_light); + + j = max (R_LightPoint (currententity->origin), minlight * 128); - if (j < 24) - j = 24; // always give some light on gun r_viewlighting.ambientlight = j; r_viewlighting.shadelight = j; diff --git a/libs/video/renderer/sw32/sw32_rmain.c b/libs/video/renderer/sw32/sw32_rmain.c index 947d369e1..771e22ef3 100644 --- a/libs/video/renderer/sw32/sw32_rmain.c +++ b/libs/video/renderer/sw32/sw32_rmain.c @@ -50,6 +50,7 @@ static __attribute__ ((unused)) const char rcsid[] = #include "QF/sound.h" #include "QF/sys.h" +#include "compat.h" #include "r_cvar.h" #include "r_dynamic.h" #include "r_local.h" @@ -434,6 +435,7 @@ R_DrawEntitiesOnList (void) float lightvec[3] = { -1, 0, 0 }; vec3_t dist; float add; + float minlight; if (!r_drawentities->int_val) return; @@ -452,10 +454,13 @@ R_DrawEntitiesOnList (void) VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); + minlight = max (currententity->min_light, currententity->model->min_light); + // see if the bounding box lets us trivially reject, also // sets trivial accept status if (R_AliasCheckBBox ()) { - j = R_LightPoint (currententity->origin); + // 128 instead of 255 due to clamping below + j = max (R_LightPoint (currententity->origin), minlight * 128); lighting.ambientlight = j; lighting.shadelight = j; @@ -499,6 +504,7 @@ R_DrawViewModel (void) unsigned int lnum; vec3_t dist; float add; + float minlight; dlight_t *dl; if (r_inhibit_viewmodel || !r_drawviewmodel->int_val @@ -515,10 +521,10 @@ R_DrawViewModel (void) VectorCopy (vup, viewlightvec); VectorInverse (viewlightvec); - j = R_LightPoint (currententity->origin); + minlight = max (currententity->min_light, currententity->model->min_light); + + j = max (R_LightPoint (currententity->origin), minlight * 128); - if (j < 24) - j = 24; // always give some light on gun r_viewlighting.ambientlight = j; r_viewlighting.shadelight = j;