light: allow .wal_json metadata to contain "light": [ r, g, b ] to override emissive color
Use this to fix the "emissive lights" test case so it can run on CI without any texture data
This commit is contained in:
parent
efac0c5a31
commit
5d3fab75b6
|
|
@ -565,6 +565,18 @@ std::optional<texture_meta> load_wal_json_meta(
|
|||
meta.animation = json["animation"].get<std::string>();
|
||||
}
|
||||
|
||||
if (json.contains("color")) {
|
||||
auto &color = json["color"];
|
||||
|
||||
qvec3b color_vec = {
|
||||
color.at(0).get<int32_t>(),
|
||||
color.at(1).get<int32_t>(),
|
||||
color.at(2).get<int32_t>()
|
||||
};
|
||||
|
||||
meta.color_override = {color_vec};
|
||||
}
|
||||
|
||||
return meta;
|
||||
} catch (json::exception e) {
|
||||
logging::funcprint("{}, invalid JSON: {}\n", name, e.what());
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ struct texture_meta
|
|||
// extension that we pulled the pixels in from.
|
||||
std::optional<ext> extension;
|
||||
|
||||
// so .json metadata can set an emissive color when we don't have
|
||||
// texture data. Also useful to override the emissive color
|
||||
std::optional<qvec3b> color_override;
|
||||
|
||||
// Q2/WAL only
|
||||
surfflags_t flags{};
|
||||
contentflags_t contents{};
|
||||
|
|
|
|||
|
|
@ -1395,9 +1395,16 @@ static void AddTextureName(const std::string_view &textureName, const mbsp_t *bs
|
|||
tex.meta = std::move(texture_meta.value());
|
||||
}
|
||||
|
||||
tex.averageColor = img::calculate_average(tex.pixels);
|
||||
tex.width_scale = (float)tex.width / (float)tex.meta.width;
|
||||
tex.height_scale = (float)tex.height / (float)tex.meta.height;
|
||||
if (tex.meta.color_override) {
|
||||
tex.averageColor = *tex.meta.color_override;
|
||||
} else {
|
||||
tex.averageColor = img::calculate_average(tex.pixels);
|
||||
}
|
||||
|
||||
if (tex.meta.width && tex.meta.height) {
|
||||
tex.width_scale = (float)tex.width / (float)tex.meta.width;
|
||||
tex.height_scale = (float)tex.height / (float)tex.meta.height;
|
||||
}
|
||||
}
|
||||
|
||||
// Load all of the referenced textures from the BSP texinfos into
|
||||
|
|
@ -1460,9 +1467,16 @@ static void ConvertTextures(const mbsp_t *bsp)
|
|||
continue;
|
||||
}
|
||||
|
||||
tex.averageColor = img::calculate_average(tex.pixels);
|
||||
tex.width_scale = (float)tex.width / (float)tex.meta.width;
|
||||
tex.height_scale = (float)tex.height / (float)tex.meta.height;
|
||||
if (tex.meta.color_override) {
|
||||
tex.averageColor = *tex.meta.color_override;
|
||||
} else {
|
||||
tex.averageColor = img::calculate_average(tex.pixels);
|
||||
}
|
||||
|
||||
if (tex.meta.width && tex.meta.height) {
|
||||
tex.width_scale = (float)tex.width / (float)tex.meta.width;
|
||||
tex.height_scale = (float)tex.height / (float)tex.meta.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"contents": ["SOLID"],
|
||||
"flags": ["LIGHT"],
|
||||
"value": 1000,
|
||||
"color": [255, 128, 64]
|
||||
}
|
||||
|
|
@ -38,9 +38,11 @@ static testresults_t LoadTestmap(const std::filesystem::path &name, std::vector<
|
|||
{
|
||||
std::vector<std::string> light_args{
|
||||
"", // the exe path, which we're ignoring in this case
|
||||
"-nodefaultpaths" // in case test_quake2_maps_dir is pointing at a real Q2 install, don't
|
||||
// read texture data etc. from there - we want the tests to behave the same
|
||||
// during development as they do on CI (which doesn't have a Q2 install).
|
||||
"-nodefaultpaths", // in case test_quake2_maps_dir is pointing at a real Q2 install, don't
|
||||
// read texture data etc. from there - we want the tests to behave the same
|
||||
// during development as they do on CI (which doesn't have a Q2 install).
|
||||
"-path",
|
||||
wal_metadata_path.string()
|
||||
};
|
||||
for (auto &arg : extra_args) {
|
||||
light_args.push_back(arg);
|
||||
|
|
@ -163,7 +165,7 @@ TEST_CASE("emissive lights") {
|
|||
for (int y = 0; y < extents.height(); ++y) {
|
||||
auto sample = LM_Sample(&bsp, extents, face->lightofs, {x, y});
|
||||
INFO("sample ", x, ", ", y);
|
||||
//CHECK(sample[0] > 0);
|
||||
CHECK(sample[0] > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue