From 51f2bc1ff0f064b4f9fa8fdf6e6c7994b3aa24da Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 19 Jun 2022 12:09:12 -0400 Subject: [PATCH] fix visapprox rays crashing fix visapprox rays to work with surface lights; it's slower than vis but it at least works now --- light/ltface.cc | 9 +++------ light/surflight.cc | 16 +++++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/light/ltface.cc b/light/ltface.cc index f3822858..e0a5c099 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1537,9 +1537,6 @@ std::map GetDirectLighting( static bool VisCullEntity(const mbsp_t *bsp, const std::vector &pvs, const mleaf_t *entleaf) { - if (options.visapprox.value() != visapprox_t::VIS) { - return false; - } if (pvs.empty()) { return false; } @@ -1569,7 +1566,7 @@ static void LightFace_Entity( const qplane3d *plane = &lightsurf->plane; /* vis cull */ - if (VisCullEntity(bsp, lightsurf->pvs, entity->leaf)) { + if (options.visapprox.value() == visapprox_t::VIS && VisCullEntity(bsp, lightsurf->pvs, entity->leaf)) { return; } @@ -2142,7 +2139,7 @@ static void LightFace_Bounce( #if 1 for (const bouncelight_t &vpl : BounceLights()) { - if (VisCullEntity(bsp, lightsurf->pvs, vpl.leaf)) { + if (options.visapprox.value() == visapprox_t::VIS && VisCullEntity(bsp, lightsurf->pvs, vpl.leaf)) { continue; } @@ -2330,7 +2327,7 @@ LightFace_SurfaceLight(const mbsp_t *bsp, const lightsurf_t *lightsurf, lightmap raystream_occlusion_t *rs = lightsurf->occlusion_stream; for (int c = 0; c < vpl.points.size(); c++) { - if (VisCullEntity(bsp, lightsurf->pvs, vpl.leaves[c])) { + if (options.visapprox.value() == visapprox_t::VIS && VisCullEntity(bsp, lightsurf->pvs, vpl.leaves[c])) { continue; } diff --git a/light/surflight.cc b/light/surflight.cc index 7a9dc824..c36a1165 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -119,9 +119,14 @@ static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspaw l.omnidirectional = true;//(info->flags.native & Q2_SURF_SKY) ? true : false; l.points = points; - if (options.visapprox.value() == visapprox_t::VIS) { - for (auto &pt : points) { + // Init bbox... + l.bounds = EstimateVisibleBoundsAtPoint(facemidpoint); + + for (auto &pt : points) { + if (options.visapprox.value() == visapprox_t::VIS) { l.leaves.push_back(Light_PointInLeaf(bsp, pt + l.surfnormal)); + } else if (options.visapprox.value() == visapprox_t::RAYS) { + l.bounds += EstimateVisibleBoundsAtPoint(pt); } } @@ -132,13 +137,6 @@ static void MakeSurfaceLightsThread(const mbsp_t *bsp, const settings::worldspaw l.intensity = l.totalintensity / points.size(); l.color = texturecolor; - // Init bbox... - l.bounds = qvec3d(0); - - if (options.visapprox.value() == visapprox_t::RAYS) { - l.bounds = EstimateVisibleBoundsAtPoint(facemidpoint); - } - // Store light... unique_lock lck{surfacelights_lock}; surfacelights.push_back(l);