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.

feat(options): shadow quality sets the sun's depth map size

Olcay Seyganacb0528e3123
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ed569ed1b..bd0241f3c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1379,6 +1379,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
covers.
- Fences, walls and props cast a real shaped shadow, worked out once.
- Each of these switches off in `GameData.ini`.
+- Shadow Quality on the launcher's Options page sets how sharp the shadows are. Medium is what the
+ game always drew. High doubles the detail for about 64 MB of video memory, and Low halves it to
+ free memory on a weak card, with the soft edges staying as wide as before at every level.
## Bright things can glow
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index fd1061dcc..4be4c9ae4 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -196,6 +196,7 @@ public:
Bool m_shadowsForParticles; // "ShadowsForParticles": big alpha-blended particle clouds drop a soft blob on the ground
Bool m_volumetricSmokeShadows; // "VolumetricSmokeShadows": smoke and dust shade the world and themselves through the sun's map (Direct3D 11)
Bool m_smokeFireLighting; // "SmokeFireLighting": smoke takes light from the fire beside it
+ Int m_shadowQuality; // "ShadowQuality": the sun's depth map at 1024, 2048 or 4096 texels a side (Direct3D 11)
Bool m_classicGraphics; // "ClassicGraphics": the game's own art, tile, shadows and picture; read at startup
Bool m_shadowMap; // "-shadowmap": draw the casters into the sun's depth buffer as well
Bool m_shadowMapReport; // "-shadowmapreport": log what ended up in that buffer, once a second
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h b/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
index b62b7e527..48897560f 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
@@ -143,6 +143,10 @@ enum { TEXTURE_FILTER_MODE_COUNT = 3 };
// stores the level; the thickness each level stands for is in OptionsCatalog.cpp.
enum { SMOKE_LEVEL_COUNT = 3 };
+// Shadow quality is the size of the sun's depth map, low, medium and high: 1024, 2048 and 4096
+// texels a side (W3DVolumetricShadow.cpp, renderShadowMap). Medium is the size the map always had.
+enum { SHADOW_QUALITY_COUNT = 3 };
+
/** Options.ini -> TheWritableGlobalData, for every row. A key that is absent leaves the field at
* whatever GlobalData's constructor put there, which is what makes an old Options.ini keep
* working when a row is added. */
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 923948e3f..bafd2d399 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -691,6 +691,7 @@ GlobalData::GlobalData()
m_shadowsForParticles = TRUE; //on by default: the shipped INI has no entry for it
m_volumetricSmokeShadows = TRUE;
m_smokeFireLighting = TRUE;
+ m_shadowQuality = 1; //medium, the 2048 map the shadows always had
m_classicGraphics = FALSE;
m_shadowMap = TRUE; //the sun's own shadows are what the game draws with now
m_shadowMapOnly = TRUE; //and they replace the stencil volumes rather than joining them
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index db810e78b..272ecfc02 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -109,6 +109,7 @@ OPTION_BOOL_ACCESSORS( m_shadowsForParticles )
OPTION_BOOL_ACCESSORS( m_particleGroundBounce )
OPTION_BOOL_ACCESSORS( m_volumetricSmokeShadows )
OPTION_BOOL_ACCESSORS( m_smokeFireLighting )
+OPTION_INT_ACCESSORS( m_shadowQuality )
//-----------------------------------------------------------------------------
static const unsigned TheMsaaSamples[ OPTION_MSAA_LEVEL_COUNT ] = { 0, 2, 4, 8, 16 };
@@ -467,6 +468,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_smokeFireLighting, set_m_smokeFireLighting },
+ // The size of the sun's depth map. The shadow pass asks for it every frame and the backend makes
+ // the map again when the size changes, so a new level shows on the next frame. No control in the
+ // game's own menu; the launcher writes it. Classic graphics and -d3d9 draw no map at all.
+ { "ShadowQuality", "", "",
+ OPTION_ENUM, APPLY_LIVE, 0, SHADOW_QUALITY_COUNT - 1,
+ get_m_shadowQuality, set_m_shadowQuality },
+
// -smoke and -particlebounce as settings. Both are spent on the particle system templates while
// the particle manager starts, so they wait for the next launch. The command line is parsed after
// this catalog loads, so either switch still wins for the one run it is given.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 6a98e94ee..14a115c9b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -4197,7 +4197,11 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
static Bool wholeMapRefused = FALSE;
if (!wholeMap)
wholeMapRefused = FALSE;
- UnsignedInt texels = SHADOW_MAP_TEXELS;
+ /* The ShadowQuality option halves or doubles the usual map: 1024, 2048 or 4096 a side. The filter
+ below is held in ground units against the 2048 map, so a level changes how sharp an edge is
+ and not how wide its penumbra is. */
+ const UnsignedInt chosenTexels = (SHADOW_MAP_TEXELS / 2) << TheGlobalData->m_shadowQuality;
+ UnsignedInt texels = chosenTexels;
Bool begun = FALSE;
if (TheGlobalData->m_shadowMap && m_shadowList != NULL && TheTacticalView != NULL)
{
@@ -4210,7 +4214,7 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
{
if (wholeMap)
wholeMapRefused = TRUE;
- begun = Direct3D11_Begin_Shadow_Map( SHADOW_MAP_TEXELS );
+ begun = Direct3D11_Begin_Shadow_Map( chosenTexels );
}
}
if (!begun)