faceextents_t: refactor to remove lightmapshift member

This commit is contained in:
Eric Wasylishen 2022-11-02 00:56:23 -06:00
parent c39ee38454
commit f3cc0907c8
3 changed files with 29 additions and 4 deletions

View File

@ -682,7 +682,7 @@ qmat4x4f TexSpaceToWorld(const mbsp_t *bsp, const mface_t *f)
// faceextents_t
faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, float lmshift) : lightmapshift(lmshift)
faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, float lightmapshift)
{
worldToTexCoordMatrix = WorldToTexSpace(&bsp, &face);
texCoordToWorldMatrix = TexSpaceToWorld(&bsp, &face);
@ -731,6 +731,13 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, float lmshi
origin = bounds.mins() + radius;
this->radius = qv::length(radius);
LMToTexCoordMatrix = qmat3x3f::row_major({
lightmapshift, 0, texmins[0] * lightmapshift,
0 , lightmapshift, texmins[1] * lightmapshift,
0 , 0 , 1
});
TexCoordToLMMatrix = qv::inverse(LMToTexCoordMatrix);
}
int faceextents_t::width() const
@ -755,12 +762,16 @@ qvec2i faceextents_t::texsize() const
qvec2f faceextents_t::lightmapCoordToTexCoord(const qvec2f &LMCoord) const
{
return {lightmapshift * (texmins[0] + LMCoord[0]), lightmapshift * (texmins[1] + LMCoord[1])};
qvec3f LMCoordPadded = {LMCoord[0], LMCoord[1], 1.0f};
qvec2f tex = LMToTexCoordMatrix * LMCoordPadded;
return tex;
}
qvec2f faceextents_t::texCoordToLightmapCoord(const qvec2f &tc) const
{
return {(tc[0] / lightmapshift) - texmins[0], (tc[1] / lightmapshift) - texmins[1]};
qvec3f tcPadded = {tc[0], tc[1], 1.0f};
qvec2f lm = TexCoordToLMMatrix * tcPadded;
return lm;
}
qvec2f faceextents_t::worldToTexCoord(qvec3f world) const

View File

@ -125,9 +125,10 @@ class faceextents_t
public:
qvec2i texmins;
qvec2i texextents;
float lightmapshift;
qmat4x4f worldToTexCoordMatrix;
qmat4x4f texCoordToWorldMatrix;
qmat3x3f LMToTexCoordMatrix;
qmat3x3f TexCoordToLMMatrix;
qvec3d origin;
vec_t radius;

View File

@ -1,6 +1,7 @@
#include <doctest/doctest.h>
#include <light/light.hh>
#include <common/bspinfo.hh>
#include <qbsp/qbsp.hh>
#include <testmaps.hh>
@ -39,6 +40,18 @@ static void LoadTestmap(const std::filesystem::path &name, std::vector<std::stri
};
light_main(light_args);
}
// serialize obj
{
bspdata_t bspdata;
LoadBSPFile(bsp_path, &bspdata);
ConvertBSPFormat(&bspdata, &bspver_generic);
// write to .json for inspection
serialize_bsp(bspdata, std::get<mbsp_t>(bspdata.bsp),
fs::path(qbsp_options.bsp_path).replace_extension(".bsp.json"));
}
}
TEST_CASE("TestLight") {