mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
[sw] Make alight_t lightvec an actual vector
The change to using separate per-model-type entity queues resulted in the lighting vector used for alias and iqm models being in an ephemeral location (in the shared setup_lighting function's stack frame). This resulted in the model rendering code getting a garbage vector due to it being overwritten by another stack frame. What I don't get is why the garbage varied from run to run for the same demo (demo2, the first scrag behind the start door showed the bad lighting nicely), which made tracking down the offending commit (and thus the code) rather troublesome, though once I found it, it was a bit of a face-palm moment.
This commit is contained in:
parent
6c29904b1d
commit
833fb2f4f8
4 changed files with 30 additions and 35 deletions
|
@ -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 =====================================================
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue