Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(shadows): keep windows' smoke map and drop the review's extras

Richard Louie Orilla20254d453697
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 60df29ea4..af5e282a2 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -4190,13 +4190,6 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
const Bool geometryShadows = TRUE;
const Bool captureShadows = m_shadowList != NULL;
#endif
- static bool modeReported = false;
- static SunShadow::Mode lastMode = SunShadow::Mode::Legacy;
- if (!modeReported || lastMode != mode) {
- fprintf(stderr, "SunShadow: requested %s\n", SunShadow::ModeName(mode));
- modeReported = true;
- lastMode = mode;
- }
/* The freecam asks for a map four times as wide and makes do with the usual one if refused. A
refusal is remembered until the freecam lands: asking again every frame released the usual
@@ -4211,8 +4204,7 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
const UnsignedInt chosenTexels = (SHADOW_MAP_TEXELS / 2) << TheGlobalData->m_shadowQuality;
UnsignedInt texels = chosenTexels;
Bool begun = FALSE;
- if (mode != SunShadow::Mode::Legacy && TheGlobalData->m_shadowMap && captureShadows && TheTacticalView != NULL
- && TheTerrainRenderObject != NULL && TheTerrainLogic != NULL && TheW3DShadowManager != NULL)
+ if (mode != SunShadow::Mode::Legacy && TheGlobalData->m_shadowMap && captureShadows && TheTacticalView != NULL)
{
if (wholeMap && !wholeMapRefused && SunShadow::Begin( DX8Wrapper::_Get_D3D_Device(), SHADOW_MAP_WHOLE_MAP_TEXELS ))
{
@@ -4458,13 +4450,21 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
// unbinds textures and flushes deferred states. The restored scene must be the last writer.
#if defined(__linux__)
DX8Wrapper::Invalidate_Cached_Render_States();
-#endif
const bool captured = SunShadow::End(DX8Wrapper::_Get_D3D_Device());
+#else
+ SunShadow::End(DX8Wrapper::_Get_D3D_Device()); // Direct3D 11 carries on whether or not it bound
+#endif
// The smoke goes into a map of its own through the sun the casters were just drawn with.
// past the map's limit the smoke nearest the camera wins: the freecam's box is centred on the
// map's middle, which is not where it is looking from
- if (mode == SunShadow::Mode::Mapped && captured)
+#if defined(__linux__)
+ const Bool fillSmoke = mode == SunShadow::Mode::Mapped && captured;
+#else
+ // Direct3D 11 fills the smoke map whether or not the depth capture bound, as it always has.
+ const Bool fillSmoke = TRUE;
+#endif
+ if (fillSmoke)
fillSmokeMap( transform, wholeMap ? sceneCamera.Get_Position() : focus, halfWidth, farClip );
else {
SunShadow::FillSmoke(DX8Wrapper::_Get_D3D_Device(), NULL, 0, 0.0f );
@@ -4518,9 +4518,15 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
strength = SHADOW_MAP_REFORGED_STRENGTH;
DX8Wrapper::Flush_Deferred_D3D9_State();
+#if defined(__linux__)
const bool receiving = captured && mode == SunShadow::Mode::Mapped
&& SunShadow::Parameters(DX8Wrapper::_Get_D3D_Device(), depthBias, strength, widest,
narrowest, penumbra / worldPerTexel, unitsPerUnitOfDepth, skyFill);
+#else
+ // Direct3D 11 takes the parameters whether or not the depth capture bound, as it always has.
+ const bool receiving = SunShadow::Parameters(DX8Wrapper::_Get_D3D_Device(), depthBias, strength, widest,
+ narrowest, penumbra / worldPerTexel, unitsPerUnitOfDepth, skyFill);
+#endif
/* Said last, and only on the way out: everything above can bail, and the volumes have to know
whether this frame's shadows are in the map or still theirs to draw. The count of casters is
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index f88b3aa43..c6ddd5b57 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -1255,7 +1255,8 @@ bool End(IDirect3DDevice9 *) {
Direct3D11_End_Shadow_Map();
return bound;
}
-void Clear(IDirect3DDevice9 *) { receiving = false; Direct3D11_Clear_Shadow_Parameters(); }
+// The pass's start only hands the frame back to the volumes, as theShadowMapHoldsTheFrame did.
+void Clear(IDirect3DDevice9 *) { receiving = false; }
bool Parameters(IDirect3DDevice9 *, float bias, float strength, float widest, float narrowest,
float texelsPerGap, float unitsPerDepth, float skyFill) {
if (!Direct3D11_Is_Active()) return false;