Merge branch 'brushbsp' of https://github.com/ericwa/ericw-tools into brushbsp

This commit is contained in:
Jonathan 2023-06-20 19:36:15 -04:00
commit db4a205537
2 changed files with 33 additions and 26 deletions

View File

@ -93,7 +93,7 @@ testresults_t QbspVisLight_Q2(
return QbspVisLight_Common(name, {"-q2bsp"}, extra_light_args, run_vis); return QbspVisLight_Common(name, {"-q2bsp"}, extra_light_args, run_vis);
} }
TEST_CASE("-world_units_per_luxel, -lightgrid" * doctest::may_fail()) TEST_CASE("-world_units_per_luxel, -lightgrid")
{ {
auto [bsp, bspx] = QbspVisLight_Q2("q2_lightmap_custom_scale.map", {"-lightgrid"}); auto [bsp, bspx] = QbspVisLight_Q2("q2_lightmap_custom_scale.map", {"-lightgrid"});
@ -123,7 +123,6 @@ TEST_CASE("-world_units_per_luxel, -lightgrid" * doctest::may_fail())
{ {
INFO("sky gets an optimized lightmap"); INFO("sky gets an optimized lightmap");
// FIXME: this currently fails, see Face_IsLightmapped
auto *sky_face = BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {256, 240, 84}, {0, -1, 0}); auto *sky_face = BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {256, 240, 84}, {0, -1, 0});
CHECK(sky_face->styles[0] == 255); CHECK(sky_face->styles[0] == 255);
@ -529,7 +528,7 @@ TEST_CASE("light channel mask / dirt interaction")
CheckFaceLuxelAtPoint(&bsp, &bsp.dmodels[1], {19, 19, 19}, {1236, 1308, 960}); CheckFaceLuxelAtPoint(&bsp, &bsp.dmodels[1], {19, 19, 19}, {1236, 1308, 960});
} }
TEST_CASE("surface lights minlight") TEST_CASE("surface lights minlight" * doctest::may_fail())
{ {
auto [bsp, bspx, lit] = QbspVisLight_Q1("q1_surflight_minlight.map", {}); auto [bsp, bspx, lit] = QbspVisLight_Q1("q1_surflight_minlight.map", {});
@ -630,7 +629,7 @@ TEST_CASE("q2_light_origin_brush_shadow")
CheckFaceLuxelAtPoint(&bsp, &bsp.dmodels[0], {100, 100, 100}, at_origin); CheckFaceLuxelAtPoint(&bsp, &bsp.dmodels[0], {100, 100, 100}, at_origin);
} }
TEST_CASE("q2_surface_lights_culling") TEST_CASE("q2_surface_lights_culling" * doctest::may_fail())
{ {
auto [bsp, bspx] = QbspVisLight_Q2("q2_surface_lights_culling.map", {}); auto [bsp, bspx] = QbspVisLight_Q2("q2_surface_lights_culling.map", {});

View File

@ -20,7 +20,7 @@
#include <common/log.hh> #include <common/log.hh>
#include <vis/vis.hh> #include <vis/vis.hh>
#include <common/bsputils.hh> #include <common/bsputils.hh>
#include <common/parallel.hh>
/* /*
Some textures (sky, water, slime, lava) are considered ambien sound emiters. Some textures (sky, water, slime, lava) are considered ambien sound emiters.
@ -60,45 +60,51 @@ void CalcAmbientSounds(mbsp_t *bsp)
{ {
logging::funcheader(); logging::funcheader();
const mface_t *surf; // fast path for -noambient
const mtexinfo_t *info; if (vis_options.noambientsky.value() && vis_options.noambientwater.value() && vis_options.noambientslime.value() &&
int i, j, k, l; vis_options.noambientlava.value()) {
mleaf_t *leaf, *hit; for (int i = 0; i < portalleafs_real; i++) {
uint8_t *vis; mleaf_t *leaf = &bsp->dleafs[i + 1];
float d, maxd; for (int j = 0; j < NUM_AMBIENTS; j++) {
ambient_type_t ambient_type; leaf->ambient_level[j] = 0;
float dists[NUM_AMBIENTS]; }
float vol; }
return;
}
for (i = 0; i < portalleafs_real; i++) { logging::parallel_for(0, portalleafs_real, [&bsp](int i) {
leaf = &bsp->dleafs[i + 1]; mleaf_t *leaf = &bsp->dleafs[i + 1];
float dists[NUM_AMBIENTS];
// //
// clear ambients // clear ambients
// //
for (j = 0; j < NUM_AMBIENTS; j++) for (int j = 0; j < NUM_AMBIENTS; j++)
dists[j] = 1020; dists[j] = 1020;
uint8_t *vis;
if (portalleafs != portalleafs_real) { if (portalleafs != portalleafs_real) {
vis = &uncompressed[leaf->cluster * leafbytes_real]; vis = &uncompressed[leaf->cluster * leafbytes_real];
} else { } else {
vis = &uncompressed[i * leafbytes_real]; vis = &uncompressed[i * leafbytes_real];
} }
for (j = 0; j < portalleafs_real; j++) { for (int j = 0; j < portalleafs_real; j++) {
if (!(vis[j >> 3] & nth_bit(j & 7))) if (!(vis[j >> 3] & nth_bit(j & 7)))
continue; continue;
// //
// check this leaf for sound textures // check this leaf for sound textures
// //
hit = &bsp->dleafs[j + 1]; mleaf_t *hit = &bsp->dleafs[j + 1];
for (k = 0; k < hit->nummarksurfaces; k++) { for (int k = 0; k < hit->nummarksurfaces; k++) {
surf = BSP_GetFace(bsp, bsp->dleaffaces[hit->firstmarksurface + k]); const mface_t *surf = BSP_GetFace(bsp, bsp->dleaffaces[hit->firstmarksurface + k]);
info = &bsp->texinfo[surf->texinfo]; const mtexinfo_t *info = &bsp->texinfo[surf->texinfo];
const auto &miptex = bsp->dtex.textures[info->miptex]; const auto &miptex = bsp->dtex.textures[info->miptex];
ambient_type_t ambient_type;
if (!Q_strncasecmp(miptex.name.data(), "sky", 3) && !vis_options.noambientsky.value()) if (!Q_strncasecmp(miptex.name.data(), "sky", 3) && !vis_options.noambientsky.value())
ambient_type = AMBIENT_SKY; ambient_type = AMBIENT_SKY;
else if (!Q_strncasecmp(miptex.name.data(), "*water", 6) && !vis_options.noambientwater.value()) else if (!Q_strncasecmp(miptex.name.data(), "*water", 6) && !vis_options.noambientwater.value())
@ -114,8 +120,9 @@ void CalcAmbientSounds(mbsp_t *bsp)
// find distance from source leaf to polygon // find distance from source leaf to polygon
aabb3d bounds = SurfaceBBox(bsp, surf); aabb3d bounds = SurfaceBBox(bsp, surf);
maxd = 0; float maxd = 0;
for (l = 0; l < 3; l++) { for (int l = 0; l < 3; l++) {
float d;
if (bounds.mins()[l] > leaf->maxs[l]) if (bounds.mins()[l] > leaf->maxs[l])
d = bounds.mins()[l] - leaf->maxs[l]; d = bounds.mins()[l] - leaf->maxs[l];
else if (bounds.maxs()[l] < leaf->mins[l]) else if (bounds.maxs()[l] < leaf->mins[l])
@ -132,7 +139,8 @@ void CalcAmbientSounds(mbsp_t *bsp)
} }
} }
for (j = 0; j < NUM_AMBIENTS; j++) { for (int j = 0; j < NUM_AMBIENTS; j++) {
float vol;
if (dists[j] < 100) if (dists[j] < 100)
vol = 1.0; vol = 1.0;
else { else {
@ -142,7 +150,7 @@ void CalcAmbientSounds(mbsp_t *bsp)
} }
leaf->ambient_level[j] = (uint8_t)(vol * 255); leaf->ambient_level[j] = (uint8_t)(vol * 255);
} }
} });
} }
/* /*