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): bind the vertex declaration each .vso is loaded with

Olcay Seygan1d06aef72b94
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
index a5a76d16d..d0beaaad7 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
@@ -1958,6 +1958,14 @@ void W3DTreeBuffer::drawTreeBuffers(Bool shadowPass)
// Render the waving grass
DX8Wrapper::Apply_Render_State_Changes();
if (m_dwTreeVertexShader) {
+ // D3D8 carried the vertex declaration beside the shader and SetVertexShader bound
+ // both. D3D9 split them, and a shader whose dcl_ inputs have no matching element in
+ // whatever declaration is currently bound reads zero out of them. The FVF the vertex
+ // buffer sets has no blend weight and no blend indices, which is where Trees.vso keeps
+ // the tree's base height, its sway type and its lit colour: without this the trees draw
+ // unswayed and black, their shadows draw unflattened on top of them, and the buffer,
+ // the draw call and the matrix all look right while it happens.
+ dev->SetVertexDeclaration(m_treeVertexDeclaration);
dev->SetVertexShader(m_dwTreeVertexShader);
dev->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
dev->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
index d18ddb1e7..c5d249148 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
@@ -1984,6 +1984,9 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)
m_pDev->SetVertexShaderConstantF(CV_ZERO, D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), 1);
m_pDev->SetVertexShaderConstantF(CV_ONE, D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f), 1);
+ // The declaration D3D8 carried beside the shader has to be bound separately in D3D9, or the
+ // shader's dcl_ inputs read zero out of a stream the current FVF describes differently.
+ m_pDev->SetVertexDeclaration(m_waveVertexDeclaration);
m_pDev->SetVertexShader(m_dwWaveVertexShader);
m_pDev->SetPixelShader(m_dwWavePixelShader);