From 6bd8864ff419bb2a8581d2643436727771644ca7 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 3 Nov 2016 01:44:17 -0600 Subject: [PATCH] light: refactor LightFace_Sky --- light/ltface.cc | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/light/ltface.cc b/light/ltface.cc index 770b455c..969edb5f 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1476,7 +1476,22 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li continue; } - rs->pushRay(i, surfpoint, incoming, MAX_SKY_DIST, shadowself); + angle = (1.0 - sun->anglescale) + sun->anglescale * angle; + float value = angle * sun->sunlight * glass_transparency; + if (sun->dirt) { + value *= Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], NULL, lightsurf); + } + + vec3_t color, normalcontrib; + VectorScale(sun->sunlight_color, value / 255.0, color); + VectorScale(sun->sunvec, value, normalcontrib); + + /* Quick distance check first */ + if (fabs(LightSample_Brightness(color)) <= fadegate) { + continue; + } + + rs->pushRay(i, surfpoint, incoming, MAX_SKY_DIST, shadowself, color, normalcontrib); } rs->tracePushedRaysIntersection(); @@ -1488,25 +1503,15 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li } const int i = rs->getPushedRayPointIndex(j); - const vec_t *surfnorm = lightsurf->normals[i]; - - // FIXME: don't recompute this: compute before tracing, check gate, and store color in ray - float angle = DotProduct(incoming, surfnorm); - if (lightsurf->twosided) { - if (angle < 0) { - angle = -angle; - } - } - - angle = (1.0 - sun->anglescale) + sun->anglescale * angle; - float value = angle * sun->sunlight * glass_transparency; - if (sun->dirt) { - value *= Dirt_GetScaleFactor(cfg, lightsurf->occlusion[i], NULL, lightsurf); - } - lightsample_t *sample = &lightmap->samples[i]; - Light_Add(sample, value, sun->sunlight_color, sun->sunvec); - + + vec3_t color, normalcontrib; + rs->getPushedRayColor(j, color); + rs->getPushedRayNormalContrib(j, normalcontrib); + + VectorAdd(sample->color, color, sample->color); + VectorAdd(sample->direction, normalcontrib, sample->direction); + hit = true; }