mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 02:11:19 +00:00
[vulkan] Check leaf sky visibility for suns
And fix some out-by-one errors for leaf visibility (pvs index 0 is actually leaf index 1)
This commit is contained in:
parent
d5454faeb7
commit
590f0f18bc
3 changed files with 32 additions and 5 deletions
|
@ -272,6 +272,7 @@ typedef struct mod_brush_s {
|
|||
|
||||
mnode_t **node_parents;
|
||||
mnode_t **leaf_parents;
|
||||
int *leaf_flags; // union of surf flags for surfs in leaf
|
||||
|
||||
unsigned int checksum;
|
||||
unsigned int checksum2;
|
||||
|
|
|
@ -651,6 +651,20 @@ Mod_SetParent (mod_brush_t *brush, mnode_t *node, mnode_t *parent)
|
|||
Mod_SetParent (brush, node->children[1], node);
|
||||
}
|
||||
|
||||
static void
|
||||
Mod_SetLeafFlags (mod_brush_t *brush)
|
||||
{
|
||||
for (int i = 0; i < brush->numleafs; i++) {
|
||||
int flags = 0;
|
||||
mleaf_t *leaf = &brush->leafs[i];
|
||||
for (int j = 0; j < leaf->nummarksurfaces; j++) {
|
||||
msurface_t *surf = leaf->firstmarksurface[j];
|
||||
flags |= surf->flags;
|
||||
}
|
||||
brush->leaf_flags[i] = flags;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Mod_LoadNodes (model_t *mod, bsp_t *bsp)
|
||||
{
|
||||
|
@ -704,9 +718,12 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
|
|||
}
|
||||
|
||||
size_t size = (brush->numleafs + brush->numnodes) * sizeof (mnode_t *);
|
||||
size += brush->numleafs * sizeof (int);
|
||||
brush->node_parents = Hunk_AllocName (size, mod->name);
|
||||
brush->leaf_parents = brush->node_parents + brush->numnodes;
|
||||
brush->leaf_flags = (int *) (brush->leaf_parents + brush->numleafs);
|
||||
Mod_SetParent (brush, brush->nodes, NULL); // sets nodes and leafs
|
||||
Mod_SetLeafFlags (brush);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -81,12 +81,19 @@ find_visible_lights (vulkan_ctx_t *ctx)
|
|||
if (leaf != lframe->leaf) {
|
||||
//double start = Sys_DoubleTime ();
|
||||
byte pvs[MAP_PVS_BYTES];
|
||||
int flags = 0;
|
||||
|
||||
Mod_LeafPVS_set (leaf, model, 0, pvs);
|
||||
memcpy (lframe->pvs, pvs, sizeof (pvs));
|
||||
for (int i = 0; i < model->brush.numleafs; i++) {
|
||||
if (pvs[i / 8] & (1 << (i % 8))) {
|
||||
Mod_LeafPVS_mix (model->brush.leafs + i, model, 0, lframe->pvs);
|
||||
Mod_LeafPVS_mix (model->brush.leafs + i + 1, model, 0,
|
||||
lframe->pvs);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < model->brush.numleafs; i++) {
|
||||
if (lframe->pvs[i / 8] & (1 << (i % 8))) {
|
||||
flags |= model->brush.leaf_flags[i + 1];
|
||||
}
|
||||
}
|
||||
lframe->leaf = leaf;
|
||||
|
@ -98,8 +105,8 @@ find_visible_lights (vulkan_ctx_t *ctx)
|
|||
memset (lframe->lightvis.a, 0, lframe->lightvis.size * sizeof (byte));
|
||||
for (size_t i = 0; i < lctx->lightleafs.size; i++) {
|
||||
int l = lctx->lightleafs.a[i];
|
||||
//FIXME -1 needs check for sky
|
||||
if (l == -1 || lframe->pvs[l / 8] & (1 << (l % 8))) {
|
||||
if ((l == -1 && (flags & SURF_DRAWSKY))
|
||||
|| lframe->pvs[l / 8] & (1 << (l % 8))) {
|
||||
lframe->lightvis.a[i] = 1;
|
||||
visible++;
|
||||
}
|
||||
|
@ -646,8 +653,10 @@ Vulkan_LoadLights (model_t *model, const char *entity_data, vulkan_ctx_t *ctx)
|
|||
DARRAY_APPEND (&lctx->lights, light);
|
||||
mleaf_t *leaf = Mod_PointInLeaf (&light.position[0],
|
||||
model);
|
||||
DARRAY_APPEND (&lctx->lightleafs, leaf - model->brush.leafs);
|
||||
dump_light (&light, leaf - model->brush.leafs);
|
||||
DARRAY_APPEND (&lctx->lightleafs,
|
||||
leaf - model->brush.leafs - 1);
|
||||
dump_light (&light,
|
||||
lctx->lightleafs.a[lctx->lightleafs.size - 1]);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < ctx->frames.size; i++) {
|
||||
|
|
Loading…
Reference in a new issue