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
fix(w3ddevice): soft particles fade no deeper than the sprite is wide
Olcay Seyganf91b4f60ef8c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 879fab0e2..f5fa2c8c3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1372,7 +1372,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A nuke flattens a town from the middle out. EA's missile did all its damage on one frame a second after it landed, so every building under the cloud blew up together. The blast now rolls out from the point of impact with the orange heat ring and reaches the edge six tenths of a second later, levelling each building and toppling each tree as it gets there, and burning the ground in the same ring. What each thing takes is unchanged. A replay recorded before this, with a nuke in it, will not play back the same.- An explosion lights everything around it, smoothly. On the default renderer the light of a blast reaches every tank, soldier, building and patch of ground it can see, fading out with distance, where the ground used to brighten in blocky squares and a model took only four lights at once, so in a big fight half the tanks next to a burning wreck stayed dark. The 32 blasts nearest the camera light at the same time, and a wall with its back to the fire stays in shadow. The light brightens what it falls on by three quarters at most: a nuke's took the ground to white within a few frames until it was held there.- A bright cloud no longer shows what is behind it as a line drawing. Inside a nuke's white cloud, or a falling War Factory's fireball, every tree and wreck under it used to come out as a thin grey outline, and the picture's sharpening ringed each dark piece in white. Both stop where the frame is bright.-- 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. This is the default renderer; Classic and the old renderer keep the hard edge they had in 2003.+- 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.- 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/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex 1cb3259af..2fda9a4ab 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -644,7 +644,9 @@ static const float SMOKE_SELF_SHADOW_CURVE = 16.0f;// blastcheck frames of 2026-10-06, and at zero it is the unfaded game's cut lines outright. Twelve// on the smoothstep (SOFT_PARTICLE_SAMPLING) is smooth in both and keeps the toxin carpet whole; the// islands once blamed on twelve were the straight ramp's creases, which the smoothstep took away.-// Twenty starts to thin the carpet.+// Twenty starts to thin the carpet. It is the longest fade and not the only one: a sprite fades+// over its own half width where that is shorter, so a mine's flare a few units across, hanging+// under one unit above the ground, is not faded away entire.static const float SOFT_PARTICLE_FADE_UNITS = 12.0f;// Each caster is a disc facing the sun, drawn as a four corner strip whose corners come from the@@ -1975,6 +1977,7 @@ bool DX11BackendClass::Build_Vertex_Description(VertexPipelineDescription & descdescription.FogEnabled = RenderStates.Get_Render_State(D3DRS_FOGENABLE) != FALSE;description.FogVertexMode = RenderStates.Get_Render_State(D3DRS_FOGVERTEXMODE);description.SmokeGlow = Smoke_Glow();+ description.SoftParticle = Soft_Particle() != SOFT_PARTICLE_NONE;return true;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cppindex 3851553b2..421c477ae 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp@@ -465,8 +465,8 @@ static bool generate_combiners(const CombinerDescription & description,// a hard line again, only a little further out.if (soft) {hlsl += (description.SoftParticle == SOFT_PARTICLE_COLOUR)- ? " current *= soft_particle_fade(input.Position);\n"- : " current.a *= soft_particle_fade(input.Position);\n";+ ? " current *= soft_particle_fade(input.Position, input.Specular.a);\n"+ : " current.a *= soft_particle_fade(input.Position, input.Specular.a);\n";}hlsl +=diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.hindex 4a660b094..4a5953338 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h@@ -415,18 +415,21 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;// texel at the pixel's own position, so the viewport's half pixel shift applies to both alike. Both// depths go back to the distance from the eye through the projection the particles are drawn with,// w = SoftParticleDepth.x / (z * SoftParticleDepth.y - SoftParticleDepth.z), which is the same-// matrix the world was drawn with; .w is one over the distance the fade takes, in world units. The-// ramp is a smoothstep: a straight one left a crease at both ends of every sprite's fade, and a-// toxin cloud is hundreds of sprites lying on the ground, whose creases stacked into contour lines.+// matrix the world was drawn with; .w is one over the longest distance the fade takes, in world+// units. A sprite never fades over more than its own half width, which the vertex half hands on in+// the specular alpha (VertexPipelineDescription::SoftParticle): a mine's flare hangs under a unit+// above the ground, and twelve units erased it whole. The ramp is a smoothstep: a straight one+// left a crease at both ends of every sprite's fade, and a toxin cloud is hundreds of sprites lying+// on the ground, whose creases stacked into contour lines.#define SOFT_PARTICLE_SAMPLING \"Texture2D SceneDepth : register(t7);\n" \"\n" \- "float soft_particle_fade(float4 position)\n" \+ "float soft_particle_fade(float4 position, float half_width)\n" \"{\n" \" float scene = SceneDepth.Load(int3(position.xy, 0)).r;\n" \" float behind = SoftParticleDepth.x / (scene * SoftParticleDepth.y - SoftParticleDepth.z);\n" \" float here = SoftParticleDepth.x / (position.z * SoftParticleDepth.y - SoftParticleDepth.z);\n" \- " float fade = saturate((behind - here) * SoftParticleDepth.w);\n" \+ " float fade = saturate((behind - here) * max(SoftParticleDepth.w, 1.0 / half_width));\n" \" return fade * fade * (3.0 - 2.0 * fade);\n" \"}\n" \"\n"diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cppindex 8834b4620..26bffa97d 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp@@ -510,6 +510,10 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,&& (description.LightingEnabled || !has_normal(description.FVF) || is_pretransformed(description.FVF))) {return false;}+ if (description.SoftParticle+ && (texture_coordinate_set_count(description.FVF) < 2 || is_pretransformed(description.FVF))) {+ return false;+ }// A pre-transformed vertex has been through the transform, the lighting and the coordinate// generation already: its position is in pixels, its colour is in the vertex, and D3D9 reads@@ -624,6 +628,11 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,}}+ // The sprite's half width, for the pixel half's fade; nothing else reads the specular alpha.+ if (description.SoftParticle) {+ body += " output.Specular.a = input.TexCoord1.x;\n";+ }+if (description.FogEnabled) {// FogParameters carries the start, the end and the density; the mode picks which two of// them are read. D3D9's factor is the weight of the unfogged colour, so 1 is no fog.@@ -752,5 +761,8 @@ std::string VertexShader_Key(const VertexPipelineDescription & description)if (description.SmokeGlow) {key += ":G";}+ if (description.SoftParticle) {+ key += ":Z";+ }return key;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.hindex 82b336048..8104fa3dd 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h@@ -137,6 +137,12 @@ struct VertexPipelineDescription// shade (CombinerDescription::SmokeGlow). Refused on a lit draw or a format with no normal.// Initialised here for a caller that fills the rest field by field.bool SmokeGlow = false;++ // A sorted particle billboard that fades into the scene's depth: the sorting pool writes the+ // sprite's half width into the first of the second coordinate set (sortingrenderer.cpp,+ // Copy_Batch_Vertices), and the program hands it on in the specular colour's alpha, which the+ // pixel half's fade reads (SOFT_PARTICLE_SAMPLING). Refused on a format with one set or none.+ bool SoftParticle = false;};// Which profile the generated text is for. The two differ in the output semantic and in how thediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cppindex 24970ef7f..e905c5e5c 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp@@ -597,7 +597,18 @@ static void Copy_Batch_Vertices(int chunk,void* context)const VertexFormatXYZNDUV2* src_verts=overlapping_node_vertices[entry.idx];VertexFormatXYZNDUV2* dest_verts=job->vertices+job->offsets[e].vertex;if (Entry_Is_Quad(entry)) {- memcpy(dest_verts,src_verts+entry.tri.i,sizeof(VertexFormatXYZNDUV2)*4);+ const VertexFormatXYZNDUV2* quad=src_verts+entry.tri.i;+ memcpy(dest_verts,quad,sizeof(VertexFormatXYZNDUV2)*4);+ // The billboard's half width, the longest its soft fade may take (SOFT_PARTICLE_SAMPLING):+ // the first two corners are one side apart. A billboard reads one coordinate set.+ const float dx=quad[1].x-quad[0].x;+ const float dy=quad[1].y-quad[0].y;+ const float dz=quad[1].z-quad[0].z;+ const float half_width=0.5f*sqrtf(dx*dx+dy*dy+dz*dz);+ dest_verts[0].u2=half_width;+ dest_verts[1].u2=half_width;+ dest_verts[2].u2=half_width;+ dest_verts[3].u2=half_width;}else {dest_verts[0]=src_verts[entry.tri.i];diff --git a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp b/GeneralsMD/Code/Tests/test_ffshadercompile.cppindex 8d025ac0c..ad480ca42 100644--- a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp+++ b/GeneralsMD/Code/Tests/test_ffshadercompile.cpp@@ -300,7 +300,7 @@ TEST(ffshadercompile_a_soft_particle_fades_into_the_scene_depth_on_d3d11_only)CHECK(additive.find("SoftParticleDepth") > additive.find("BlastLightAmbient"));CHECK(additive.find("register(t5)") == std::string::npos);const size_t clip = additive.find("clip(");- const size_t fade = additive.find("current *= soft_particle_fade(input.Position);");+ const size_t fade = additive.find("current *= soft_particle_fade(input.Position, input.Specular.a);");CHECK(clip != std::string::npos);CHECK(fade != std::string::npos);CHECK(clip < fade);@@ -317,7 +317,7 @@ TEST(ffshadercompile_a_soft_particle_fades_into_the_scene_depth_on_d3d11_only)description.SoftParticle = SOFT_PARTICLE_ALPHA;std::string smoke;CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_D3D11, smoke));- CHECK(smoke.find("current.a *= soft_particle_fade(input.Position);") != std::string::npos);+ CHECK(smoke.find("current.a *= soft_particle_fade(input.Position, input.Specular.a);") != std::string::npos);CHECK(smoke.find("blast_reaching(input.Position)") > smoke.find("light_reaching(input.Position)"));D3DCompileFunction compile = load_compiler();diff --git a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp b/GeneralsMD/Code/Tests/test_ffvertexcompile.cppindex 7b11244ac..00b56f4b7 100644--- a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp+++ b/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp@@ -242,3 +242,35 @@ TEST(ffvertexcompile_the_smoke_glow_rides_the_specular_slot)CHECK(VertexShader_Generate(glow, VERTEX_SHADER_TARGET_D3D11, glow_hlsl));CHECK(compiles(compile, glow_hlsl, D3D11_PROFILE));}++// A soft billboard's half width rides the specular alpha out of the second coordinate set, after+// the glow wrote the colour, so the pixel half's fade can read it. Keyed apart, and refused on a+// format with one coordinate set.+TEST(ffvertexcompile_a_soft_billboard_hands_its_half_width_on)+{+ VertexPipelineDescription glow = plain_description();+ glow.SmokeGlow = true;+ VertexPipelineDescription soft = glow;+ soft.SoftParticle = true;++ std::string hlsl;+ CHECK(VertexShader_Generate(soft, VERTEX_SHADER_TARGET_D3D11, hlsl));+ const size_t colour = hlsl.find("output.Specular = float4(input.Normal, 0.0);");+ const size_t width = hlsl.find("output.Specular.a = input.TexCoord1.x;");+ CHECK(colour != std::string::npos);+ CHECK(width != std::string::npos);+ CHECK(colour < width);+ CHECK(VertexShader_Key(soft) == VertexShader_Key(glow) + ":Z");++ VertexPipelineDescription one_set = soft;+ one_set.FVF = D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1|D3DFVF_DIFFUSE;+ CHECK(!VertexShader_Generate(one_set, VERTEX_SHADER_TARGET_D3D11, hlsl));++ D3DCompileFunction compile = load_compiler();+ if (compile == NULL) {+ printf(" d3dcompiler_47.dll not present, skipping the compile\n");+ return;+ }+ CHECK(VertexShader_Generate(soft, VERTEX_SHADER_TARGET_D3D11, hlsl));+ CHECK(compiles(compile, hlsl, D3D11_PROFILE));+}