diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e0851af85..2bf7025ec 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3614,6 +3614,7 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale) FBITFIELD blendmode = PF_Translucent|PF_Modulated; INT32 shader = SHADER_DEFAULT; UINT8 i; + INT32 heightsec, phs; SINT8 flip = P_MobjFlip(thing); INT32 light; @@ -3626,7 +3627,23 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale) groundz = R_GetShadowZ(thing, &groundslope); - //if (abs(groundz - gl_viewz) / tz > 4) return; // Prevent stretchy shadows and possible crashes + heightsec = thing->subsector->sector->heightsec; + if (viewplayer->mo && viewplayer->mo->subsector) + phs = viewplayer->mo->subsector->sector->heightsec; + else + phs = -1; + + if (heightsec != -1 && phs != -1) // only clip things which are in special sectors + { + if (gl_viewz < FIXED_TO_FLOAT(sectors[phs].floorheight) ? + thing->z >= sectors[heightsec].floorheight : + thing->z < sectors[heightsec].floorheight) + return; + if (gl_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? + thing->z < sectors[heightsec].ceilingheight && gl_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : + thing->z >= sectors[heightsec].ceilingheight) + return; + } floordiff = abs((flip < 0 ? thing->height : 0) + thing->z - groundz); @@ -5259,13 +5276,19 @@ static void HWR_ProjectSprite(mobj_t *thing) if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { + float top = gzt; + float bottom = FIXED_TO_FLOAT(thing->z); + + if (R_ThingIsFloorSprite(thing)) + top = bottom; + if (gl_viewz < FIXED_TO_FLOAT(sectors[phs].floorheight) ? - FIXED_TO_FLOAT(thing->z) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : - gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) + bottom >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : + top < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) return; if (gl_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? - gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gl_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : - FIXED_TO_FLOAT(thing->z) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) + top < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gl_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : + bottom >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) return; } diff --git a/src/r_things.c b/src/r_things.c index ea57e4086..6c510c68d 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1265,6 +1265,7 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, vissprite_t *shadow; patch_t *patch; fixed_t xscale, yscale, shadowxscale, shadowyscale, shadowskew, x1, x2; + INT32 heightsec, phs; INT32 light = 0; fixed_t scalemul; UINT8 trans; fixed_t floordiff; @@ -1276,6 +1277,24 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, if (abs(groundz-viewz)/tz > 4) return; // Prevent stretchy shadows and possible crashes + heightsec = thing->subsector->sector->heightsec; + if (viewplayer->mo && viewplayer->mo->subsector) + phs = viewplayer->mo->subsector->sector->heightsec; + else + phs = -1; + + if (heightsec != -1 && phs != -1) // only clip things which are in special sectors + { + if (viewz < sectors[phs].floorheight ? + groundz >= sectors[heightsec].floorheight : + groundz < sectors[heightsec].floorheight) + return; + if (viewz > sectors[phs].ceilingheight ? + groundz < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : + groundz >= sectors[heightsec].ceilingheight) + return; + } + floordiff = abs((isflipped ? thing->height : 0) + thing->z - groundz); trans = floordiff / (100*FRACUNIT) + 3; @@ -1926,13 +1945,19 @@ static void R_ProjectSprite(mobj_t *thing) if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { + fixed_t top = gzt; + fixed_t bottom = thing->z; + + if (splat) + top = bottom; + if (viewz < sectors[phs].floorheight ? - thing->z >= sectors[heightsec].floorheight : - gzt < sectors[heightsec].floorheight) + bottom >= sectors[heightsec].floorheight : + top < sectors[heightsec].floorheight) return; if (viewz > sectors[phs].ceilingheight ? - gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : - thing->z >= sectors[heightsec].ceilingheight) + top < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : + bottom >= sectors[heightsec].ceilingheight) return; } @@ -2801,6 +2826,57 @@ static void R_DrawPrecipitationSprite(vissprite_t *spr) R_DrawPrecipitationVisSprite(spr); } +//SoM: 3/17/2000: Clip sprites in water. +static void R_HeightSecClip(vissprite_t *spr, INT32 x1, INT32 x2) +{ + fixed_t mh, h; + INT32 x, phs; + + if (spr->heightsec == -1) + return; + + if (spr->cut & (SC_SPLAT | SC_SHADOW) || spr->renderflags & RF_SHADOWDRAW) + return; + + phs = viewplayer->mo->subsector->sector->heightsec; + + if ((mh = sectors[spr->heightsec].floorheight) > spr->gz && + (h = centeryfrac - FixedMul(mh -= viewz, spr->sortscale)) >= 0 && + (h >>= FRACBITS) < viewheight) + { + if (mh <= 0 || (phs != -1 && viewz > sectors[phs].floorheight)) + { // clip bottom + for (x = x1; x <= x2; x++) + if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + spr->clipbot[x] = (INT16)h; + } + else // clip top + { + for (x = x1; x <= x2; x++) + if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + spr->cliptop[x] = (INT16)h; + } + } + + if ((mh = sectors[spr->heightsec].ceilingheight) < spr->gzt && + (h = centeryfrac - FixedMul(mh-viewz, spr->sortscale)) >= 0 && + (h >>= FRACBITS) < viewheight) + { + if (phs != -1 && viewz >= sectors[phs].ceilingheight) + { // clip bottom + for (x = x1; x <= x2; x++) + if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + spr->clipbot[x] = (INT16)h; + } + else // clip top + { + for (x = x1; x <= x2; x++) + if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + spr->cliptop[x] = (INT16)h; + } + } +} + // R_ClipVisSprite // Clips vissprites without drawing, so that portals can work. -Red void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, drawseg_t* dsstart, portal_t* portal) @@ -2902,47 +2978,9 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, drawseg_t* dsstart, p } } } - //SoM: 3/17/2000: Clip sprites in water. - if (spr->heightsec != -1) // only things in specially marked sectors - { - fixed_t mh, h; - INT32 phs = viewplayer->mo->subsector->sector->heightsec; - if ((mh = sectors[spr->heightsec].floorheight) > spr->gz && - (h = centeryfrac - FixedMul(mh -= viewz, spr->sortscale)) >= 0 && - (h >>= FRACBITS) < viewheight) - { - if (mh <= 0 || (phs != -1 && viewz > sectors[phs].floorheight)) - { // clip bottom - for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) - spr->clipbot[x] = (INT16)h; - } - else // clip top - { - for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) - spr->cliptop[x] = (INT16)h; - } - } - if ((mh = sectors[spr->heightsec].ceilingheight) < spr->gzt && - (h = centeryfrac - FixedMul(mh-viewz, spr->sortscale)) >= 0 && - (h >>= FRACBITS) < viewheight) - { - if (phs != -1 && viewz >= sectors[phs].ceilingheight) - { // clip bottom - for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) - spr->clipbot[x] = (INT16)h; - } - else // clip top - { - for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) - spr->cliptop[x] = (INT16)h; - } - } - } + R_HeightSecClip(spr, x1, x2); + if (spr->cut & SC_TOP && spr->cut & SC_BOTTOM) { for (x = x1; x <= x2; x++)