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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameenginedevice): give trees a shadow built from their own model
Olcay Seygan984e141964c6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 208203fb1..5f598fa99 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -245,11 +245,23 @@ darken a single pixel, so a forest sat on clean bright sand next to tanks with sthem. The blob is now blended onto the ground the way its own artwork describes it — the samepicture, the same darkness EA chose, actually visible.-So every tree on the map has a shadow now. So does every palm, every bush and every piece of-scenery that only ever had the soft kind, whichever shadow setting you play on. Leaning that pool-away from the sun was tried and put back: a round smudge sitting a tree's width to one side does-not read as that tree's shadow, it reads as a stain on the ground.-+So every tree on the map has a shadow now — and not just a pool. A tree was the last thing out+there whose shadow was a circle while everything else threw its own shape. It threw a circle for+three reasons, all of them the game's own: the trees ask for the cheap kind by name; the shadow+builder refuses any part of a model marked see-through, and a tree's *trunk* is marked see-through+along with its leaves, so the whole tree was refused; and leaves are flat sheets, which cannot cast+a solid shadow no matter what you do with them.++Trees are now handled the way the soldiers were: they get a real shadow built from the model, and+the see-through rule is only lifted when it would otherwise leave the tree with nothing at all — a+helicopter's rotor still does not throw a solid disc. What comes out is the trunk, stretched across+the ground in the sun's direction, with the soft pool kept underneath for the crown the leaves+cannot cast. Palms on a beach now lie their trunks across the sand.++Every tree, too, not most of them: 27 of the game's 128 tree types never said whether they should+cast at all, and silently got nothing. They cast now. So do the bushes, the palms and the scenery.+`ShadowsForProps = No` in `GameData.ini` puts every bit of this back the way it was if a map full+of trees costs you frames.And the scenery nobody gave a shadow to at all: fences, walls of tyres, rubbish piles, lowshrubs, the props that dress a map. They stood on the terrain with nothing under them, which isthe one thing the eye picks out instantly. Anything that cannot move and had no shadow now castsdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.hindex 0c24a7b26..2e336b7fc 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h@@ -501,6 +501,7 @@ private:Bool m_shadowEnabled; ///< cached state of shadow. Used to determine if shadows should be enabled via options screen.RenderObjClass* m_renderObject; ///< W3D Render object for this drawableShadow* m_shadow; ///< Updates/Renders shadows of this object+ Shadow* m_shadowBlob; ///< a foliage prop's soft pool - its leaves are open planes and cast no volumeShadow* m_terrainDecal;TerrainTracksRenderObjClass* m_trackRenderObject; ///< This is rendered under objectParticleSystemIDVec m_particleSystemIDs; ///< The ID numbers of the particle systems currently running.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex 1fa8e1705..9b9c8d163 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -1728,6 +1728,7 @@ W3DModelDraw::W3DModelDraw(Thing *thing, const ModuleData* moduleData) : DrawModm_hexColor = 0;m_renderObject = NULL;m_shadow = NULL;+ m_shadowBlob = NULL;m_shadowEnabled = TRUE;m_terrainDecal = NULL;m_trackRenderObject = NULL;@@ -1828,6 +1829,8 @@ void W3DModelDraw::setHidden(Bool hidden)if (m_shadow)m_shadow->enableShadowRender(!hidden);+ if (m_shadowBlob)+ m_shadowBlob->enableShadowRender(!hidden);m_shadowEnabled = hidden;@@ -1848,6 +1851,9 @@ void W3DModelDraw::releaseShadows(void) ///< frees all shadow resources used byif (m_shadow)m_shadow->release();m_shadow = NULL;+ if (m_shadowBlob)+ m_shadowBlob->release();+ m_shadowBlob = NULL;}/** Does this model contain any skinned (bone-deformed) geometry? Infantry and other animated@@ -1897,6 +1903,24 @@ never a volume; a zero decal size makes addShadow take the size from the model'sReturns FALSE when this drawable gets no shadow at all. */static Bool fillShadowInfoFromTemplate(const ThingTemplate *tmplate, Shadow::ShadowTypeInfo *shadowInfo, Bool allowPropVolume = TRUE){+ //A prop the art gave a blob - a palm, a bush, a rock - cast a round pool instead of its own+ //shape. It never moves, so a volume is built once and then costs nothing to keep. Same+ //allowPropVolume retry as below: a model with no usable shadow geometry drops back to the blob.+ if (tmplate->getShadowType() == SHADOW_DECAL && allowPropVolume &&+ TheGlobalData->m_shadowsForProps && TheGlobalData->m_useShadowVolumes &&+ tmplate->isKindOf(KINDOF_IMMOBILE) && !tmplate->isKindOf(KINDOF_PROJECTILE))+ {+ shadowInfo->m_ShadowName[0] = 0;+ shadowInfo->allowUpdates = FALSE;+ shadowInfo->allowWorldAlign = TRUE;+ shadowInfo->m_type = SHADOW_VOLUME;+ shadowInfo->m_sizeX = 0.0f;+ shadowInfo->m_sizeY = 0.0f;+ shadowInfo->m_offsetX = 0.0f;+ shadowInfo->m_offsetY = 0.0f;+ return TRUE;+ }+if (tmplate->getShadowType() == SHADOW_NONE){//a prop the art gave no shadow at all - a fence, a rubbish pile, a shrub - gets a real volume@@ -1958,7 +1982,7 @@ void W3DModelDraw::allocateShadows(void)Bool promotedToVolume = tmplate->getShadowType() != SHADOW_NONE &&promoteSkinShadowToVolume(m_renderObject, &shadowInfo);//a prop we handed a volume the template never asked for falls back the same way- if (tmplate->getShadowType() == SHADOW_NONE && shadowInfo.m_type == SHADOW_VOLUME)+ if (tmplate->getShadowType() != SHADOW_VOLUME && shadowInfo.m_type == SHADOW_VOLUME)promotedToVolume = TRUE;m_shadow = TheW3DShadowManager->addShadow(m_renderObject, &shadowInfo);@@ -1969,6 +1993,17 @@ void W3DModelDraw::allocateShadows(void)m_shadow = TheW3DShadowManager->addShadow(m_renderObject, &shadowInfo);}++ //A tree's leaves are open planes: they contribute nothing to a stencil volume, so what the+ //volume gives is the trunk alone. Keep the blob under the crown as well - together they are+ //a trunk laid across the ground and a pool of shade under the branches.+ if (m_shadowBlob == NULL && m_shadow && shadowInfo.m_type == SHADOW_VOLUME &&+ tmplate->getShadowType() == SHADOW_DECAL)+ {+ Shadow::ShadowTypeInfo blobInfo;+ if (fillShadowInfoFromTemplate(tmplate, &blobInfo, FALSE))+ m_shadowBlob = TheW3DShadowManager->addShadow(m_renderObject, &blobInfo);+ }if (m_shadow){ m_shadow->enableShadowInvisible(m_fullyObscuredByShroud);if (m_renderObject->Is_Hidden() || !m_shadowEnabled)@@ -1982,6 +2017,8 @@ void W3DModelDraw::setShadowsEnabled(Bool enable){if (m_shadow)m_shadow->enableShadowRender(enable);+ if (m_shadowBlob)+ m_shadowBlob->enableShadowRender(enable);m_shadowEnabled = enable;}@@ -2045,6 +2082,8 @@ void W3DModelDraw::setFullyObscuredByShroud(Bool fullyObscured)if (m_shadow)m_shadow->enableShadowInvisible(m_fullyObscuredByShroud);+ if (m_shadowBlob)+ m_shadowBlob->enableShadowInvisible(m_fullyObscuredByShroud);if (m_terrainDecal)m_terrainDecal->enableShadowInvisible(m_fullyObscuredByShroud);@@ -2894,6 +2933,9 @@ void W3DModelDraw::nukeCurrentRender(Matrix3D* xform)if (m_shadow)m_shadow->release();m_shadow = NULL;+ if (m_shadowBlob)+ m_shadowBlob->release();+ m_shadowBlob = NULL;if(m_terrainDecal)m_terrainDecal->release();@@ -3172,7 +3214,7 @@ void W3DModelDraw::setModelState(const ModelConditionInfo* newState)Bool promotedToVolume = tmplate->getShadowType() != SHADOW_NONE &&promoteSkinShadowToVolume(m_renderObject, &shadowInfo);//a prop we handed a volume the template never asked for falls back the same way- if (tmplate->getShadowType() == SHADOW_NONE && shadowInfo.m_type == SHADOW_VOLUME)+ if (tmplate->getShadowType() != SHADOW_VOLUME && shadowInfo.m_type == SHADOW_VOLUME)promotedToVolume = TRUE;m_shadow = TheW3DShadowManager->addShadow(m_renderObject, &shadowInfo, draw);@@ -3183,6 +3225,17 @@ void W3DModelDraw::setModelState(const ModelConditionInfo* newState)m_shadow = TheW3DShadowManager->addShadow(m_renderObject, &shadowInfo, draw);}++ //A tree's leaves are open planes: they contribute nothing to a stencil volume, so what the+ //volume gives is the trunk alone. Keep the blob under the crown as well - together they are+ //a trunk laid across the ground and a pool of shade under the branches.+ if (m_shadowBlob == NULL && m_shadow && shadowInfo.m_type == SHADOW_VOLUME &&+ tmplate->getShadowType() == SHADOW_DECAL)+ {+ Shadow::ShadowTypeInfo blobInfo;+ if (fillShadowInfoFromTemplate(tmplate, &blobInfo, FALSE))+ m_shadowBlob = TheW3DShadowManager->addShadow(m_renderObject, &blobInfo, draw);+ }if (m_shadow){ m_shadow->enableShadowInvisible(m_fullyObscuredByShroud);m_shadow->enableShadowRender(m_shadowEnabled);@@ -3251,6 +3304,8 @@ void W3DModelDraw::setModelState(const ModelConditionInfo* newState)m_renderObject->Set_Hidden(TRUE);if (m_shadow)m_shadow->enableShadowRender(FALSE);+ if (m_shadowBlob)+ m_shadowBlob->enableShadowRender(FALSE);m_shadowEnabled = FALSE;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex a45a777d5..3d1fa8010 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -655,6 +655,16 @@ Int W3DShadowGeometry::initFromHLOD(RenderObjClass *robj)m_numTotalsVerts=0;+ //Two passes. The first is EA's: a transparent mesh is not a shadow caster, because its+ //silhouette is the quad it is painted on rather than the thing painted on it - a rotor disc+ //would throw a solid disc. The second pass runs only when that left the model with nothing+ //at all, which is every tree and bush in the game: their trunk is flagged transparent along+ //with their leaves, so the choice there is not 'a good shadow or a bad one' but 'the model's+ //own shadow or none'. Open leaf planes still contribute nothing to a stencil volume, so what+ //comes out is the solid part - the trunk.+ for (Int pass = 0; pass < 2 && m_meshCount == 0; pass++)+ {+ const Bool allowTransparent = (pass == 1);for (i = 0; i < hlod->Get_Lod_Model_Count(top); i++){if (hlod->Peek_Lod_Model(top,i) && hlod->Peek_Lod_Model(top,i)->Class_ID() == RenderObjClass::CLASSID_MESH)@@ -667,7 +677,7 @@ Int W3DShadowGeometry::initFromHLOD(RenderObjClass *robj)// if (!geomMesh->m_mesh->Peek_Model()->Get_Flag(MeshGeometryClass::CAST_SHADOW))// continue; // CNC3 (gth) Only cast shadows from meshes with the shadow flag ENABLED!- if ((geomMesh->m_mesh->Is_Alpha() || geomMesh->m_mesh->Is_Translucent()) && !geomMesh->m_mesh->Peek_Model()->Get_Flag(MeshGeometryClass::CAST_SHADOW))+ if (!allowTransparent && (geomMesh->m_mesh->Is_Alpha() || geomMesh->m_mesh->Is_Translucent()) && !geomMesh->m_mesh->Peek_Model()->Get_Flag(MeshGeometryClass::CAST_SHADOW))continue; //transparent meshes that don't have forced shadows will not cast volumetric shadows// CNC3 (gth) skin meshes should never cast a volumetric shadowif (geomMesh->m_mesh->Peek_Model()->Get_Flag(MeshGeometryClass::SKIN))@@ -875,6 +885,7 @@ Int W3DShadowGeometry::initFromHLOD(RenderObjClass *robj)m_meshCount++;}}+ }// for (i = 0; i < AdditionalModels.Count(); i++) {// res |= AdditionalModels[i].Model->Cast_Ray(raytest);@@ -896,8 +907,9 @@ Int W3DShadowGeometry::initFromMesh(RenderObjClass *robj)geomMesh->m_mesh = (MeshClass *)robj;geomMesh->m_meshRobjIndex = -1; //robj is the mesh so no index needed.- if (((geomMesh->m_mesh->Is_Alpha() || geomMesh->m_mesh->Is_Translucent()) && !geomMesh->m_mesh->Peek_Model()->Get_Flag(MeshGeometryClass::CAST_SHADOW)))- return FALSE; //transparent meshes that don't have forced shadows will not cast volumetric shadows+ //A lone transparent mesh is the whole model, so refusing it is refusing the object any shadow+ //at all - see the two passes in initFromHLOD. It is taken, and its open planes simply do not+ //contribute to the volume.MeshModelClass *mm = geomMesh->m_mesh->Peek_Model();geomMesh->m_numVerts=mm->Get_Vertex_Count();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cppindex 787a1a775..2a33f7848 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp@@ -1620,7 +1620,11 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDif (type<0) { // deleted.continue;}- if (!m_trees[curTree].visible || !m_treeTypes[type].m_doShadow) {+ //DoShadow is the tree type's own say, and 27 of the game's 128 tree types never name it at+ //all - the module data defaults it to false, so those stood on clean ground. With+ //ShadowsForProps on, every tree gets the blob and the flag only decides it when that is off.+ if (!m_trees[curTree].visible ||+ (!m_treeTypes[type].m_doShadow && !TheGlobalData->m_shadowsForProps)) {continue;}Real factor = 1.0f;