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(w3ddevice): bridge decks cast into the sun's shadow map

Olcay Seygan9cc0c0b00d47
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1aaaa4ef..8f5faa284 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1150,6 +1150,10 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
treatment through the finishing passes. The patch goes with the building's shadow in the fog: an
enemy base you have never scouted used to leave its dark footprints on grey ground, a map of
where every building stood.
+- A bridge stops the sun. A tank crossing one used to throw its shadow twice, on the deck where it
+ belongs and again on the ground under the bridge, because the light went straight through the
+ stone. The bridge now casts its own shadow across the bank and the water below it, a unit on the
+ deck shadows the deck alone, and the side of the bridge that faces away from the sun is in shade.
- Infantry shadows are built from the pose: arms, head, weapon, moving with him.
- `UseShadowVolumesForSkins = No` puts the old flat blobs back.
- Scuds, rockets and falling bombs cast a shadow running along the ground.
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
index 05a1ba0f2..abcbe9347 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
@@ -211,6 +211,7 @@ public:
void removeTerrainBibHighlighting(void);
W3DShroud *getShroud() {return m_shroud;}
+ W3DBridgeBuffer *getBridgeBuffer() {return m_bridgeBuffer;}
void updateShorelineTiles(Int minX, Int minY, Int maxX, Int maxY, WorldHeightMap *pMap); ///<figure out which tiles on this map cross water plane
void updateShorelineTile(Int X, Int Y, Int Border, WorldHeightMap *pMap); ///<figure out which tiles on this map cross water plane
void recordShoreLineSortInfos(void);
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBridgeBuffer.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBridgeBuffer.h
index b0962f310..179da2a81 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBridgeBuffer.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DBridgeBuffer.h
@@ -158,6 +158,8 @@ public:
void clearAllBridges(void);
/// Draws the bridges. Uses camera for culling.
void drawBridges(CameraClass * camera, Bool wireframe, TextureClass *cloudTexture);
+ /// Draws the decks into whatever depth target is bound, for the sun's shadow map.
+ void drawBridgeShadowCasters(void);
/// Called when the view changes, and sort key needs to be recalculated.
/// Normally sortKey gets calculated when a bridge becomes visible.
void doFullUpdate(void) {m_updateVis = true;};
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 1c47e2660..e8db5bba5 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -49,6 +49,7 @@
#include "Lib/BaseType.h"
#include "W3DDevice/GameClient/W3DGranny.h"
#include "W3DDevice/GameClient/Heightmap.h"
+#include "W3DDevice/GameClient/W3DBridgeBuffer.h"
#include "d3dx9math.h"
#include "common/GlobalData.h"
#include "common/drawmodule.h"
@@ -110,6 +111,10 @@ const Real cosAngleToCare = cos ((0.2 * PI) / 180.0); //1.5 degree difference
// fully blocked pixel goes, and how far the filter reaches in texels. The first is the one that
// decides between a surface shadowing itself in stripes and a shadow lifting off its own caster.
#define SHADOW_MAP_DEPTH_BIAS 0.0015f
+// How far a bridge deck is pushed back in the map, in multiples of its own depth slope across one
+// texel. The decks are the one caster drawn with both faces, so this is their only guard against
+// shadowing themselves.
+#define SHADOW_MAP_BRIDGE_SLOPE_BIAS 2.0f
// 0.55 was picked on a frame with one base in it; over fourteen buildings a wide shadow on the
// ground read at a quarter of the sunlit sand, black in front of every wall, and the owner took
// 0.45 from three panels of the same base on 2026-09-21.
@@ -3933,6 +3938,20 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
while the pass runs and cuts it at its alpha, which keeps the blades. */
SortingRendererClass::Flush();
+ /* The bridge decks are not casters in the list above and have to be in the map all the same:
+ without them the sun reached through a deck, and a tank crossing it laid one shadow on the
+ deck and a second on the ground under the bridge. Drawn last so the bias below reaches no
+ other caster. A deck goes in with both faces, so the map holds its top, and a top that
+ tilts away from the sun would shadow its own far edge in stripes; the slope bias pushes it
+ back by what its tilt across a texel or two is worth, which is nothing next to the height
+ of a bridge over the ground and leaves a unit on the deck nearer the sun than the deck.
+ Nothing else in the game sets this state, so it goes back to zero rather than to the
+ wrapper's cached value, which an invalidate leaves as a sentinel. */
+ const float bridgeSlopeBias = SHADOW_MAP_BRIDGE_SLOPE_BIAS;
+ DX8Wrapper::Set_DX8_Render_State( D3DRS_SLOPESCALEDEPTHBIAS, *(const DWORD *)&bridgeSlopeBias );
+ TheTerrainRenderObject->getBridgeBuffer()->drawBridgeShadowCasters();
+ DX8Wrapper::Set_DX8_Render_State( D3DRS_SLOPESCALEDEPTHBIAS, 0 );
+
DX8Wrapper::Set_DX8_Render_State( D3DRS_COLORWRITEENABLE,
D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE
| D3DCOLORWRITEENABLE_ALPHA );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp
index 5316840f7..95d776b08 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DBridgeBuffer.cpp
@@ -1214,4 +1214,34 @@ void W3DBridgeBuffer::drawBridges(CameraClass * camera, Bool wireframe, TextureC
}
}
+//=============================================================================
+// W3DBridgeBuffer::drawBridgeShadowCasters
+//=============================================================================
+/** The decks again, into the sun's depth map. A deck that is not in the map lets the sun through
+ it, so a tank crossing a bridge shadowed the deck and the ground under the bridge as well.
+ The same shader as the frame's own draw, because its alpha test is what cuts the holes in a
+ truss, and the same textures for that alpha. The enabled flags are the ones drawBridges set
+ on the frame before, which is what keeps a destroyed span out of the map. */
+//=============================================================================
+void W3DBridgeBuffer::drawBridgeShadowCasters(void)
+{
+ if (m_curNumBridgeIndices == 0) {
+ return;
+ }
+
+ // The vertices are in world space; the frame's terrain draw sets this before drawBridges.
+ DX8Wrapper::Set_Transform(D3DTS_WORLD, Matrix3D(1));
+ DX8Wrapper::Set_Material(m_vertexMaterial);
+ DX8Wrapper::Set_Index_Buffer(m_indexBridge,0);
+ DX8Wrapper::Set_Vertex_Buffer(m_vertexBridge);
+ DX8Wrapper::Set_Shader(detailAlphaShader);
+ DX8Wrapper::Set_Texture(1,NULL);
+
+ for (Int curBridge=0; curBridge<m_numBridges; curBridge++) {
+ if (m_bridges[curBridge].isEnabled() && m_bridges[curBridge].isVisible()) {
+ m_bridges[curBridge].renderBridge(FALSE);
+ }
+ }
+}
+