light: implement -novanilla with -world_units_per_luxel
currently it's required because the non-novanilla path isn't yet implemented
This commit is contained in:
parent
629f86625e
commit
c6b19fe6da
|
|
@ -2848,13 +2848,15 @@ void SaveLightmapSurface(const mbsp_t *bsp, mface_t *face, facesup_t *facesup,
|
|||
lightofs = out - filebase.data();
|
||||
}
|
||||
|
||||
if (facesup) {
|
||||
if (facesup_decoupled && light_options.novanilla.value()) {
|
||||
facesup_decoupled->offset = lightofs;
|
||||
face->lightofs = -1;
|
||||
} else if (facesup_decoupled && !light_options.novanilla.value()) {
|
||||
FError("-world_units_per_luxel currently requires -novanilla");
|
||||
} else if (facesup) {
|
||||
facesup->lightofs = lightofs;
|
||||
} else {
|
||||
face->lightofs = lightofs;
|
||||
if (facesup_decoupled) {
|
||||
facesup_decoupled->offset = lightofs;
|
||||
}
|
||||
}
|
||||
|
||||
// sanity check that we don't save a lightmap for a non-lightmapped face
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ static testresults_t LoadTestmap(const std::filesystem::path &name, std::vector<
|
|||
}
|
||||
|
||||
TEST_CASE("TestLight") {
|
||||
LoadTestmap("q2_lightmap_custom_scale.map", {"-threads", "1", "-world_units_per_luxel", "8"});
|
||||
LoadTestmap("q2_lightmap_custom_scale.map", {"-threads", "1", "-world_units_per_luxel", "8", "-novanilla"});
|
||||
}
|
||||
|
||||
TEST_CASE("emissive cube artifacts") {
|
||||
|
|
@ -80,7 +80,7 @@ TEST_CASE("emissive cube artifacts") {
|
|||
//
|
||||
// "_surflight_rescale" "0"
|
||||
//
|
||||
auto [bsp, bspx] = LoadTestmap("light_q2_emissive_cube.map", {"-threads", "1", "-world_units_per_luxel", "4"});
|
||||
auto [bsp, bspx] = LoadTestmap("light_q2_emissive_cube.map", {"-threads", "1", "-world_units_per_luxel", "4", "-novanilla"});
|
||||
|
||||
const auto start = qvec3d{1044, -1244, 880};
|
||||
const auto end = qvec3d{1044, -1272, 880};
|
||||
|
|
@ -107,3 +107,43 @@ TEST_CASE("emissive cube artifacts") {
|
|||
previous_sample = sample;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("-novanilla + -world_units_per_luxel")
|
||||
{
|
||||
auto [bsp, bspx] = LoadTestmap("q2_lightmap_custom_scale.map", {"-novanilla", "-world_units_per_luxel", "8"});
|
||||
|
||||
for (auto &face : bsp.dfaces) {
|
||||
CHECK(face.lightofs == -1);
|
||||
}
|
||||
|
||||
// make sure no other bspx lumps are written
|
||||
CHECK(bspx.size() == 1);
|
||||
CHECK(bspx.find("DECOUPLED_LM") != bspx.end());
|
||||
|
||||
// make sure all dlightdata bytes are accounted for by the DECOUPLED_LM lump
|
||||
// and no extra was written.
|
||||
size_t expected_dlightdata_bytes = 0;
|
||||
for (auto &face : bsp.dfaces) {
|
||||
// count used styles
|
||||
size_t face_used_styles = 0;
|
||||
for (auto style : face.styles) {
|
||||
if (style != 255) {
|
||||
++face_used_styles;
|
||||
}
|
||||
}
|
||||
|
||||
// count used pixels per style
|
||||
auto lm_info = BSPX_DecoupledLM(bspx, Face_GetNum(&bsp, &face));
|
||||
const faceextents_t extents(face, bsp, lm_info.lmwidth, lm_info.lmheight, lm_info.world_to_lm_space);
|
||||
int samples_per_face = extents.numsamples() * face_used_styles;
|
||||
|
||||
// round up to multiple of 4
|
||||
if (samples_per_face % 4) {
|
||||
samples_per_face += (4 - (samples_per_face % 4));
|
||||
}
|
||||
|
||||
int bytes_per_face = 3 * samples_per_face;
|
||||
expected_dlightdata_bytes += bytes_per_face;
|
||||
}
|
||||
CHECK(bsp.dlightdata.size() == expected_dlightdata_bytes);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue