Skip to content

Commit 45f68e0

Browse files
authored
gl_shadow.c: Fix Q2BSPs segfaulting with orthographic lights (#358)
1 parent 8596e6d commit 45f68e0

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

engine/gl/gl_shadow.c

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,65 @@ next:;
999999
#endif
10001000

10011001
#ifdef Q2BSPS
1002+
void CategorizePlane ( mplane_t *plane );
1003+
static void SHM_OrthoWorldLeafsQ2 (dlight_t *dl)
1004+
{
1005+
int c, i;
1006+
msurface_t *surf, **mark;
1007+
mleaf_t *pleaf, *plastleaf;
1008+
1009+
mplane_t orthoplanes[5];
1010+
1011+
sh_shadowframe++;
1012+
1013+
VectorCopy(dl->axis[0], orthoplanes[0].normal);
1014+
VectorNegate(dl->axis[0], orthoplanes[1].normal);
1015+
VectorCopy(dl->axis[1], orthoplanes[2].normal);
1016+
VectorNegate(dl->axis[1], orthoplanes[3].normal);
1017+
VectorNegate(dl->axis[0], orthoplanes[4].normal);
1018+
1019+
for (i = 0; i < countof(orthoplanes); i++)
1020+
{
1021+
orthoplanes[i].dist = DotProduct(dl->origin, orthoplanes[i].normal) - dl->radius;
1022+
CategorizePlane(&orthoplanes[i]);
1023+
}
1024+
1025+
for (pleaf = cl.worldmodel->leafs+1, plastleaf = cl.worldmodel->leafs+cl.worldmodel->numleafs; pleaf <= plastleaf; pleaf++)
1026+
{
1027+
for (i = 0; i < countof(orthoplanes); i++)
1028+
if (BOX_ON_PLANE_SIDE (pleaf->minmaxs, pleaf->minmaxs+3, &orthoplanes[i]) == 2)
1029+
goto next;
1030+
1031+
SHM_Shadow_Cache_Leaf(pleaf);
1032+
1033+
mark = pleaf->firstmarksurface;
1034+
c = pleaf->nummarksurfaces;
1035+
1036+
while (c --> 0)
1037+
{
1038+
surf = *mark++;
1039+
1040+
if (surf->flags & (SURF_DRAWALPHA | SURF_DRAWTILED | SURF_DRAWSKY))
1041+
continue;
1042+
1043+
if (surf->shadowframe != sh_shadowframe)
1044+
{
1045+
surf->shadowframe = sh_shadowframe;
1046+
1047+
// if (dot < 0)
1048+
{
1049+
SHM_Shadow_Cache_Surface(surf);
1050+
}
1051+
// else
1052+
// SHM_MeshBackOnly(surf->mesh->numvertexes, surf->mesh->xyz_array, surf->mesh->numindexes, surf->mesh->indexes);
1053+
SHM_MeshFrontOnly(surf->mesh->numvertexes, surf->mesh->xyz_array, surf->mesh->numindexes, surf->mesh->indexes);
1054+
}
1055+
}
1056+
1057+
next:;
1058+
}
1059+
}
1060+
10021061
static void SHM_RecursiveWorldNodeQ2_r (dlight_t *dl, mnode_t *node)
10031062
{
10041063
int c, side;
@@ -1254,8 +1313,14 @@ static void SHM_MarkLeavesQ2(dlight_t *dl, const unsigned char *lvis)
12541313
}
12551314
void Q2BSP_GenerateShadowMesh(model_t *model, dlight_t *dl, const qbyte *lightvis, qbyte *litvis, void (*callback)(msurface_t *surf))
12561315
{
1257-
SHM_MarkLeavesQ2(dl, lightvis);
1258-
SHM_RecursiveWorldNodeQ2_r(dl, model->nodes);
1316+
genshadowmapcallback = callback;
1317+
if (sh_shmesh->type == SMT_ORTHO)
1318+
SHM_OrthoWorldLeafsQ2(dl);
1319+
else
1320+
{
1321+
SHM_MarkLeavesQ2(dl, lightvis);
1322+
SHM_RecursiveWorldNodeQ2_r(dl, model->nodes);
1323+
}
12591324
}
12601325
#endif
12611326

0 commit comments

Comments
 (0)