diff --git a/light/ltface.c b/light/ltface.c index f333de9e..6cd8f164 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -1563,7 +1563,7 @@ BounceLight_ColorAtDist(const bouncelight_t *vpl, vec_t dist, vec3_t color) // returns color in [0,255] void -GetIndirectLighting (const bouncelight_t *vpl, const vec3_t origin, const vec3_t normal, vec3_t color) +GetIndirectLighting (const bsp2_t *bsp, const bouncelight_t *vpl, const bsp2_dface_t *face, const byte *pvs, const vec3_t origin, const vec3_t normal, vec3_t color) { VectorSet(color, 0, 0, 0); @@ -1571,27 +1571,22 @@ GetIndirectLighting (const bouncelight_t *vpl, const vec3_t origin, const vec3_t VectorSubtract(origin, vpl->pos, dir); // vpl -> sample point vec_t dist = VectorNormalize(dir); - vec_t anglescale = 1; - if (dist != 0) { - const vec_t dp1 = DotProduct(vpl->surfnormal, dir); - if (dp1 < 0) - return; // sample point behind vpl - - vec3_t sp_vpl; - VectorScale(dir, -1, sp_vpl); - - const vec_t dp2 = DotProduct(sp_vpl, normal); - if (dp2 < 0) - return; // vpl behind sample face - - anglescale = dp1 * dp2; - } + const vec_t dp1 = DotProduct(vpl->surfnormal, dir); + if (dp1 < 0) + return; // sample point behind vpl + + vec3_t sp_vpl; + VectorScale(dir, -1, sp_vpl); + + const vec_t dp2 = DotProduct(sp_vpl, normal); + if (dp2 < 0) + return; // vpl behind sample face // get light contribution BounceLight_ColorAtDist(vpl, dist, color); // apply angle scale - VectorScale(color, anglescale, color); + VectorScale(color, dp1 * dp2, color); } bool @@ -1605,6 +1600,8 @@ BounceLight_SphereCull(const bsp2_t *bsp, const bouncelight_t *vpl, const lights vec_t dist = VectorNormalize(dir) + lightsurf->radius; // get light contribution + + VectorScale(vpl->color, vpl->area, color); BounceLight_ColorAtDist(vpl, dist, color); if (((color[0] + color[1] + color[2]) / 3) < 0.25) @@ -1636,7 +1633,7 @@ LightFace_Bounce(const bsp2_t *bsp, const bsp2_dface_t *face, const lightsurf_t for (int i = 0; i < lightsurf->numpoints; i++) { vec3_t indirect = {0}; - GetIndirectLighting(vpl, lightsurf->points[i], lightsurf->normals[i], indirect); + GetIndirectLighting(bsp, vpl, face, lightsurf->pvs, lightsurf->points[i], lightsurf->normals[i], indirect); if (((indirect[0] + indirect[1] + indirect[2]) / 3) < 0.25) continue;