diff --git a/light/ltface.cc b/light/ltface.cc index 0d8cb25d..67a0f3dc 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -2026,9 +2026,9 @@ LightFace_SurfaceLight(const mbsp_t *bsp, lightsurf_t *lightsurf, lightmapdict_t raystream_occlusion_t &rs = occlusion_stream; - rs.clearPushedRays(); - for (int c = 0; c < vpl.points.size(); c++) { + rs.clearPushedRays(); + for (int i = 0; i < lightsurf->samples.size(); i++) { const auto &sample = lightsurf->samples[i]; @@ -2059,50 +2059,49 @@ LightFace_SurfaceLight(const mbsp_t *bsp, lightsurf_t *lightsurf, lightmapdict_t rs.pushRay(i, pos, dir, dist, &indirect); } } - } - if (!rs.numPushedRays()) - continue; - - rs.tracePushedRaysOcclusion(lightsurf->modelinfo, CHANNEL_MASK_DEFAULT); - -#if 0 - total_surflight_rays += rs.numPushedRays(); -#endif - - const int lightmapstyle = vpl_setting.style; - lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, lightmapstyle, lightsurf); - - bool hit = false; - const int numrays = rs.numPushedRays(); - for (int j = 0; j < numrays; j++) { - if (rs.getPushedRayOccluded(j)) + if (!rs.numPushedRays()) continue; - - const ray_io &ray = rs.getRay(j); - const int i = ray.index; - qvec3f indirect = rs.getPushedRayColor(j); - //Q_assert(!std::isnan(indirect[0])); - - // Use dirt scaling on the surface lighting. - const float dirtscale = - Dirt_GetScaleFactor(cfg, lightsurf->samples[i].occlusion, nullptr, 0.0, lightsurf); - indirect *= dirtscale; - - lightsample_t &sample = lightmap->samples[i]; - sample.color += indirect; - lightmap->bounce_color += indirect; - - hit = true; #if 0 - ++total_surflight_ray_hits; + total_surflight_rays += rs.numPushedRays(); #endif - } + rs.tracePushedRaysOcclusion(lightsurf->modelinfo, CHANNEL_MASK_DEFAULT); - // If surface light contributed anything, save. - if (hit) - Lightmap_Save(bsp, lightmaps, lightsurf, lightmap, lightmapstyle); + const int lightmapstyle = vpl_setting.style; + lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, lightmapstyle, lightsurf); + + bool hit = false; + const int numrays = rs.numPushedRays(); + for (int j = 0; j < numrays; j++) { + if (rs.getPushedRayOccluded(j)) + continue; + + const ray_io &ray = rs.getRay(j); + const int i = ray.index; + qvec3f indirect = rs.getPushedRayColor(j); + + //Q_assert(!std::isnan(indirect[0])); + + // Use dirt scaling on the surface lighting. + const float dirtscale = + Dirt_GetScaleFactor(cfg, lightsurf->samples[i].occlusion, nullptr, 0.0, lightsurf); + indirect *= dirtscale; + + lightsample_t &sample = lightmap->samples[i]; + sample.color += indirect; + lightmap->bounce_color += indirect; + + hit = true; +#if 0 + ++total_surflight_ray_hits; +#endif + } + + // If surface light contributed anything, save. + if (hit) + Lightmap_Save(bsp, lightmaps, lightsurf, lightmap, lightmapstyle); + } } } }