From ad49d52b1cae31f8ed8beecfdb1ace69a9b109a5 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sun, 23 May 2021 21:42:14 +0200 Subject: [PATCH] Add cvars to sprite shadows progressively according to thing <-> floor distance This also adds the `r_actorspriteshadowalpha` and `r_actorspriteshadowfadeheight` cvars for greater control (only effective in hardware renderers). These are set to 0.5 and 0 by default, which means this fading behavior is disabled by default. When enabled, this has two benefits: - It becomes easier for the player to judge an entity's height since the shadow opacity now gives this information. - Entities that are far high above the ground no longer cast a shadow, which looked strange. --- src/rendering/hwrenderer/scene/hw_sprites.cpp | 10 ++++++++-- src/rendering/r_utility.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index c11878c11..b98b9b03c 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -67,7 +67,8 @@ const float LARGE_VALUE = 1e19f; EXTERN_CVAR(Bool, r_debug_disable_vis_filter) EXTERN_CVAR(Float, transsouls) - +EXTERN_CVAR(Float, r_actorspriteshadowalpha) +EXTERN_CVAR(Float, r_actorspriteshadowfadeheight) //========================================================================== // @@ -1174,7 +1175,12 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t { RenderStyle = STYLE_Stencil; ThingColor = MAKEARGB(255, 0, 0, 0); - trans *= 0.5f; + // fade shadow progressively as the thing moves higher away from the floor + if (r_actorspriteshadowfadeheight > 0.0) { + trans *= clamp(0.0f, float(r_actorspriteshadowalpha - (thingpos.Z - thing->floorz) * (1.0 / r_actorspriteshadowfadeheight)), float(r_actorspriteshadowalpha)); + } else { + trans *= r_actorspriteshadowalpha; + } hw_styleflags = STYLEHW_NoAlphaTest; } diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index 1fe4aa1da..1ce0df498 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -121,6 +121,20 @@ CUSTOM_CVARD(Float, r_actorspriteshadowdist, 1500.0, CVAR_ARCHIVE | CVAR_GLOBALC else if (self > 8192.f) self = 8192.f; } +CUSTOM_CVARD(Float, r_actorspriteshadowalpha, 0.5, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "maximum sprite shadow opacity, only effective with hardware renderers (0.0 = fully transparent, 1.0 = opaque)") +{ + if (self < 0.f) + self = 0.f; + else if (self > 1.f) + self = 1.f; +} +CUSTOM_CVARD(Float, r_actorspriteshadowfadeheight, 0.0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "distance over which sprite shadows should fade, only effective with hardware renderers (0 = infinite)") +{ + if (self < 0.f) + self = 0.f; + else if (self > 8192.f) + self = 8192.f; +} int viewwindowx; int viewwindowy;