decouple extra and bounce extra; this allows you to still use extra4 but not have to wait like 16x longer for bounce lights to work

This commit is contained in:
Jonathan 2022-08-18 07:35:06 -04:00
parent 424e3ee110
commit 48c6b7a370
3 changed files with 29 additions and 11 deletions

View File

@ -415,6 +415,8 @@ public:
this, "lightmap_scale", 0, &experimental_group, "force change lightmap scale; vanilla engines only allow 16"};
setting_extra extra{
this, {"extra", "extra4"}, 1, &performance_group, "supersampling; 2x2 (extra) or 4x4 (extra4) respectively"};
setting_extra bounceextra{
this, {"bounceextra", "bounceextra4"}, 1, &performance_group, "bounce light supersampling; 2x2 (bounceextra) or 4x4 (bounceextra4) respectively"};
setting_enum<visapprox_t> visapprox{this, "visapprox", visapprox_t::AUTO,
{{"auto", visapprox_t::AUTO}, {"none", visapprox_t::NONE}, {"vis", visapprox_t::VIS},
{"rays", visapprox_t::RAYS}},

View File

@ -171,15 +171,27 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m
return;
}
// point divisor on one axis;
// extra4 + bounceextra4 = 1
// extra2 + bounceextra4 = 0.5 (for every point, we get two bounce lights)
// extra4 + bounceextra = 2 (for every two points, we get one bounce light)
// extra4 + (no bounce extra) = 4 (for every 4 points, we get one bounce light)
const vec_t bounce_step = light_options.extra.value() / light_options.bounceextra.value();
// color divisor;
// extra4 + (no bounce extra) = 16, since surf.points is 16x larger than vanilla
const vec_t bounce_divisor = bounce_step * bounce_step;
const vec_t area_divisor = sqrt(area);
const vec_t sample_divisor = surf.points.size() / (surf.vanilla_extents.width() * surf.vanilla_extents.height());
const vec_t sample_divisor = (surf.points.size() / bounce_divisor) / (surf.vanilla_extents.width() * surf.vanilla_extents.height());
// average them, area weighted
std::unordered_map<int, qvec3d> sum;
for (const auto &lightmap : surf.lightmapsByStyle) {
for (const auto &sample : lightmap.samples) {
sum[lightmap.style] += sample.color / sample_divisor;
for (vec_t x = 0; x < surf.width; x += bounce_step) {
for (vec_t y = 0; y < surf.height; y += bounce_step) {
sum[lightmap.style] += lightmap.samples[(y * surf.width) + x].color / sample_divisor;
}
}
}
@ -209,10 +221,13 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m
qplane3d faceplane = winding.plane();
area /= surf.points.size();
for (auto &pt : surf.points) {
AddBounceLight(pt, emitcolors, faceplane.normal, area, &face, bsp);
area /= surf.points.size() / bounce_divisor;
for (vec_t x = 0; x < surf.width; x += bounce_step) {
for (vec_t y = 0; y < surf.height; y += bounce_step) {
auto &pt = surf.points[(y * surf.width) + x];
AddBounceLight(pt, emitcolors, faceplane.normal, area, &face, bsp);
}
}
}

View File

@ -1689,7 +1689,7 @@ inline bool BounceLight_SphereCull(const mbsp_t *bsp, const bouncelight_t *vpl,
}
static bool // mxd
SurfaceLight_SphereCull(const surfacelight_t *vpl, const lightsurf_t *lightsurf)
SurfaceLight_SphereCull(const surfacelight_t *vpl, const lightsurf_t *lightsurf, const vec_t &bouncelight_gate)
{
if (light_options.visapprox.value() == visapprox_t::RAYS &&
vpl->bounds.disjoint(lightsurf->extents.bounds, 0.001)) {
@ -1703,7 +1703,7 @@ SurfaceLight_SphereCull(const surfacelight_t *vpl, const lightsurf_t *lightsurf)
// Get light contribution
const qvec3f color = SurfaceLight_ColorAtDist(cfg, vpl->totalintensity, vpl->color, dist);
return qv::gate(color, 0.01f);
return qv::gate(color, (float) bouncelight_gate);
}
#if 0
@ -1824,9 +1824,10 @@ static void // mxd
LightFace_SurfaceLight(const mbsp_t *bsp, lightsurf_t *lightsurf, lightmapdict_t *lightmaps)
{
const settings::worldspawn_keys &cfg = *lightsurf->cfg;
const vec_t bouncelight_gate = 0.01 / light_options.bounceextra.value();
for (const surfacelight_t &vpl : GetSurfaceLights()) {
if (SurfaceLight_SphereCull(&vpl, lightsurf))
if (SurfaceLight_SphereCull(&vpl, lightsurf, bouncelight_gate))
continue;
raystream_occlusion_t &rs = lightsurf->occlusion_stream;
@ -1856,7 +1857,7 @@ LightFace_SurfaceLight(const mbsp_t *bsp, lightsurf_t *lightsurf, lightmapdict_t
dir /= dist;
const qvec3d indirect = GetSurfaceLighting(cfg, &vpl, dir, dist, lightsurf_normal);
if (!qv::gate(indirect, 0.01)) { // Each point contributes very little to the final result
if (!qv::gate(indirect, bouncelight_gate)) { // Each point contributes very little to the final result
rs.pushRay(i, pos, dir, dist, &indirect);
}
}