From 345a0978c64f9019724ac6f6d0f2a1d9cc5ef2d1 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Sun, 13 Aug 2023 02:35:06 +0100 Subject: [PATCH] Fix rtlights with decoupled lightmaps. --- engine/gl/gl_shadow.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/engine/gl/gl_shadow.c b/engine/gl/gl_shadow.c index 59a5a2b41..b07657f62 100644 --- a/engine/gl/gl_shadow.c +++ b/engine/gl/gl_shadow.c @@ -1010,6 +1010,8 @@ static void SHM_RecursiveWorldNodeQ2_r (dlight_t *dl, mnode_t *node) float l, maxdist; int j, s, t; vec3_t impact; + vec4_t *lmvecs; + float *lmvecscale; if (node->shadowframe != sh_shadowframe) return; @@ -1120,13 +1122,17 @@ static void SHM_RecursiveWorldNodeQ2_r (dlight_t *dl, mnode_t *node) for (j=0 ; j<3 ; j++) impact[j] = dl->origin[j] - surf->plane->normal[j]*dot; + if (currentmodel->facelmvecs) + lmvecs = currentmodel->facelmvecs[surf-currentmodel->surfaces].lmvecs, lmvecscale = currentmodel->facelmvecs[surf-currentmodel->surfaces].lmvecscale; + else + lmvecs = surf->texinfo->vecs, lmvecscale = surf->texinfo->vecscale; // clamp center of light to corner and check brightness - l = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0]; + l = DotProduct (impact, lmvecs[0]) + lmvecs[0][3] - surf->texturemins[0]; s = l;if (s < 0) s = 0;else if (s > surf->extents[0]) s = surf->extents[0]; - s = (l - s)*surf->texinfo->vecscale[0]; - l = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1]; + s = (l - s)*lmvecscale[0]; + l = DotProduct (impact, lmvecs[1]) + lmvecs[1][3] - surf->texturemins[1]; t = l;if (t < 0) t = 0;else if (t > surf->extents[1]) t = surf->extents[1]; - t = (l - t)*surf->texinfo->vecscale[1]; + t = (l - t)*lmvecscale[1]; // compare to minimum light if ((s*s+t*t+dot*dot) < maxdist) {