diff --git a/include/r_local.h b/include/r_local.h index 53a503a2f..b78954e0e 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -47,9 +47,9 @@ // viewmodel lighting ======================================================= typedef struct { - int ambientlight; - int shadelight; - float *plightvec; + int ambientlight; + int shadelight; + vec3_t lightvec; } alight_t; // clipped bmodel edges ===================================================== diff --git a/libs/video/renderer/sw/sw_ralias.c b/libs/video/renderer/sw/sw_ralias.c index f99b2712d..81e59720a 100644 --- a/libs/video/renderer/sw/sw_ralias.c +++ b/libs/video/renderer/sw/sw_ralias.c @@ -52,7 +52,7 @@ trivertx_t *r_apverts; // TODO: these probably will go away with optimized rasterization static mdl_t *pmdl; -vec3_t r_plightvec; +vec3_t r_lightvec; int r_ambientlight; float r_shadelight; static aliashdr_t *paliashdr; @@ -413,7 +413,7 @@ R_AliasTransformFinalVert (finalvert_t *fv, trivertx_t *pverts, // lighting plightnormal = r_avertexnormals[pverts->lightnormalindex]; - lightcos = DotProduct (plightnormal, r_plightvec); + lightcos = DotProduct (plightnormal, r_lightvec); temp = r_ambientlight; if (lightcos < 0) { @@ -463,7 +463,7 @@ R_AliasTransformAndProjectFinalVerts (finalvert_t *fv, stvert_t *pstverts) // lighting plightnormal = r_avertexnormals[pverts->lightnormalindex]; - lightcos = DotProduct (plightnormal, r_plightvec); + lightcos = DotProduct (plightnormal, r_lightvec); temp = r_ambientlight; if (lightcos < 0) { @@ -555,11 +555,11 @@ R_AliasSetupSkin (entity_t *ent) static void -R_AliasSetupLighting (alight_t *plighting) +R_AliasSetupLighting (alight_t *lighting) { // guarantee that no vertex will ever be lit below LIGHT_MIN, so we don't // have to clamp off the bottom - r_ambientlight = plighting->ambientlight; + r_ambientlight = lighting->ambientlight; if (r_ambientlight < LIGHT_MIN) r_ambientlight = LIGHT_MIN; @@ -569,7 +569,7 @@ R_AliasSetupLighting (alight_t *plighting) if (r_ambientlight < LIGHT_MIN) r_ambientlight = LIGHT_MIN; - r_shadelight = plighting->shadelight; + r_shadelight = lighting->shadelight; if (r_shadelight < 0) r_shadelight = 0; @@ -577,9 +577,9 @@ R_AliasSetupLighting (alight_t *plighting) r_shadelight *= VID_GRADES; // rotate the lighting vector into the model's frame of reference - r_plightvec[0] = DotProduct (plighting->plightvec, alias_forward); - r_plightvec[1] = DotProduct (plighting->plightvec, alias_left); - r_plightvec[2] = DotProduct (plighting->plightvec, alias_up); + r_lightvec[0] = DotProduct (lighting->lightvec, alias_forward); + r_lightvec[1] = DotProduct (lighting->lightvec, alias_left); + r_lightvec[2] = DotProduct (lighting->lightvec, alias_up); } /* @@ -598,7 +598,7 @@ R_AliasSetupFrame (entity_t *ent) void -R_AliasDrawModel (entity_t *ent, alight_t *plighting) +R_AliasDrawModel (entity_t *ent, alight_t *lighting) { int size; finalvert_t *finalverts; @@ -623,7 +623,7 @@ R_AliasDrawModel (entity_t *ent, alight_t *plighting) R_AliasSetupSkin (ent); R_AliasSetUpTransform (ent, ent->visibility.trivial_accept); - R_AliasSetupLighting (plighting); + R_AliasSetupLighting (lighting); R_AliasSetupFrame (ent); r_affinetridesc.drawtype = ((ent->visibility.trivial_accept == 3) diff --git a/libs/video/renderer/sw/sw_riqm.c b/libs/video/renderer/sw/sw_riqm.c index b4851c991..e2691d2e5 100644 --- a/libs/video/renderer/sw/sw_riqm.c +++ b/libs/video/renderer/sw/sw_riqm.c @@ -58,14 +58,14 @@ // avoid the need for inner-loop light // clamping -static vec3_t r_plightvec; +static vec3_t r_lightvec; static int r_ambientlight; static float r_shadelight; static inline int calc_light (float *normal) { - float lightcos = DotProduct (normal, r_plightvec); + float lightcos = DotProduct (normal, r_lightvec); int temp = r_ambientlight; if (lightcos < 0) { @@ -236,9 +236,9 @@ R_IQMSetupLighting (entity_t *ent, alight_t *plighting) mat4f_t mat; Transform_GetWorldMatrix (ent->transform, mat); //FIXME vectorize - r_plightvec[0] = DotProduct (plighting->plightvec, mat[0]); - r_plightvec[1] = DotProduct (plighting->plightvec, mat[1]); - r_plightvec[2] = DotProduct (plighting->plightvec, mat[2]); + r_lightvec[0] = DotProduct (plighting->lightvec, mat[0]); + r_lightvec[1] = DotProduct (plighting->lightvec, mat[1]); + r_lightvec[2] = DotProduct (plighting->lightvec, mat[2]); } static void diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index e668b1458..9771e8182 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -60,8 +60,6 @@ #endif void *colormap; -static vec3_t viewlightvec; -static alight_t r_viewlighting = { 128, 192, viewlightvec }; int r_numallocatededges; qboolean r_drawpolys; qboolean r_drawculledpolys; @@ -369,7 +367,7 @@ setup_lighting (entity_t *ent, alight_t *lighting) lighting->ambientlight = j; lighting->shadelight = j; - lighting->plightvec = lightvec; + VectorCopy (lightvec, lighting->lightvec); for (unsigned lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= vr_data.realtime) { @@ -439,7 +437,6 @@ static void R_DrawViewModel (void) { // FIXME: remove and do real lighting - float lightvec[3] = { -1, 0, 0 }; int j; unsigned int lnum; vec3_t dist; @@ -447,6 +444,7 @@ R_DrawViewModel (void) float minlight; dlight_t *dl; entity_t *viewent; + alight_t lighting; if (vr_data.inhibit_viewmodel || !r_drawviewmodel->int_val @@ -459,8 +457,7 @@ R_DrawViewModel (void) VectorCopy (Transform_GetWorldPosition (viewent->transform), r_entorigin); - VectorCopy (vup, viewlightvec); - VectorNegate (viewlightvec, viewlightvec); + VectorNegate (vup, lighting.lightvec); minlight = max (viewent->renderer.min_light, viewent->renderer.model->min_light); @@ -468,8 +465,8 @@ R_DrawViewModel (void) j = max (R_LightPoint (&r_refdef.worldmodel->brush, r_entorigin), minlight * 128); - r_viewlighting.ambientlight = j; - r_viewlighting.shadelight = j; + lighting.ambientlight = j; + lighting.shadelight = j; // add dynamic lights for (lnum = 0; lnum < r_maxdlights; lnum++) { @@ -484,18 +481,16 @@ R_DrawViewModel (void) VectorSubtract (r_entorigin, dl->origin, dist); add = dl->radius - VectorLength (dist); if (add > 0) - r_viewlighting.ambientlight += add; + lighting.ambientlight += add; } // clamp lighting so it doesn't overbright as much - if (r_viewlighting.ambientlight > 128) - r_viewlighting.ambientlight = 128; - if (r_viewlighting.ambientlight + r_viewlighting.shadelight > 192) - r_viewlighting.shadelight = 192 - r_viewlighting.ambientlight; + if (lighting.ambientlight > 128) + lighting.ambientlight = 128; + if (lighting.ambientlight + lighting.shadelight > 192) + lighting.shadelight = 192 - lighting.ambientlight; - r_viewlighting.plightvec = lightvec; - - R_AliasDrawModel (viewent, &r_viewlighting); + R_AliasDrawModel (viewent, &lighting); } static int