From 9abdb855f91b2e81aed830bc37f5cf5a102305cc Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 2 Nov 2020 02:33:49 -0800 Subject: [PATCH 1/3] Check that top of sprite is above plane or bottom is below This fixes slightly raised fofs drawing on top of sprites that should be in front of them. Previously would check that the bottom of the object was above the plane. Now also uses sprite offsets like the fof seg sorting does. --- src/r_things.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index fd200cf87..01aa8f23a 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2425,19 +2425,15 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps planeobjectz = P_GetZAt(r2->plane->slope, rover->gx, rover->gy, r2->plane->height); planecameraz = P_GetZAt(r2->plane->slope, viewx, viewy, r2->plane->height); - if (rover->mobjflags & MF_NOCLIPHEIGHT) + // bird: if any part of the sprite peeks in front the plane + if (planecameraz < viewz) { - //Objects with NOCLIPHEIGHT can appear halfway in. - if (planecameraz < viewz && rover->pz+(rover->thingheight/2) >= planeobjectz) - continue; - if (planecameraz > viewz && rover->pzt-(rover->thingheight/2) <= planeobjectz) + if (rover->gzt >= planeobjectz) continue; } - else + else if (planecameraz > viewz) { - if (planecameraz < viewz && rover->pz >= planeobjectz) - continue; - if (planecameraz > viewz && rover->pzt <= planeobjectz) + if (rover->gz <= planeobjectz) continue; } From 263a11e62f4d5e4a7c5a9dd99a130e2559964636 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 2 Nov 2020 03:37:16 -0800 Subject: [PATCH 2/3] Remove unused stuff --- src/r_things.c | 20 +------------------- src/r_things.h | 4 +--- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 01aa8f23a..9702c7d3f 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1074,14 +1074,6 @@ static void R_SplitSprite(vissprite_t *sprite) sprite->sz = cutfrac; newsprite->szt = (INT16)(sprite->sz - 1); - if (testheight < sprite->pzt && testheight > sprite->pz) - sprite->pz = newsprite->pzt = testheight; - else - { - newsprite->pz = newsprite->gz; - newsprite->pzt = newsprite->gzt; - } - newsprite->szt -= 8; newsprite->cut |= SC_TOP; @@ -1305,16 +1297,12 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, shadow->patch = patch; shadow->heightsec = vis->heightsec; - shadow->thingheight = FRACUNIT; - shadow->pz = groundz + (isflipped ? -shadow->thingheight : 0); - shadow->pzt = shadow->pz + shadow->thingheight; - shadow->mobjflags = 0; shadow->sortscale = vis->sortscale; shadow->dispoffset = vis->dispoffset - 5; shadow->gx = thing->x; shadow->gy = thing->y; - shadow->gzt = (isflipped ? shadow->pzt : shadow->pz) + SHORT(patch->height) * shadowyscale / 2; + shadow->gzt = groundz + SHORT(patch->height) * shadowyscale / 2; shadow->gz = shadow->gzt - SHORT(patch->height) * shadowyscale; shadow->texturemid = FixedMul(thing->scale, FixedDiv(shadow->gzt - viewz, shadowyscale)); if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) @@ -1812,9 +1800,6 @@ static void R_ProjectSprite(mobj_t *thing) vis->gy = thingypos; vis->gz = gz; vis->gzt = gzt; - vis->thingheight = thing->height; - vis->pz = thingzpos; - vis->pzt = vis->pz + vis->thingheight; vis->texturemid = vis->gzt - viewz; vis->scalestep = scalestep; vis->paperoffset = paperoffset; @@ -2032,9 +2017,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->gy = thing->y; vis->gz = gz; vis->gzt = gzt; - vis->thingheight = 4*FRACUNIT; - vis->pz = thing->z; - vis->pzt = vis->pz + vis->thingheight; vis->texturemid = vis->gzt - viewz; vis->scalestep = 0; vis->paperdistance = 0; diff --git a/src/r_things.h b/src/r_things.h index b6e8a1d9d..400a63bcb 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -138,8 +138,7 @@ typedef struct vissprite_s INT32 x1, x2; fixed_t gx, gy; // for line side calculation - fixed_t gz, gzt; // global bottom/top for silhouette clipping - fixed_t pz, pzt; // physical bottom/top for sorting with 3D floors + fixed_t gz, gzt; // global bottom/top for silhouette clipping and sorting with 3D floors fixed_t startfrac; // horizontal position of x1 fixed_t scale, sortscale; // sortscale only differs from scale for paper sprites and MF2_LINKDRAW @@ -171,7 +170,6 @@ typedef struct vissprite_s fixed_t xscale; // Precalculated top and bottom screen coords for the sprite. - fixed_t thingheight; // The actual height of the thing (for 3D floors) sector_t *sector; // The sector containing the thing. INT16 sz, szt; From 0d6f329b1d9ecf3ba754a5affe80c669c56afc07 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 2 Nov 2020 17:54:51 -0800 Subject: [PATCH 3/3] Do not sort sprite in front of plane if plane should render in front of sprite's plane Say you have a higher plane in the foreground and a lower one behind. And then insert a sprite above the plane in the background, the top of which is higher than the height in the foreground. Should the sprite be drawn in front of the foreground plane? I think not. Sprites drawing in front of a plane if only part of them is above the plane is a rendering trick that allows sprites to extend into the floor. This doesn't make sense if the plane they extend into would be obscured anyway, or if they don't extend into the plane at all. --- src/r_things.c | 37 +++++++++++++++++++++++++++++++++++-- src/r_things.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 9702c7d3f..df1946ba6 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1230,6 +1230,32 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope) return groundz; } +static void R_SetSpritePlaneHeights(vissprite_t *vis) +{ + ffloor_t *rover; + + fixed_t top; + fixed_t bot; + + vis->pt = vis->sector->floorheight; + vis->pb = vis->sector->ceilingheight; + + for (rover = vis->sector->ffloors; rover; rover = rover->next) + { + if (rover->flags & FF_EXISTS) + { + top = P_GetFFloorTopZAt (rover, vis->gx, vis->gy); + bot = P_GetFFloorBottomZAt (rover, vis->gx, vis->gy); + + if (top <= vis->gzt && top > vis->pt) + vis->pt = top; + + if (bot >= vis->gz && bot < vis->pb) + vis->pb = bot; + } + } +} + static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, fixed_t tx, fixed_t tz) { vissprite_t *shadow; @@ -1318,6 +1344,8 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, shadow->xscale = FixedMul(xscale, shadowxscale); //SoM: 4/17/2000 shadow->scale = FixedMul(yscale, shadowyscale); shadow->sector = vis->sector; + shadow->pt = vis->pt; + shadow->pb = vis->pb; shadow->szt = (INT16)((centeryfrac - FixedMul(shadow->gzt - viewz, yscale))>>FRACBITS); shadow->sz = (INT16)((centeryfrac - FixedMul(shadow->gz - viewz, yscale))>>FRACBITS); shadow->cut = SC_ISSCALED|SC_SHADOW; //check this @@ -1817,6 +1845,9 @@ static void R_ProjectSprite(mobj_t *thing) vis->sector = thing->subsector->sector; vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, sortscale))>>FRACBITS); + + R_SetSpritePlaneHeights(vis); + vis->cut = cut; if (thing->subsector->sector->numlights) vis->extra_colormap = *thing->subsector->sector->lightlist[light].extra_colormap; @@ -2031,6 +2062,8 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, yscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, yscale))>>FRACBITS); + R_SetSpritePlaneHeights(vis); + iscale = FixedDiv(FRACUNIT, xscale); vis->startfrac = 0; @@ -2410,12 +2443,12 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps // bird: if any part of the sprite peeks in front the plane if (planecameraz < viewz) { - if (rover->gzt >= planeobjectz) + if (rover->pt >= planeobjectz && rover->gzt >= planeobjectz) continue; } else if (planecameraz > viewz) { - if (rover->gz <= planeobjectz) + if (rover->pb <= planeobjectz && rover->gz <= planeobjectz) continue; } diff --git a/src/r_things.h b/src/r_things.h index 400a63bcb..f95cd5c9e 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -171,6 +171,7 @@ typedef struct vissprite_s // Precalculated top and bottom screen coords for the sprite. sector_t *sector; // The sector containing the thing. + fixed_t pt, pb; // plane heights, also for sorting against 3D floors INT16 sz, szt; spritecut_e cut;