light: never write .lit/.lux in Q2 mode

fixes `-dirtdebug` broken in lightpreview
This commit is contained in:
Eric Wasylishen 2024-03-16 15:07:18 -06:00
parent 40e4c71407
commit 3d68b12473
2 changed files with 41 additions and 15 deletions

View File

@ -1094,7 +1094,9 @@ void SaveLightmapSurfaces(bspdata_t *bspdata, const fs::path &source)
bspdata->bspx.entries.erase("RGBLIGHTING");
bspdata->bspx.entries.erase("LIGHTINGDIR");
/*fixme: add a new per-surface offset+lmscale lump for compat/versitility?*/
// lit/lux files (or their BSPX equivalents) - only write in games that lack RGB lightmaps.
// (technically we could allow .lux in Q2 mode, but no engines support it.)
if (!bsp->loadversion->game->has_rgb_lightmap) {
if (light_options.write_litfile & lightfile::external) {
WriteLitFile(bsp, faces_sup, source, LIT_VERSION, lit_filebase, lux_filebase);
}
@ -1109,4 +1111,5 @@ void SaveLightmapSurfaces(bspdata_t *bspdata, const fs::path &source)
lux_filebase.resize(bsp->dlightdata.size() * 3);
bspdata->bspx.transfer("LIGHTINGDIR", lux_filebase);
}
}
}

View File

@ -84,6 +84,13 @@ static testresults_t QbspVisLight_Common(const std::filesystem::path &name, std:
light_args.push_back(bsp_path.string());
light_main(light_args);
// ensure a .lit is never created in q2
if (is_q2) {
auto lit_check_path = bsp_path;
lit_check_path.replace_extension(".lit");
CHECK(!fs::exists(lit_check_path));
}
}
// serialize obj
@ -336,6 +343,7 @@ static void CheckFaceLuxelAtPoint(const mbsp_t *bsp, const dmodelh2_t *model, co
INFO("lm coord: ", coord[0], ", ", coord[1]);
INFO("lm int_coord: ", int_coord[0], ", ", int_coord[1]);
INFO("face num: ", Face_GetNum(bsp, face));
INFO("actual sample: ", sample[0], " ", sample[1], " ", sample[2]);
qvec3i delta = qv::abs(qvec3i{sample} - qvec3i{expected_color});
CHECK(delta[0] <= 1);
@ -392,6 +400,21 @@ TEST_CASE("q2_dirt")
CheckFaceLuxels(bsp, *face_under_lava, [](qvec3b sample) { CHECK(sample == qvec3b(96)); });
}
TEST_CASE("q2_dirtdebug")
{
INFO("dirtdebug works in q2");
auto [bsp, bspx] = QbspVisLight_Q2("q2_dirt.map", {"-dirtdebug"});
auto *face_under_lava = BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {104, 112, 48});
REQUIRE(face_under_lava);
CheckFaceLuxels(bsp, *face_under_lava, [](qvec3b sample) { CHECK(sample == qvec3b(255)); });
// check floor in the corner
CheckFaceLuxelAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0}, {-124, 300, 32});
}
TEST_CASE("q2_light_translucency")
{
INFO("liquids cast translucent colored shadows (sampling texture) by default");