- tweaked shadow code a bit.

* let CASTSPRITESHADOW act as an override for render style checks. If this is set we can assume that a shadow is desired regardless of style.
* reordered code to do the more costly checks only when needed.
This commit is contained in:
Christoph Oelckers 2021-07-02 09:12:26 +02:00
parent 5273ef360e
commit e82fd43313

View file

@ -1075,27 +1075,37 @@ CUSTOM_CVAR(Float, maxviewpitch, 90.f, CVAR_ARCHIVE | CVAR_SERVERINFO)
bool R_ShouldDrawSpriteShadow(AActor *thing) bool R_ShouldDrawSpriteShadow(AActor *thing)
{ {
auto rs = thing->RenderStyle; int rf = thing->renderflags;
rs.CheckFuzz(); // for wall and flat sprites the shadow math does not work so these must be unconditionally skipped.
// For non-standard render styles, draw no shadows. This will always look weird. if (rf & (RF_FLATSPRITE | RF_WALLSPRITE)) return false;
if (rs.BlendOp != STYLEOP_Add && rs.BlendOp != STYLEOP_Shadow) return false;
if (rs.DestAlpha != STYLEALPHA_Zero && rs.DestAlpha != STYLEALPHA_InvSrc) return false;
if (thing->renderflags & (RF_FLATSPRITE | RF_WALLSPRITE)) return false; // for wall and flat sprites the shadow math does not work.
bool doit = false;
switch (r_actorspriteshadow) switch (r_actorspriteshadow)
{ {
case 1: case 1:
return (thing->renderflags & RF_CASTSPRITESHADOW); doit = (rf & RF_CASTSPRITESHADOW);
break;
case 2: case 2:
if (thing->renderflags & RF_CASTSPRITESHADOW) doit = (rf & RF_CASTSPRITESHADOW) || (!(rf & RF_NOSPRITESHADOW) && ((thing->flags3 & MF3_ISMONSTER) || thing->player != nullptr));
{ break;
return true;
}
return (thing->renderflags & RF_CASTSPRITESHADOW) || (!(thing->renderflags & RF_NOSPRITESHADOW) && ((thing->flags3 & MF3_ISMONSTER) || thing->player != nullptr));
default: default:
case 0: break;
return false;
} }
if (doit)
{
auto rs = thing->RenderStyle;
rs.CheckFuzz();
// For non-standard render styles, draw no shadows. This will always look weird. However, if the sprite forces shadows, render them anyway.
if (!(rf & RF_CASTSPRITESHADOW))
{
if (rs.BlendOp != STYLEOP_Add && rs.BlendOp != STYLEOP_Shadow) return false;
if (rs.DestAlpha != STYLEALPHA_Zero && rs.DestAlpha != STYLEALPHA_InvSrc) return false;
}
}
return doit;
} }