From 221ea65efbf2c87855c945351caca259a1efae96 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 3 Nov 2022 23:44:18 -0600 Subject: [PATCH] light: fix -world_units_per_luxel on sloped faces --- common/bsputils.cc | 10 ++++++---- light/ltface.cc | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/common/bsputils.cc b/common/bsputils.cc index 13aaeb95..3182bf50 100644 --- a/common/bsputils.cc +++ b/common/bsputils.cc @@ -746,6 +746,8 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, float light } faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, uint16_t lmwidth, uint16_t lmheight, texvecf world_to_lm_space) { + const qplane3f plane = Face_Plane(&bsp, &face); + if (lmwidth > 0 && lmheight > 0) { lm_extents = {lmwidth - 1, lmheight - 1}; } @@ -755,7 +757,7 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, uint16_t lm worldToLMMatrix.set_row(0, world_to_lm_space.row(0)); worldToLMMatrix.set_row(1, world_to_lm_space.row(1)); - worldToLMMatrix.set_row(2, {0, 0, 1, 0}); + worldToLMMatrix.set_row(2, qvec4f(plane.normal[0], plane.normal[1], plane.normal[2], -plane.dist)); worldToLMMatrix.set_row(3, {0, 0, 0, 1}); lmToWorldMatrix = qv::inverse(worldToLMMatrix); @@ -775,6 +777,7 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, uint16_t lm faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, world_units_per_luxel_t tag, float world_units_per_luxel) { + const qplane3f plane = Face_Plane(&bsp, &face); auto orig_normal = Face_Normal(&bsp, &face); size_t axis = qv::indexOfLargestMagnitudeComponent(orig_normal); @@ -795,10 +798,9 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, world_units t = t * (1/world_units_per_luxel); b = b * (1/world_units_per_luxel); - qmat world_to_lm; + qmat world_to_lm; world_to_lm.set_row(0, t); world_to_lm.set_row(1, b); - world_to_lm.set_row(2, snapped_normal); aabb2f lm_bounds; for (int i = 0; i < face.numedges; i++) { @@ -817,7 +819,7 @@ faceextents_t::faceextents_t(const mface_t &face, const mbsp_t &bsp, world_units worldToLMMatrix.set_row(0, qvec4f(world_to_lm.row(0), -lm_mins[0])); worldToLMMatrix.set_row(1, qvec4f(world_to_lm.row(1), -lm_mins[1])); - worldToLMMatrix.set_row(2, qvec4f(world_to_lm.row(2), 0)); + worldToLMMatrix.set_row(2, qvec4f(plane.normal[0], plane.normal[1], plane.normal[2], -plane.dist)); worldToLMMatrix.set_row(3, qvec4f(0, 0, 0, 1)); lmToWorldMatrix = qv::inverse(worldToLMMatrix); diff --git a/light/ltface.cc b/light/ltface.cc index 7844a3ad..91d95262 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -51,7 +51,7 @@ void PrintFaceInfo(const mface_t *face, const mbsp_t *bsp) const char *texname = Face_TextureName(bsp, face); logging::print("face {}, texture {}, {} edges; vectors:\n" - "{: 3.3}\n", + "{}\n", Face_GetNum(bsp, face), texname, face->numedges, tex->vecs); for (int i = 0; i < face->numedges; i++) {