light: remove entity->fadedist, it was error-prone, and instead just check light level. it's only very slightly slower.

This commit is contained in:
Eric Wasylishen 2015-10-25 23:18:17 -06:00
parent 7f1beca6b4
commit d0fb0bd410
3 changed files with 9 additions and 40 deletions

View File

@ -63,7 +63,6 @@ typedef struct entity_s {
lightsample_t light; lightsample_t light;
light_formula_t formula; light_formula_t formula;
vec_t fadedist;
float atten; float atten;
float anglescale; float anglescale;
int style; int style;

View File

@ -254,37 +254,6 @@ CheckEntityFields(entity_t *entity)
} else { } else {
VectorCopy(vec3_white, entity->light.color); VectorCopy(vec3_white, entity->light.color);
} }
if (entity->formula == LF_LINEAR) {
/* Linear formula always has a falloff point */
entity->fadedist = fabs(entity->light.light) - fadegate;
entity->fadedist = entity->fadedist / entity->atten / scaledist;
entity->fadedist = qmax(0.0f, entity->fadedist);
} else if (fadegate < EQUAL_EPSILON) {
/* If fadegate is tiny, other lights have effectively infinite reach */
entity->fadedist = VECT_MAX;
} else {
/* Calculate the distance at which brightness falls to zero */
switch (entity->formula) {
case LF_INFINITE:
case LF_LOCALMIN:
entity->fadedist = VECT_MAX;
break;
case LF_INVERSE:
entity->fadedist = (LF_SCALE * fabs(entity->light.light)) / (scaledist * entity->atten * fadegate);
break;
case LF_INVERSE2:
case LF_INVERSE2A:
entity->fadedist = sqrt(fabs(entity->light.light * SQR(LF_SCALE) / (SQR(scaledist) * SQR(entity->atten) * fadegate)));
if (entity->formula == LF_INVERSE2A) {
entity->fadedist -= (LF_SCALE / (scaledist * entity->atten));
}
entity->fadedist = qmax(0.0f, entity->fadedist);
break;
default:
Error("Internal error: formula not handled in %s", __func__);
}
}
} }
/* /*

View File

@ -813,10 +813,15 @@ CullLight(const entity_t *entity, const lightsurf_t *lightsurf)
vec_t dist; vec_t dist;
VectorSubtract(entity->origin, lightsurf->origin, distvec); VectorSubtract(entity->origin, lightsurf->origin, distvec);
dist = VectorLength(distvec) - lightsurf->radius - entity->fadedist; dist = VectorLength(distvec) - lightsurf->radius;
/* return true if the spheres don't intersect */ /* light is inside surface bounding sphere => can't cull */
return dist > 0; if (dist < 0)
return false;
/* return true if the light level at the closest point on the
surface bounding sphere to the light source is <= fadegate */
return GetLightValue(&entity->light, entity, dist) <= fadegate;
} }
/* /*
@ -844,10 +849,6 @@ LightFace_Entity(const entity_t *entity, const lightsample_t *light,
if (dist < 0) if (dist < 0)
return; return;
/* don't bother with light too far away from plane */
if (dist > entity->fadedist)
return;
/* sphere cull surface and light */ /* sphere cull surface and light */
if (CullLight(entity, lightsurf)) if (CullLight(entity, lightsurf))
return; return;
@ -867,7 +868,7 @@ LightFace_Entity(const entity_t *entity, const lightsample_t *light,
dist = VectorLength(ray); dist = VectorLength(ray);
/* Quick distance check first */ /* Quick distance check first */
if (dist > entity->fadedist) if (GetLightValue(&entity->light, entity, dist) <= fadegate)
continue; continue;
/* Check spotlight cone */ /* Check spotlight cone */