output all lightstyled lightmaps too

This commit is contained in:
Jonathan 2022-07-08 18:22:20 -04:00
parent 7f64c9dfeb
commit 8696c6ee56
1 changed files with 22 additions and 11 deletions

View File

@ -195,7 +195,7 @@ static faceextents_t get_face_extents(const mbsp_t &bsp, const bspxentries_t &bs
return { face, bsp, (float) nth_bit(reinterpret_cast<const char *>(bspx.at("LMSHIFT").data())[&face - bsp.dfaces.data()]) };
}
static std::optional<img::texture> get_lightmap_face(const mbsp_t &bsp, const bspxentries_t &bspx, const mface_t &face, bool use_bspx)
static std::optional<img::texture> get_lightmap_face(const mbsp_t &bsp, const bspxentries_t &bspx, const mface_t &face, int32_t style, bool use_bspx)
{
img::texture texture;
faceextents_t extents = get_face_extents(bsp, bspx, face, use_bspx);
@ -203,6 +203,11 @@ static std::optional<img::texture> get_lightmap_face(const mbsp_t &bsp, const bs
texture.meta.height = texture.height = extents.height();
texture.pixels.resize(texture.meta.width * texture.meta.height);
// FIXME: LMSTYLE & LMSTYLE16 support
if (face.styles[style] == INVALID_LIGHTSTYLE_OLD) {
return std::nullopt;
}
auto pixels = bsp.dlightdata.begin();
if (!use_bspx) {
@ -218,17 +223,21 @@ static std::optional<img::texture> get_lightmap_face(const mbsp_t &bsp, const bs
stream.seekg((&face - bsp.dfaces.data()) * sizeof(int32_t));
int32_t ofs;
stream >= ofs;
pixels += ofs;
if (ofs == -1) {
return std::nullopt;
}
pixels += ofs;
}
// FIXME: bspx lit?
const bool is_rgb = bsp.loadversion->game->has_rgb_lightmap;
pixels += (texture.pixels.size() * (is_rgb ? 3 : 1)) * style;
auto out_pixels = texture.pixels.begin();
const bool is_rgb = bsp.loadversion->game->has_rgb_lightmap;
for (size_t i = 0; i < texture.pixels.size(); i++) {
if (is_rgb) {
uint8_t r = *pixels++;
@ -268,7 +277,7 @@ static std::optional<std::string> generate_lightmap_atlas(const mbsp_t &bsp, con
rectangles.reserve(bsp.dfaces.size());
for (auto &face : bsp.dfaces) {
face_rect rect { &face, get_lightmap_face(bsp, bspx, face, use_bspx) };
face_rect rect { &face, get_lightmap_face(bsp, bspx, face, style, use_bspx) };
if (!rect.texture) {
continue;
@ -619,13 +628,15 @@ void serialize_bsp(const bspdata_t &bspdata, const mbsp_t &bsp, const fs::path &
}
// lightmap atlas
if (auto lm = generate_lightmap_atlas(bsp, bspdata.bspx.entries, 0, false)) {
j.emplace("lightmap", std::move(*lm));
}
for (int32_t i = 0; i < MAXLIGHTMAPS; i++) {
if (auto lm = generate_lightmap_atlas(bsp, bspdata.bspx.entries, i, false)) {
j.emplace(fmt::format("lightmap{}", i), std::move(*lm));
}
if (bspdata.bspx.entries.find("LMOFFSET") != bspdata.bspx.entries.end()) {
if (auto lm = generate_lightmap_atlas(bsp, bspdata.bspx.entries, 0, true)) {
j.emplace("bspx_lightmap", std::move(*lm));
if (bspdata.bspx.entries.find("LMOFFSET") != bspdata.bspx.entries.end()) {
if (auto lm = generate_lightmap_atlas(bsp, bspdata.bspx.entries, i, true)) {
j.emplace(fmt::format("bspx_lightmap{}", i), std::move(*lm));
}
}
}