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(w3ddevice): power outage, emp, cloak and revealed looks on d3d11
Olcay Seygan528b90543e7d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3d320e8e8..3f8bfd897 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1375,6 +1375,8 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Smoke and fire no longer end on a straight line where they meet the ground or a building. A puff that sinks into a hillside or drifts against a wall thins out over its last few metres, softly enough that a nuke's haze and a Scud's grey smoke no longer come out as stacked, stair-stepped terraces, and a toxin cloud lying low over the ground keeps its body instead of breaking into hard-edged green islands. A China mine field blinks where you can see it again: its lights hang just off the ground, and the fade had eaten all but a thirtieth of their bright middle. No effect fades over more than its own size now, so a small spark close to the ground keeps its light. This is the default renderer; Classic and the old renderer keep the hard edge they had in 2003.- Gunfire shows at the zoom you play at. A rifle's tracer was a third of a unit wide, about one pixel from the default camera, and a bullet hit nothing you could see. Tracers from rifles, Gattlings, Humvees, Technicals and Quad Cannons are now twice as wide and half again as long, the muzzle flash is half as big again, and every hit kicks up sparks and a puff of dirt where it lands. Tank guns fire a hot streak that flies with the shell, a Crusader's, Battlemaster's, Scorpion's, Paladin's or Overlord's muzzle flame and flash are about half as big again, and a shell landing throws dirt and sparks around its blast. The colours are the ones the game always used, and no weapon does anything different.- A China mine field has mines in it. EA's field had no model at all, only a white glint blinking on each of its eight spots, so your own minefield looked like a patch of fireflies. Each spot is now a round steel mine pressed into a ring of dug earth, at a random turn, with an arming LED over its fuse that flicks on for a fifth of a second every second and a half, red on standard and cluster mines and a cold blue on EMP mines. You and your allies see them a little see-through, the way you see your own stealthed units. The enemy still sees nothing until he detects the field, and then he sees the same mines. A mine going off under a tank now throws a column of dark earth twice the tank's height, scatters clods round it and leaves a low black smoke and a scorch, with a short jolt of the screen; it used to puff a pale spray of specks that looked like dust kicked up. An EMP mine adds a blue ring across the ground and a crackle of blue sparks. What a mine does is unchanged.+- A base out of power looks out of power. A building short of power, or one a hacker shut down, drains to a cold grey and sags darker, and its windows and lamps go out. Every few seconds it blinks dark for an instant or its lights catch again for a moment, and blue sparks jump on its walls where something shorts. A tank or building hit by an EMP crawls with thin blue arcs for as long as it stays dead, where it used to just turn dark grey.+- Your own stealthed units look cloaked instead of faded. What stands behind a Pathfinder, Colonel Burton or a stealthed GLA unit bends through its body in a slow ripple, under a cold edge you can still read the unit by. When an enemy detector has found him, that edge pulses amber. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it keeps its own paint, drained of colour, under a burning red-orange outline with scan lines running up it, and all of it flares on every sweep of the detector. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.- Effects fade out instead of blinking off. The rings a nuke sends across the ground, and any spark, flash or puff whose own colours never reached nothing, used to vanish at full strength on their last frame. Each one now dims away over its last quarter of a second, or over a quarter of its life when it lives shorter than that. One that was already fading looks the way it always did.- Toxin, anthrax and radiation pools lie on the ground. A pool is a carpet of puddle pictures spread up to 140 paces from where the shell or the spray came down, and every one of them was drawn dead flat at the height of that one spot: on a hillside the uphill half of the pool disappeared into the slope and the downhill half hung in the air above it. Each puddle now bends over the ground underneath it, on both renderers, and a pool on a bridge stays on the deck. The pool also holds still. It used to throb twice a second, because every half second the pool's poison fired a fresh batch of puddles that swelled out of black to full green and back to black in two seconds, each batch somewhere new. Now it comes up in half a second, stays one pool at full colour for as long as it does damage, and fades over its last three seconds, or over three seconds from the moment the fog of war closes over it. It is not frozen, though: each puddle fades down and back up on its own beat, so the surface shimmers like something liquid while the pool as a whole never pulses. Four Scud warheads landing on one spot used to stack into a white-hot blotch in the middle; overlapping pools now share their light and the middle stays toxin green. The ground under it takes on its colour, green for toxin and the anthrax colours for anthrax, so it looks spilled rather than shone onto the grass. China's radiation keeps its orange but glows instead of browning the grass, which made it look like a scorch mark, and small bubbles swell out of it and pop. A nuke's radiation lies on the hillside as a pool from three seconds after the blast, where its first ten seconds used to be flat squares cutting into the slope.- A Scud Storm or a carpet bomb shakes the screen as hard as it should. The game cut a pile of heavy shakes back to a mild one, so a run of missiles or bombs landing together shook less than one of them alone. Each now shakes a step lighter and the run builds up. Demo traps and Aurora bombs shake now, and a falling building shakes harder the bigger it was.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex b40e570bf..6300710b2 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -834,6 +834,8 @@ static void pushDirect3D11PostChain( void ){// Classic graphics is the game's own picture, which is what -d3d9 draws: hard edged sprites.Direct3D11_Allow_Soft_Particles( !TheGlobalData->m_classicGraphics );+ // and its own looks for the power outage, the EMP and the two stealth states+ Direct3D11_Allow_Draw_Effects( !TheGlobalData->m_classicGraphics );const AsciiString & requested = TheGlobalData->m_direct3D11PostChain;if( !Direct3D11_Post_Chain( requested.str() ) && !requested.isEmpty() ){diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cppindex c62646fca..84b0efb30 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp@@ -615,6 +615,62 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable}}+//=============================================================================+/** Which of the Direct3D 11 frame's own looks a drawable wears this frame, and its four numbers+ * (DRAW_EFFECT_SAMPLING in ffshader.h): seconds, strength, a seed from the drawable's id and the+ * drawable's opacity. Only reads the object, which the renderer is allowed to do; nothing here+ * goes back into the logic. None under -d3d9, -headless or Classic graphics, where the heat+ * vision pass and the disabled tint draw what they always drew.+ *+ * An enemy a detector found is revealed, and an own stealthed unit that is see-through is cloaked,+ * with the detector's pulse as the strength in both. The cloak only in the translucent pass: the+ * scene's copy it bends is taken at its first draw, and the behind-building markers draw an+ * occluded unit early, mid-way through the opaque world. Mines keep the heat vision's old exception.+ * An EMP takes precedence over power: an EMP'd building is out of power as well. */+//=============================================================================+static unsigned chooseDrawEffect( const Drawable *draw, const Object *obj, Bool translucentPass, float parameters[4] )+{+ if ( !Direct3D11_Draw_Effects() )+ return DRAW_EFFECT_NONE;++ unsigned effect = DRAW_EFFECT_NONE;+ const StealthLookType look = draw->getStealthLook();+ const Real pulse = draw->getSecondMaterialPassOpacity();+ const Real opacity = draw->getEffectiveOpacity();+ Real strength = 1.0f;++ if ( look == STEALTHLOOK_VISIBLE_DETECTED && !draw->isKindOf( KINDOF_MINE ) )+ {+ effect = DRAW_EFFECT_REVEALED;+ strength = pulse;+ }+ else if ( ( look == STEALTHLOOK_VISIBLE_FRIENDLY || look == STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED )+ && opacity < 0.99f && translucentPass )+ {+ effect = DRAW_EFFECT_CLOAK;+ strength = ( look == STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED ) ? pulse : 0.0f;+ }+ else if ( obj && !obj->isEffectivelyDead() )+ {+ if ( obj->isDisabledByType( DISABLED_EMP ) )+ effect = DRAW_EFFECT_EMP;+ else if ( obj->isKindOf( KINDOF_STRUCTURE )+ && ( obj->isDisabledByType( DISABLED_UNDERPOWERED ) || obj->isDisabledByType( DISABLED_SCRIPT_UNDERPOWERED )+ || obj->isDisabledByType( DISABLED_HACKED ) ) )+ effect = DRAW_EFFECT_OUTAGE;+ }++ if ( effect != DRAW_EFFECT_NONE )+ {+ // an hour of seconds keeps the sines' arguments small enough for single precision+ parameters[0] = (float)( WW3D::Get_Sync_Time() % 3600000u ) * 0.001f;+ parameters[1] = strength;+ parameters[2] = (float)fmod( (double)draw->getID() * 0.6180339887, 1.0 );+ parameters[3] = opacity;+ }+ return effect;+}+//============================================================================// RTS3DScene::renderOneObject//=============================================================================@@ -703,12 +759,18 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, IlightEnv.Reset(sph.Center, ambient);+ // The Direct3D 11 frame's own look for this object, if it is in one of the four states that+ // have one. The two that replace the disabled tint skip it: the dark grey under them only+ // muddied the cold grey they draw.+ rinfo.drawEffect = chooseDrawEffect( draw, obj, rinfo.alphaOverride < 1.0f, rinfo.drawEffectParameters );+// HANDLE THE SPECIAL DRAWABLE-LEVEL COLORING SETTINGS FIRSTconst Vector3 *tintColor = NULL;const Vector3 *selectionColor = NULL;- tintColor = draw->getTintColor();+ if ( rinfo.drawEffect != DRAW_EFFECT_OUTAGE && rinfo.drawEffect != DRAW_EFFECT_EMP )+ tintColor = draw->getTintColor();selectionColor = draw->getSelectionColor();if ( tintColor || selectionColor )@@ -749,8 +811,10 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, I}}- //Apply custom render pass for any drawables with heatvision enabled- if (draw->getSecondMaterialPassOpacity() != 0 )+ //Apply custom render pass for any drawables with heatvision enabled. The cloak and the+ //revealed look draw the detector's pulse themselves, over the unit's own paint.+ if (draw->getSecondMaterialPassOpacity() != 0+ && rinfo.drawEffect != DRAW_EFFECT_CLOAK && rinfo.drawEffect != DRAW_EFFECT_REVEALED ){rinfo.materialPassEmissiveOverride = draw->getSecondMaterialPassOpacity();@@ -869,6 +933,7 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, I}//drawable or robj is not hiddenrinfo.light_environment = NULL;+ rinfo.drawEffect = DRAW_EFFECT_NONE;if (doExtraMaterialPop) //check if there is an extra material on the stack from the add'l material effect.rinfo.Pop_Material_Pass();if (doExtraFlagsPop)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex 2fda9a4ab..af3b66c7c 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -320,6 +320,12 @@ DX11BackendClass::DX11BackendClass()SceneDepthStale = true;SceneDepthRefused = false;FrameDepthCopies = 0;+ DrawEffect = DRAW_EFFECT_NONE;+ memset(DrawEffectNumbers, 0, sizeof(DrawEffectNumbers));+ SceneColourCopy = NULL;+ SceneColourCopyView = NULL;+ SceneColourStale = true;+ SceneColourRefused = false;set_identity(WorldFromClip);for (unsigned stage = 0; stage < DX11_BACKEND_TEXTURE_STAGES; ++stage) {set_identity(TextureTransforms[stage]);@@ -481,6 +487,7 @@ void DX11BackendClass::Shutdown()ShadowMapBound = false;Release_Smoke_Map();Release_Scene_Depth();+ Release_Scene_Colour();RenderStates.Set_Shadow_Caster_Pass(false);Note_Shadow_State_Changed();Device = NULL;@@ -980,6 +987,124 @@ bool DX11BackendClass::Additive_Glow() const&& RenderStates.Get_Render_State(D3DRS_BLENDOP) == D3DBLENDOP_ADD;}+void DX11BackendClass::Set_Draw_Effect(unsigned effect, const float parameters[4])+{+ if (effect >= DRAW_EFFECT_COUNT) {+ effect = DRAW_EFFECT_NONE;+ }+ if (DrawEffect != effect) {+ DrawEffect = effect;+ PipelineChanged = true;+ ConstantsChanged = true;+ TexturesChanged = true; // the cloak binds the scene's copy with the stages+ }+ if (effect != DRAW_EFFECT_NONE && memcmp(DrawEffectNumbers, parameters, sizeof(DrawEffectNumbers)) != 0) {+ memcpy(DrawEffectNumbers, parameters, sizeof(DrawEffectNumbers));+ ConstantsChanged = true;+ }+ // Before any of the object's draws resolves: a copy the device refuses has to be known before a+ // cloak program is chosen, or that program reads nothing at t8 and draws the unit black.+ if (effect == DRAW_EFFECT_CLOAK && CurrentTarget == NULL && !ShadowMapBound) {+ Take_Scene_Colour();+ }+}++/** Which look the current draw takes. Only the scene's own world draws: not the sun's map, not a+ mirror or a filter target, not a screen space quad and not a transcribed program. A draw+ adding light (ONE as either factor) takes the outage alone, which puts a building's glow cards+ out with it; dressed in arcs or a rim, the card's whole quad would show. A multiplying pass+ takes none. The cloak needs the scene's copy, and without one the object keeps its plain+ translucency. */+unsigned DX11BackendClass::Draw_Effect() const+{+ if (DrawEffect == DRAW_EFFECT_NONE || ShadowMapBound || CurrentTarget != NULL+ || (VertexFormat & D3DFVF_XYZRHW) != 0+ || VertexProgram != ENGINE_SHADER_NONE || PixelProgram != ENGINE_SHADER_NONE) {+ return DRAW_EFFECT_NONE;+ }+ if (RenderStates.Get_Render_State(D3DRS_ALPHABLENDENABLE) != FALSE) {+ const DWORD source = RenderStates.Get_Render_State(D3DRS_SRCBLEND);+ const DWORD destination = RenderStates.Get_Render_State(D3DRS_DESTBLEND);+ if (source == D3DBLEND_ZERO || source == D3DBLEND_DESTCOLOR || destination == D3DBLEND_SRCCOLOR) {+ return DRAW_EFFECT_NONE;+ }+ if (source == D3DBLEND_ONE || destination == D3DBLEND_ONE) {+ return (DrawEffect == DRAW_EFFECT_OUTAGE) ? DRAW_EFFECT_OUTAGE : DRAW_EFFECT_NONE;+ }+ }+ if (DrawEffect == DRAW_EFFECT_CLOAK && SceneColourRefused) {+ return DRAW_EFFECT_NONE;+ }+ return DrawEffect;+}++void DX11BackendClass::Release_Scene_Colour()+{+ if (SceneColourCopyView != NULL) {+ SceneColourCopyView->Release();+ SceneColourCopyView = NULL;+ }+ if (SceneColourCopy != NULL) {+ SceneColourCopy->Release();+ SceneColourCopy = NULL;+ }+ SceneColourStale = true;+}++/** The scene's colour for the cloak, copied once a frame at the first cloaked draw: made at the+ scene target's own size and format and made again when a resize changes either. A multisampled+ target cannot be copied into a texture that is read by pixel, so that refuses the cloak. */+bool DX11BackendClass::Take_Scene_Colour()+{+ if (SceneColourRefused) {+ return false;+ }+ if (!SceneColourStale) {+ return true;+ }+ ID3D11Resource * source = NULL;+ Device->Get_Scene_View()->GetResource(&source);+ D3D11_TEXTURE2D_DESC description;+ static_cast<ID3D11Texture2D *>(source)->GetDesc(&description);+ if (SceneColourCopy != NULL) {+ D3D11_TEXTURE2D_DESC held;+ SceneColourCopy->GetDesc(&held);+ if (held.Width != description.Width || held.Height != description.Height+ || held.Format != description.Format) {+ Release_Scene_Colour();+ }+ }+ if (SceneColourCopy == NULL) {+ description.BindFlags = D3D11_BIND_SHADER_RESOURCE;+ description.MiscFlags = 0;+ description.Usage = D3D11_USAGE_DEFAULT;+ description.CPUAccessFlags = 0;+ // Read the copy the way the scene is written, which also covers a typeless surface.+ D3D11_RENDER_TARGET_VIEW_DESC written;+ Device->Get_Scene_View()->GetDesc(&written);+ D3D11_SHADER_RESOURCE_VIEW_DESC view;+ memset(&view, 0, sizeof(view));+ view.Format = written.Format;+ view.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;+ view.Texture2D.MipLevels = 1;+ if (description.SampleDesc.Count > 1+ || FAILED(Device->Get_Device()->CreateTexture2D(&description, NULL, &SceneColourCopy))+ || FAILED(Device->Get_Device()->CreateShaderResourceView(SceneColourCopy, &view,+ &SceneColourCopyView))) {+ Note_Refusal("the device refused a copy of the scene's colour for the cloak");+ Release_Scene_Colour();+ SceneColourRefused = true;+ source->Release();+ return false;+ }+ }+ Device->Get_Context()->CopyResource(SceneColourCopy, source);+ SceneColourStale = false;+ ++FrameDepthCopies; // counted with the depth copies, so DX11 FRAME COST sees it+ source->Release();+ return true;+}+bool DX11BackendClass::Smoke_Glow() const{return SmokeGlow && VertexProgram == ENGINE_SHADER_NONE && PixelProgram == ENGINE_SHADER_NONE@@ -1683,6 +1808,7 @@ void DX11BackendClass::Dump_Program(const std::string & key, const std::string &void DX11BackendClass::Begin_Scene(){SceneDepthStale = true;+ SceneColourStale = true;// A scene can begin with a render target already set: the water's reflection and the shadow// projector both set theirs and then call WW3D::Begin_Render, and forcing the back buffer here@@ -1893,6 +2019,7 @@ bool DX11BackendClass::Build_Combiner_Description(CombinerDescription & descriptdescription.ShadowReceiving = description.StageCount > 0 && Shadow_Receiving();description.SmokeGlow = Smoke_Glow();description.SoftParticle = Soft_Particle();+ description.DrawEffect = Draw_Effect();return description.StageCount > 0;}@@ -2371,7 +2498,9 @@ void DX11BackendClass::Upload_Pixel_Constants()const bool camera_space = Camera_Space_Draw();const float * const world_to_camera = (camera_space && SceneViewKnown) ? SceneView : View;- if (ShadowReceiving) {+ // A look takes its pixel back to the world the same way, with or without a sun's map.+ const unsigned effect = Draw_Effect();+ if (ShadowReceiving || effect != DRAW_EFFECT_NONE) {if (!ShadowFromClipValid|| memcmp(ShadowFromClipView, world_to_camera, sizeof(View)) != 0|| memcmp(ShadowFromClipProjection, Projection, sizeof(Projection)) != 0) {@@ -2386,6 +2515,17 @@ void DX11BackendClass::Upload_Pixel_Constants()ShadowFromClipValid = true;}}+ }+ if (effect != DRAW_EFFECT_NONE) {+ pixel_block.ShadowViewport[0] = (ViewportWidth > 0)+ ? 1.0f / static_cast<float>(ViewportWidth) : 0.0f;+ pixel_block.ShadowViewport[1] = (ViewportHeight > 0)+ ? 1.0f / static_cast<float>(ViewportHeight) : 0.0f;+ memcpy(pixel_block.WorldFromClip, WorldFromClip, sizeof(pixel_block.WorldFromClip));+ memcpy(pixel_block.DrawEffectParameters, DrawEffectNumbers, sizeof(DrawEffectNumbers));+ }++ if (ShadowReceiving) {pixel_block.VolumeParameters[0] = SmokeMapFilled ? SmokeStrength : 0.0f;pixel_block.VolumeParameters[1] = SmokeMapFilled ? SMOKE_SELF_SHADOW_GAIN : 0.0f;pixel_block.VolumeParameters[2] = camera_space ? 1.0f : 0.0f;@@ -2712,6 +2852,15 @@ void DX11BackendClass::Bind_State_Objects()Bound.SceneDepth = depth;}}++ // The scene's colour at t8 for the cloak, read with Load. Set_Draw_Effect took the copy.+ if (Draw_Effect() == DRAW_EFFECT_CLOAK) {+ ID3D11ShaderResourceView * const colour = SceneColourCopyView;+ if (!known || colour != Bound.SceneColour) {+ context->PSSetShaderResources(DX11_BACKEND_TEXTURE_STAGES + 4, 1, &colour);+ Bound.SceneColour = colour;+ }+ }}void DX11BackendClass::Bind_Pipeline(const Pipeline & pipeline, ID3D11Buffer * vertices, UINT stride,diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.hindex c3c7b6aaf..4c7e24600 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h@@ -233,6 +233,12 @@ public:// the smoke billboards' runs. An unlit draw with a normal takes it; any other ignores it.void Set_Smoke_Glow(bool glow);+ // The look the draws that follow are dressed in (a DRAW_EFFECT_* value, ffshader.h) and its+ // four numbers: wall clock seconds, strength, a per-object seed and the object's opacity. The+ // mesh renderer sets it around one object's draws and puts DRAW_EFFECT_NONE back after them.+ // A draw it does not suit takes none (Draw_Effect).+ void Set_Draw_Effect(unsigned effect, const float parameters[4]);+// What an additive draw (ONE, ONE) into the scene is worth, for the Glow option: the blend// takes the draw's colour times this through the blend factor, so fire, muzzle flashes and// laser cores pass white in the half float scene and the bloom's bright pass finds them, where@@ -401,8 +407,11 @@ private:float BlastLightDiffuse[BLAST_LIGHT_SLOTS][4];float BlastLightAmbient[BLAST_LIGHT_SLOTS][4];// A soft particle's way from a depth back to a distance, and one over the distance its fade- // takes (SOFT_PARTICLE_SAMPLING). Last, so only a program that fades has to declare it.+ // takes (SOFT_PARTICLE_SAMPLING). Only a program that fades or wears a look declares it.float SoftParticleDepth[4];+ // A per-object look's numbers (DRAW_EFFECT_SAMPLING). Last, so only such a program+ // declares it.+ float DrawEffectParameters[4];};// A draw that is painting the world and can take a shadow from the sun's map.bool Shadow_Receiving() const;@@ -494,6 +503,19 @@ private:bool Camera_Space_Draw() const;bool SmokeGlow;bool Smoke_Glow() const;+ // Set_Draw_Effect's look and numbers, and the look the current draw takes after the checks.+ unsigned DrawEffect;+ float DrawEffectNumbers[4];+ unsigned Draw_Effect() const;+ // The scene as it stood when the first cloaked draw of the frame needed it, at t8: one copy a+ // frame, taken at Set_Draw_Effect. The scene asks for the cloak only in its translucent pass,+ // after the opaque world, so the copy holds what is behind them. Refused for good when the device will not make it.+ ID3D11Texture2D * SceneColourCopy;+ ID3D11ShaderResourceView * SceneColourCopyView;+ bool SceneColourStale;+ bool SceneColourRefused;+ bool Take_Scene_Colour();+ void Release_Scene_Colour();float AdditiveGain;bool GlowDraw;bool Additive_Glow() const;@@ -812,6 +834,8 @@ private:ID3D11SamplerState * MapSamplers[2];// The scene's depth copy at t7, for the soft particles.ID3D11ShaderResourceView * SceneDepth;+ // The scene's colour copy at t8, for the cloak.+ ID3D11ShaderResourceView * SceneColour;ID3D11InputLayout * Layout;ID3D11Buffer * VertexBuffer;UINT VertexStride;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cppindex b154971d2..59ea43fa2 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp@@ -348,6 +348,25 @@ void Direct3D11_Set_Smoke_Glow(bool glow)}}+static bool DrawEffectsAllowed = true;++void Direct3D11_Set_Draw_Effect(unsigned effect, const float parameters[4])+{+ if (Active && DrawEffectsAllowed) {+ Backend.Set_Draw_Effect(effect, parameters);+ }+}++bool Direct3D11_Draw_Effects()+{+ return Active && DrawEffectsAllowed;+}++void Direct3D11_Allow_Draw_Effects(bool allowed)+{+ DrawEffectsAllowed = allowed;+}+void Direct3D11_Set_Glow_Draw(bool glow){if (Active) {diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex 7a3b307ff..8c3f8e732 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -171,6 +171,16 @@ void Direct3D11_Set_Scene_View(const float view[16]);// (DX11BackendClass::Set_Smoke_Glow). The sorting pool sets it around the smoke billboards' runs.void Direct3D11_Set_Smoke_Glow(bool glow);+// The look one object's draws are dressed in (DRAW_EFFECT_* in ffshader.h) and its four numbers+// (DX11BackendClass::Set_Draw_Effect). The mesh renderer sets it around a mesh's draws and puts+// zero back after them. -d3d9, -headless and the SDL3 port draw the object as they always did.+void Direct3D11_Set_Draw_Effect(unsigned effect, const float parameters[4]);++// Whether the looks are drawn at all: a Direct3D 11 frame is presenting and the Classic graphics+// setting is off. The scene asks before it leaves the heat vision pass out for one of them.+bool Direct3D11_Draw_Effects();+void Direct3D11_Allow_Draw_Effects(bool allowed);+// Whether the draws that follow take the Glow option's additive gain (DX11BackendClass::// Set_Glow_Draw). ShaderClass::Apply sends it from the shader's GLOW_ENABLE bit.void Direct3D11_Set_Glow_Draw(bool glow);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cppindex 910f785d8..ea0e1d905 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp@@ -75,6 +75,9 @@ void Direct3D11_Clear_Shadow_Parameters() {}bool Direct3D11_Fill_Smoke_Map(const float *, unsigned, float) { return false; }void Direct3D11_Set_Scene_View(const float [16]) {}void Direct3D11_Set_Smoke_Glow(bool) {}+void Direct3D11_Set_Draw_Effect(unsigned, const float [4]) {}+bool Direct3D11_Draw_Effects() { return false; }+void Direct3D11_Allow_Draw_Effects(bool) {}void Direct3D11_Set_Glow_Draw(bool) {}void Direct3D11_Set_Scene_Stand_In(struct IDirect3DBaseTexture9 *, struct IDirect3DSurface9 *) {}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cppindex 086d0ed89..f948ef99b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp@@ -50,6 +50,7 @@#include "dx8fvf.h"#include "dx8caps.h"#include "dx8rendererdebugger.h"+#include "dx11runtime.h"#include "wwdebug.h"#include "wwprofile.h"#include "wwmemlog.h"@@ -1879,6 +1880,13 @@ void DX8TextureCategoryClass::Render(void)//(gth) this if statement's contents are not tabbed to avoid perforce merge problems...if (!DX8RendererDebugger::Is_Enabled() || !mesh->Is_Disabled_By_Debugger()) {+ // The object's look on the Direct3D 11 frame (RTS3DScene::renderOneObject picks it), for this+ // mesh's draws only. A sorted mesh draws later, from the sorting pool, and goes without.+ const unsigned draw_effect = mesh->Get_Draw_Effect();+ if (draw_effect != 0) {+ Direct3D11_Set_Draw_Effect(draw_effect, mesh->Get_Draw_Effect_Parameters());+ }+if ((!!mesh->Peek_Model()->Get_Flag(MeshGeometryClass::SORT)) && WW3D::Is_Sorting_Enabled()) {renderer->Render_Sorted(mesh->Get_Base_Vertex_Offset(),mesh->Get_Bounding_Sphere());} else {@@ -1933,6 +1941,10 @@ void DX8TextureCategoryClass::Render(void)elserenderer->Render(mesh->Get_Base_Vertex_Offset());}+ if (draw_effect != 0) {+ static const float no_effect[4] = { 0.0f, 0.0f, 0.0f, 0.0f };+ Direct3D11_Set_Draw_Effect(0, no_effect);+ }//--------------------------------------------------------------------if (mesh->Get_ObjectScale() != 1.0f)DX8Wrapper::Set_DX8_Render_State(D3DRS_NORMALIZENORMALS, false);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cppindex 421c477ae..2c80eb74d 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp@@ -255,6 +255,9 @@ static bool generate_combiners(const CombinerDescription & description,// The soft particles ride on the Direct3D 11 text for the smoke's reason: the SDL3 backend binds// nothing at t7 and uploads nothing past SkyUp.const bool soft = volumetric && description.SoftParticle != SOFT_PARTICLE_NONE;+ // The per-object looks likewise: nothing past SoftParticleDepth reaches the SDL3 programs.+ const unsigned effect = (volumetric && description.DrawEffect < DRAW_EFFECT_COUNT)+ ? description.DrawEffect : DRAW_EFFECT_NONE;volumetric = volumetric && description.ShadowReceiving;if (description.StageCount == 0 || description.StageCount > MAXIMUM_COMBINER_STAGES) {return false;@@ -360,7 +363,7 @@ static bool generate_combiners(const CombinerDescription & description,// ones and the terrain's sun, so a program that reads them has to declare those too, unused:// without them a shadow matrix lands where the first light's direction is. A soft particle's// field closes the block, so a program that fades declares all of it.- if (description.ShadowReceiving || soft) {+ if (description.ShadowReceiving || soft || effect != DRAW_EFFECT_NONE) {char line[256];snprintf(line, sizeof(line)," float4 NormalLightDirection[%u];\n"@@ -381,9 +384,12 @@ static bool generate_combiners(const CombinerDescription & description," float4 Sky;\n"" float4 SkyUp;\n";}- if (volumetric || soft) {+ if (volumetric || soft || effect != DRAW_EFFECT_NONE) {hlsl += VOLUMETRIC_CONSTANTS;}+ if (effect != DRAW_EFFECT_NONE) {+ hlsl += DRAW_EFFECT_CONSTANTS;+ }hlsl += "};\n";if (description.ShadowReceiving) {hlsl += SHADOW_SAMPLING;@@ -394,6 +400,9 @@ static bool generate_combiners(const CombinerDescription & description,if (soft) {hlsl += SOFT_PARTICLE_SAMPLING;}+ if (effect != DRAW_EFFECT_NONE) {+ hlsl += DRAW_EFFECT_SAMPLING;+ }}else {for (unsigned stage = 0; stage < MAXIMUM_COMBINER_STAGES; ++stage) {@@ -461,6 +470,17 @@ static bool generate_combiners(const CombinerDescription & description,return false;}+ // After the fog and the alpha test: the cloak bends a picture that is fogged already, and a+ // texel the test threw away has no surface to dress.+ static const char * const effect_calls[DRAW_EFFECT_COUNT] = {+ "",+ " current = effect_outage(current, input.Position);\n",+ " current = effect_emp(current, input.Position);\n",+ " current = effect_cloak(current, input.Position);\n",+ " current = effect_revealed(current, input.Position);\n"+ };+ hlsl += effect_calls[effect];+// After the alpha test: faded before it, a sprite's edge against the ground would be clipped to// a hard line again, only a little further out.if (soft) {@@ -547,5 +567,9 @@ std::string CombinerShader_Key(const CombinerDescription & description)snprintf(field, sizeof(field), ":Z%u", description.SoftParticle);key += field;}+ if (description.DrawEffect != DRAW_EFFECT_NONE) {+ snprintf(field, sizeof(field), ":X%u", description.DrawEffect);+ key += field;+ }return key;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.hindex 4a5953338..0b0a122ea 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h@@ -112,6 +112,11 @@ struct CombinerDescription// a building. SOFT_PARTICLE_ALPHA fades the alpha alone, which is what a SRCALPHA blend reads;// SOFT_PARTICLE_COLOUR fades the colour as well, for a blend that adds the colour unweighted.unsigned SoftParticle = 0;++ // D3D11 only: a look the scene asked for on this one object (DRAW_EFFECT_*), written after the+ // fog and the alpha test (DRAW_EFFECT_SAMPLING). RTS3DScene::renderOneObject picks it and+ // the mesh renderer hands it to the backend around each of the object's draws.+ unsigned DrawEffect = 0;};enum@@ -121,6 +126,17 @@ enumSOFT_PARTICLE_COLOUR = 2};+// The per-object looks. The numbers are in the program key, so they do not move.+enum+{+ DRAW_EFFECT_NONE = 0,+ DRAW_EFFECT_OUTAGE = 1, ///< a building out of power: drained, cold, lights out, sparks+ DRAW_EFFECT_EMP = 2, ///< anything an EMP disabled: arcs crawling over it+ DRAW_EFFECT_CLOAK = 3, ///< own stealthed unit: what is behind it bent through it, a rim+ DRAW_EFFECT_REVEALED = 4, ///< enemy stealthed unit a detector found: hot edges, scan lines+ DRAW_EFFECT_COUNT = 5+};+// The constant block still carries this many normal mapped light slots, unread, so the shadow and// sky fields behind them keep their offsets.const unsigned NORMAL_MAPPED_LIGHTS = 4;@@ -448,6 +464,146 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;" float4 BlastLightAmbient[" BLAST_LIGHT_SLOTS_TEXT "];\n" \" float4 SoftParticleDepth;\n"+// The per-object looks (CombinerDescription::DrawEffect), Direct3D 11 only, declared after the+// whole block above: DrawEffectParameters is its last field. x is seconds on the wall clock, y a+// strength (the detector's pulse for the two stealth looks), z a seed from the object's id so two+// buildings do not flicker in step, w the object's own opacity for the cloak. The surface is taken+// back to the world through WorldFromClip the way the headlights take it, and faces the eye. The+// cloak reads the scene as it stood before the translucent objects went in, at t8, by pixel.+#define DRAW_EFFECT_CONSTANTS \+ " float4 DrawEffectParameters;\n"++#define DRAW_EFFECT_SAMPLING \+ "Texture2D SceneColour : register(t8);\n" \+ "\n" \+ "float effect_hash(float3 p)\n" \+ "{\n" \+ " return frac(sin(dot(p, float3(12.9898, 78.233, 37.719))) * 43758.5453);\n" \+ "}\n" \+ "\n" \+ "float effect_noise(float3 p)\n" \+ "{\n" \+ " float3 i = floor(p);\n" \+ " float3 f = frac(p);\n" \+ " f = f * f * (3.0 - 2.0 * f);\n" \+ " float a = lerp(effect_hash(i), effect_hash(i + float3(1, 0, 0)), f.x);\n" \+ " float b = lerp(effect_hash(i + float3(0, 1, 0)), effect_hash(i + float3(1, 1, 0)), f.x);\n" \+ " float c = lerp(effect_hash(i + float3(0, 0, 1)), effect_hash(i + float3(1, 0, 1)), f.x);\n" \+ " float d = lerp(effect_hash(i + float3(0, 1, 1)), effect_hash(i + float3(1, 1, 1)), f.x);\n" \+ " return lerp(lerp(a, b, f.y), lerp(c, d, f.y), f.z);\n" \+ "}\n" \+ "\n" \+ "void effect_surface(float4 position, out float3 world, out float3 surface, out float facing)\n" \+ "{\n" \+ " float2 ndc = float2(position.x * ShadowViewport.x * 2.0 - 1.0,\n" \+ " 1.0 - position.y * ShadowViewport.y * 2.0);\n" \+ " float4 at = mul(float4(ndc, position.z, 1.0), WorldFromClip);\n" \+ " world = at.xyz / at.w;\n" \+ " float4 eye = mul(float4(ndc, 0.0, 1.0), WorldFromClip);\n" \+ " float3 to_eye = normalize(eye.xyz / eye.w - world);\n" \+ " float3 across = cross(ddx(world), ddy(world));\n" \+ " surface = across * rsqrt(max(dot(across, across), 1e-20));\n" \+ " if (dot(surface, to_eye) < 0.0) surface = -surface;\n" \+ " facing = saturate(dot(surface, to_eye));\n" \+ "}\n" \+ "\n" \+ "/* Out of power. The colour drains to a cold grey and sags, the brightest texels, which on\n" \+ " this art are the windows, lamps and beacons, go out, and now and then the whole building\n" \+ " blinks dark or the lights catch for a moment. A few points on the walls short out in\n" \+ " blue-white for a sixth of a second each, past white so the bloom finds them. */\n" \+ "float4 effect_outage(float4 current, float4 position)\n" \+ "{\n" \+ " float3 world; float3 surface; float facing;\n" \+ " effect_surface(position, world, surface, facing);\n" \+ " float t = DrawEffectParameters.x;\n" \+ " float seed = DrawEffectParameters.z;\n" \+ " float grey = dot(current.rgb, float3(0.299, 0.587, 0.114));\n" \+ " float3 cold = grey * float3(0.80, 0.88, 1.0);\n" \+ " float stutter = effect_hash(float3(floor(t * 9.0 + seed * 31.0), seed * 97.0, 1.0));\n" \+ " float sag = 0.60 + 0.07 * sin(t * 1.7 + seed * 6.2832);\n" \+ " float dip = (stutter > 0.92) ? 0.6 : 1.0;\n" \+ " float relit = (stutter > 0.975) ? 1.0 : 0.0;\n" \+ " float lamp = smoothstep(0.55, 0.9, max(current.r, max(current.g, current.b)));\n" \+ " float3 dark = cold * sag * dip * (1.0 - 0.8 * lamp * (1.0 - relit));\n" \+ " float3 cell = floor(world * 0.25);\n" \+ " float3 inside = frac(world * 0.25) - 0.5;\n" \+ " float slot = floor(t * 6.0 + seed * 7.0);\n" \+ " float live = step(0.9975, effect_hash(cell + float3(slot * 1.31, seed * 13.0, 0.0)));\n" \+ " float3 point_at = float3(effect_hash(cell + 3.1), effect_hash(cell + 5.7), effect_hash(cell + 7.3)) - 0.5;\n" \+ " float spark = live * saturate(1.0 - length((inside - point_at * 0.6) - surface * dot(inside - point_at * 0.6, surface)) * 4.0);\n" \+ " current.rgb = lerp(current.rgb, dark, DrawEffectParameters.y)\n" \+ " + spark * spark * saturate(grey * 4.0) * float3(1.6, 2.2, 3.0);\n" \+ " return current;\n" \+ "}\n" \+ "\n" \+ "/* Caught by an EMP. The surface dims a little towards blue and thin lines of current crawl\n" \+ " over it: two bands of moving noise at two sizes, strobing, with a cold rim on top. */\n" \+ "float4 effect_emp(float4 current, float4 position)\n" \+ "{\n" \+ " float3 world; float3 surface; float facing;\n" \+ " effect_surface(position, world, surface, facing);\n" \+ " float t = DrawEffectParameters.x;\n" \+ " float seed = DrawEffectParameters.z;\n" \+ " float grey = dot(current.rgb, float3(0.299, 0.587, 0.114));\n" \+ " float3 base = lerp(current.rgb, grey * float3(0.70, 0.80, 1.0), 0.55) * 0.75;\n" \+ " float wide = effect_noise(world * 0.11 + float3(seed * 17.0, 0.0, t * 1.6));\n" \+ " float fine = effect_noise(world * 0.29 - float3(0.0, t * 2.3, seed * 9.0));\n" \+ " float line_wide = saturate(1.0 - abs(wide - 0.5) * 28.0);\n" \+ " float line_fine = saturate(1.0 - abs(fine - 0.5) * 40.0);\n" \+ " float strobe = step(0.3, effect_hash(float3(floor(t * 24.0), seed * 41.0, 2.0)));\n" \+ " float arc = (line_wide * line_wide + 0.7 * line_fine * line_fine) * strobe;\n" \+ " float rim = pow(1.0 - facing, 3.0) * (0.55 + 0.45 * sin(t * 37.0 + seed * 6.2832));\n" \+ " current.rgb = base + (arc * 2.4 + rim * 0.5) * float3(0.45, 0.72, 1.0) * DrawEffectParameters.y;\n" \+ " return current;\n" \+ "}\n" \+ "\n" \+ "/* Own stealthed unit. What is behind it shows through, bent by a slow ripple that swims over\n" \+ " the body and bends harder towards the outline, with a little of the unit itself left in so\n" \+ " its owner can still read what it is, and a cold rim. Detected, the rim pulses amber. The\n" \+ " alpha goes back up to the texel's own, because the shade already holds the mix. */\n" \+ "float4 effect_cloak(float4 current, float4 position)\n" \+ "{\n" \+ " float3 world; float3 surface; float facing;\n" \+ " effect_surface(position, world, surface, facing);\n" \+ " float t = DrawEffectParameters.x;\n" \+ " float opacity = max(DrawEffectParameters.w, 0.05);\n" \+ " float rim = pow(1.0 - facing, 2.5);\n" \+ " float swim_x = effect_noise(world * 0.35 + float3(t * 0.7, t * 0.4, t * 1.1)) - 0.5;\n" \+ " float swim_y = effect_noise(world * 0.35 + float3(5.2 - t * 0.5, 1.3, t * 0.9)) - 0.5;\n" \+ " float2 screen = 1.0 / ShadowViewport.xy;\n" \+ " float2 bend = float2(swim_x, swim_y) * (0.012 + 0.03 * rim) * screen.y + surface.xy * rim * 0.006 * screen.y;\n" \+ " int2 at = int2(clamp(position.xy + bend, float2(0.0, 0.0), screen - 1.0));\n" \+ " float3 behind = SceneColour.Load(int3(at, 0)).rgb;\n" \+ " float band = smoothstep(0.92, 1.0, sin(world.z * 0.35 - t * 3.0)) * 0.12;\n" \+ " float own = saturate(opacity * 0.6);\n" \+ " float3 edge = lerp(float3(0.45, 0.85, 1.0), float3(1.0, 0.55, 0.15), DrawEffectParameters.y);\n" \+ " float edge_gain = 0.45 + 0.35 * DrawEffectParameters.y * (0.5 + 0.5 * sin(t * 9.0));\n" \+ " current.rgb = lerp(behind * float3(0.93, 0.98, 1.04), current.rgb, own)\n" \+ " + (rim * edge_gain + band) * edge;\n" \+ " current.a = saturate(current.a / opacity);\n" \+ " return current;\n" \+ "}\n" \+ "\n" \+ "/* Enemy stealthed unit a detector found. The paint drains to a dull warm grey, the outline\n" \+ " burns red-orange, scan lines run up it in world height, and each sweep of the detector\n" \+ " (the strength, one at the sweep and falling after) brightens all of it. */\n" \+ "float4 effect_revealed(float4 current, float4 position)\n" \+ "{\n" \+ " float3 world; float3 surface; float facing;\n" \+ " effect_surface(position, world, surface, facing);\n" \+ " float t = DrawEffectParameters.x;\n" \+ " float pulse = DrawEffectParameters.y;\n" \+ " float grey = dot(current.rgb, float3(0.299, 0.587, 0.114));\n" \+ " float3 heat = float3(1.0, 0.36, 0.10);\n" \+ " float rim = pow(1.0 - facing, 2.0);\n" \+ " float scan = smoothstep(0.80, 1.0, frac(world.z * 0.4 - t * 1.5));\n" \+ " float sweep = smoothstep(0.96, 1.0, sin(world.z * 0.08 - t * 2.2));\n" \+ " float glow = (rim * 1.7 + scan * 0.35 + sweep * 0.6 + 0.12) * (0.55 + 0.75 * pulse);\n" \+ " current.rgb = grey * float3(0.85, 0.62, 0.52) * 0.85 + heat * glow;\n" \+ " return current;\n" \+ "}\n" \+ "\n"+// SHADOW_APPLY with the smoke in it. A particle takes the shade whatever its own brightness: the// threshold is there for ground under the shroud, and on smoke it tied the shade to the colour, so// the fire's glow, lifting a dark plume over the threshold, made it take more shade and go darker.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cppindex fdf0984a4..a99e99c60 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.cpp@@ -169,8 +169,10 @@ MeshClass::MeshClass(void) :MeshDebugId(MeshDebugIdCount++),m_alphaOverride(1.0f),m_materialPassAlphaOverride(1.0f),- m_materialPassEmissiveOverride(1.0f)+ m_materialPassEmissiveOverride(1.0f),+ m_drawEffect(0){+ m_drawEffectParameters[0] = m_drawEffectParameters[1] = m_drawEffectParameters[2] = m_drawEffectParameters[3] = 0.0f;}@@ -198,8 +200,10 @@ MeshClass::MeshClass(const MeshClass & that) :MeshDebugId(MeshDebugIdCount++),m_alphaOverride(1.0f),m_materialPassAlphaOverride(1.0f),- m_materialPassEmissiveOverride(1.0f)+ m_materialPassEmissiveOverride(1.0f),+ m_drawEffect(0){+ m_drawEffectParameters[0] = m_drawEffectParameters[1] = m_drawEffectParameters[2] = m_drawEffectParameters[3] = 0.0f;REF_PTR_SET(Model,that.Model); // mesh instances share models by default}@@ -688,6 +692,7 @@ void MeshClass::Render(RenderInfoClass & rinfo)m_alphaOverride = rinfo.alphaOverride;m_materialPassAlphaOverride = rinfo.materialPassAlphaOverride;m_materialPassEmissiveOverride = rinfo.materialPassEmissiveOverride;+ Take_Draw_Effect(rinfo);WW3D::Add_To_Static_Sort_List(this, sort_level);} else {@@ -725,6 +730,7 @@ void MeshClass::Render(RenderInfoClass & rinfo)m_alphaOverride = rinfo.alphaOverride;m_materialPassAlphaOverride = rinfo.materialPassAlphaOverride;m_materialPassEmissiveOverride = rinfo.materialPassEmissiveOverride;+ Take_Draw_Effect(rinfo);}/*@@ -821,6 +827,15 @@ void MeshClass::Render(RenderInfoClass & rinfo)}+void MeshClass::Take_Draw_Effect(const RenderInfoClass & rinfo)+{+ m_drawEffect = rinfo.drawEffect;+ for (int i = 0; i < 4; ++i) {+ m_drawEffectParameters[i] = rinfo.drawEffectParameters[i];+ }+}++/************************************************************************************************ MeshClass::Render_Material_Pass -- Render a procedural material pass for this mesh ** *diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.hindex dfd335c77..578ec7794 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mesh.h@@ -146,6 +146,9 @@ public:void Set_Lighting_Environment(LightEnvironmentClass * light_env) { if (light_env) {m_localLightEnv=*light_env;LightEnvironment = &m_localLightEnv;} else {LightEnvironment = NULL;} }LightEnvironmentClass * Get_Lighting_Environment(void) { return LightEnvironment; }inline float Get_Alpha_Override(void) { return m_alphaOverride;}+ inline unsigned Get_Draw_Effect(void) const { return m_drawEffect;}+ inline const float * Get_Draw_Effect_Parameters(void) const { return m_drawEffectParameters;}+ void Take_Draw_Effect(const RenderInfoClass & rinfo);void Set_Next_Visible_Skin(MeshClass * next_visible) { NextVisibleSkin = next_visible; }MeshClass * Peek_Next_Visible_Skin(void) { return NextVisibleSkin; }@@ -187,6 +190,8 @@ protected:float m_alphaOverride; //added for 'Generals' to allow variable alpha on meshes.float m_materialPassEmissiveOverride; //added for 'Generals' to allow variable emissive on additional passes.float m_materialPassAlphaOverride; //added for 'Generals' to allow variable alpha on additional render passes.+ unsigned m_drawEffect; // RenderInfoClass::drawEffect as the mesh was last submitted with it+ float m_drawEffectParameters[4];int BaseVertexOffset; // offset to our first vertex in whatever vb this mesh is in.MeshClass * NextVisibleSkin; // linked list of visible skinsdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.cppindex 609b9181a..b9829ddd6 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.cpp@@ -60,8 +60,10 @@ RenderInfoClass::RenderInfoClass(CameraClass & cam) :Texture_Projector(NULL),alphaOverride(1.0f),materialPassAlphaOverride(1.0f),- materialPassEmissiveOverride(1.0f)-{+ materialPassEmissiveOverride(1.0f),+ drawEffect(0)+{+ drawEffectParameters[0] = drawEffectParameters[1] = drawEffectParameters[2] = drawEffectParameters[3] = 0.0f;// Need to have one entry in the override flags stack, initialize it to default values.OverrideFlag[OverrideFlagLevel]=RINFO_OVERRIDE_DEFAULT;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.hindex 184536a2b..dcb0c2d05 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/rinfo.h@@ -106,6 +106,11 @@ public:float alphaOverride; //added for 'Generals' to allow variable alpha -MWfloat materialPassAlphaOverride; ////added for 'Generals' to allow variable alpha on additional render passes.-MWfloat materialPassEmissiveOverride; ////added for 'Generals' to allow variable emissive on additional render passes.-MW+ // The look the scene asked for on this object (DRAW_EFFECT_* in ffshader.h) and its four+ // numbers, carried to each mesh like the alpha above and handed to the Direct3D 11 backend+ // around the mesh's draws. Zero is none, and every other renderer ignores it.+ unsigned drawEffect;+ float drawEffectParameters[4];LightEnvironmentClass* light_environment;diff --git a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp b/GeneralsMD/Code/Tests/test_ffshadercompile.cppindex ad480ca42..36da8473b 100644--- a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp+++ b/GeneralsMD/Code/Tests/test_ffshadercompile.cpp@@ -328,3 +328,51 @@ TEST(ffshadercompile_a_soft_particle_fades_into_the_scene_depth_on_d3d11_only)CHECK(compiles(compile, additive, D3D11_PROFILE));CHECK(compiles(compile, smoke, D3D11_PROFILE));}++// Each per-object look is its own program on Direct3D 11, written after the fog and declaring the+// whole constant block up to its own field, with or without the sun's map. Only the cloak calls+// the function that reads the scene's copy at t8. SDL3 and D3D9 get none of it.+TEST(ffshadercompile_each_draw_effect_compiles_on_d3d11_only)+{+ D3DCompileFunction compile = load_compiler();+ for (unsigned shadow = 0; shadow < 2; ++shadow) {+ for (unsigned effect = DRAW_EFFECT_OUTAGE; effect < DRAW_EFFECT_COUNT; ++effect) {+ CombinerDescription description;+ memset(&description, 0, sizeof(description));+ description.StageCount = 1;+ description.Stages[0] = one_stage(D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE,+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 0, true);+ description.PixelPipeline.FogEnabled = true;+ description.ShadowReceiving = shadow != 0;+ const std::string plain_key = CombinerShader_Key(description);+ description.DrawEffect = effect;+ char suffix[8];+ snprintf(suffix, sizeof(suffix), ":X%u", effect);+ CHECK(CombinerShader_Key(description) == plain_key + suffix);++ std::string eleven;+ CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_D3D11, eleven));+ CHECK(eleven.find("DrawEffectParameters;") > eleven.find("SoftParticleDepth;"));+ const size_t fog = eleven.find("FogColour.rgb, current.rgb");+ const size_t call = eleven.find("current = effect_");+ CHECK(fog != std::string::npos);+ CHECK(call != std::string::npos);+ CHECK(fog < call);+ CHECK((eleven.find("current = effect_cloak(") != std::string::npos) == (effect == DRAW_EFFECT_CLOAK));++ std::string sdl;+ std::string nine;+ CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_SDL3_GPU, sdl));+ CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_D3D9, nine));+ CHECK(sdl.find("effect_") == std::string::npos);+ CHECK(nine.find("effect_") == std::string::npos);++ if (compile != NULL) {+ CHECK(compiles(compile, eleven, D3D11_PROFILE));+ }+ }+ }+ if (compile == NULL) {+ printf(" d3dcompiler_47.dll not present, skipping the compile\n");+ }+}