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(ww3d2): keep headlight beams and glows out of the sun's shadow map

Olcay Seygan529ef2f4c5e9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd2346ab8..3c5bdb543 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1238,6 +1238,12 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
Comanche's thin body so wide that nothing of it was left on the ground, and the spinning blades
never reached the shadow at all. Now the blades turn in the shadow as a star under the fuselage,
still softer than a tank's.
+- Headlights light the ground instead of shading it. At night a Humvee, an Avenger or a Sentry
+ Drone with its lights on laid its own beam on the ground as a dark wedge in front of it, as if
+ the light were a solid thing standing in the moonlight, and civilian cars, trucks and the lamps
+ on night buildings did the same. A beam or a glow casts nothing now. Rotor blades, leaves,
+ fences and flags keep their shadows. With nine vehicles parked on Dark Night's village square,
+ 44 beams and glows around them came out of the shadow.
- Zoomed all the way out, the top of the screen has its shadows. The sun's view of the battlefield
was a fixed square around the middle of the screen, and from full height the far ground at the top
lies well outside it, so buildings, trees and tanks up there stood on bright ground with nothing
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 9d469af66..2b1184e74 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -4223,6 +4223,9 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
DX8Wrapper::Set_DX8_Render_State( D3DRS_CULLMODE, D3DCULL_CW );
RenderInfoClass sunInfo( sun );
+ // MeshClass::Render leaves the light pieces (beams, glows) out under this hint.
+ sunInfo.Push_Override_Flags( RenderInfoClass::RINFO_OVERRIDE_SHADOW_RENDERING );
+ MeshClass::Shadow_Pass_Light_Meshes = 0;
#ifndef DEBUG_LOGGING
Int castersCounted = 0;
#endif
@@ -4392,8 +4395,9 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
if (frame >= nextReportFrame)
{
nextReportFrame = frame + LOGICFRAMES_PER_SECOND;
- DEBUG_LOG(("SHADOWMAP: %d casters, %d left out as reaching nothing in view, %s\n",
- castersCounted, castersOutOfView, Direct3D11_Shadow_Map_Report().c_str()));
+ DEBUG_LOG(("SHADOWMAP: %d casters, %d left out as reaching nothing in view, %d light meshes left out, %s\n",
+ castersCounted, castersOutOfView, MeshClass::Shadow_Pass_Light_Meshes,
+ Direct3D11_Shadow_Map_Report().c_str()));
}
}
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
index 0bdcf09a1..fdf0984a4 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp
@@ -125,6 +125,7 @@
static unsigned MeshDebugIdCount;
bool MeshClass::Legacy_Meshes_Fogged = true;
+int MeshClass::Shadow_Pass_Light_Meshes = 0;
static SimpleDynVecClass<uint32> temp_apt;
/*
@@ -664,6 +665,18 @@ void MeshClass::Render(RenderInfoClass & rinfo)
return;
}
+ /* A shadow pass draws matter, and a mesh that blends on its base pass without the artist's
+ cast-shadow flag is light: a headlight's beam, a glow, a muzzle flash. The stencil volumes
+ have always left a blended mesh like that out (W3DShadowGeometry::initFromHLOD); the sun's
+ depth pass drew it, and a Humvee laid the cone of its own headlight on the ground. Alpha
+ tested meshes (leaves, fences, flags) are not IS_ALPHA and stay, where the volumes drop them,
+ and every rotor disc in the game carries the flag. */
+ if ((rinfo.Current_Override_Flags() & RenderInfoClass::RINFO_OVERRIDE_SHADOW_RENDERING)
+ && Is_Alpha() && !Model->Get_Flag(MeshGeometryClass::CAST_SHADOW)) {
+ ++Shadow_Pass_Light_Meshes;
+ return;
+ }
+
// If static sort lists are enabled and this mesh has a sort level, put it on the list instead
// of rendering it.
unsigned int sort_level = (unsigned int)Model->Get_Sort_Level();
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h
index 9ba8650e1..dfd335c77 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h
@@ -156,6 +156,9 @@ public:
// Do old .w3d mesh files get fog turned on or off?
static bool Legacy_Meshes_Fogged;
+ // Meshes a shadow pass left out as light rather than matter, counted until the caller resets it.
+ static int Shadow_Pass_Light_Meshes;
+
void Replace_Texture(TextureClass* texture,TextureClass* new_texture);
void Replace_VertexMaterial(VertexMaterialClass* vmat,VertexMaterialClass* new_vmat);