From 3d68b1247362d1a261f848d3614723e6815d228b Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 16 Mar 2024 15:07:18 -0600 Subject: [PATCH] light: never write .lit/.lux in Q2 mode fixes `-dirtdebug` broken in lightpreview --- light/write.cc | 33 ++++++++++++++++++--------------- tests/test_ltface.cc | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/light/write.cc b/light/write.cc index 79d735f3..6d5c83ed 100644 --- a/light/write.cc +++ b/light/write.cc @@ -1094,19 +1094,22 @@ 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?*/ - if (light_options.write_litfile & lightfile::external) { - WriteLitFile(bsp, faces_sup, source, LIT_VERSION, lit_filebase, lux_filebase); + // 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); + } + if (light_options.write_litfile & lightfile::bspx) { + lit_filebase.resize(bsp->dlightdata.size() * 3); + bspdata->bspx.transfer("RGBLIGHTING", lit_filebase); + } + if (light_options.write_luxfile & lightfile::external) { + WriteLuxFile(bsp, source, LIT_VERSION, lux_filebase); + } + if (light_options.write_luxfile & lightfile::bspx) { + lux_filebase.resize(bsp->dlightdata.size() * 3); + bspdata->bspx.transfer("LIGHTINGDIR", lux_filebase); + } } - if (light_options.write_litfile & lightfile::bspx) { - lit_filebase.resize(bsp->dlightdata.size() * 3); - bspdata->bspx.transfer("RGBLIGHTING", lit_filebase); - } - if (light_options.write_luxfile & lightfile::external) { - WriteLuxFile(bsp, source, LIT_VERSION, lux_filebase); - } - if (light_options.write_luxfile & lightfile::bspx) { - lux_filebase.resize(bsp->dlightdata.size() * 3); - bspdata->bspx.transfer("LIGHTINGDIR", lux_filebase); - } -} \ No newline at end of file +} diff --git a/tests/test_ltface.cc b/tests/test_ltface.cc index 5121250b..630b05e5 100644 --- a/tests/test_ltface.cc +++ b/tests/test_ltface.cc @@ -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");