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): -volsmoke tank plume in soft tongues, twice as tall on High

Olcay Seygan7155c749eb4e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4bb6169e3..6e255fe7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -112,7 +112,7 @@ found and fixed, EA's own, not port damage.**
## Smoke simulation
- Options > Effects has a Smoke Simulation box. On Low or High a tank's cook-off, a shell's dirt fountain and a nuclear mushroom are a moving body of air rather than flat sprites: the smoke rolls, rises with the heat, settles as dust and parts round the buildings in its way. Off is the default, and Off draws exactly the picture the game drew before. The box works mid-match, the next frame after you press Accept, on the default renderer; the Direct3D 9 renderer and the Classic graphics setting hide it.
-- A tank goes up the way the footage of a real one does. Orange flame and black smoke burst out low along its own hull, long under an Overlord and short under a Crusader, and roll along the ground off both ends over a skirt of pale dust. A ragged white-yellow plume of fire shoots up out of the hull top, taller than the tank is long and opening as it climbs, and in about a second it has cooled to grey-brown smoke. The glowing ball and the rays round it are gone, and so is the ring on the ground. Shells that hit a tank's armour no longer throw a fountain of dirt off it, and the scrap flying off a dead tank keeps its own sparks and smoke trails instead of dragging pale rays and brown tentacles through the air.
+- A tank goes up the way the footage of a real one does. Orange flame and black smoke burst out low along its own hull, long under an Overlord and short under a Crusader, and roll along the ground off both ends over a skirt of pale dust. A ragged white-yellow plume of fire shoots up out of the hull top in flickering tongues, on High about twice as tall as the fire is wide and on Low about as tall, and in about a second it has cooled to grey-brown smoke. The glowing ball and the rays round it are gone, and so is the ring on the ground. Shells that hit a tank's armour no longer throw a fountain of dirt off it, and the scrap flying off a dead tank keeps its own sparks and smoke trails instead of dragging pale rays and brown tentacles through the air.
- Every other smoke goes the same way while it is on: missile and rocket trails, the dust behind a tank, a burning building's column, muzzle smoke. They are fed into one body of air round the camera instead of being drawn as sprites, and a unit moving through it pushes it. A tank's hull shoves the smoke aside and leaves a turning wake, a jet drags a sheet of it down between two wingtip vortices, and a helicopter hovering low flattens a burning column into a dark ring on the ground and lifts a band of dust round itself. A blast's front pushes the smoke already hanging round it outwards. Units you cannot see push nothing, so the smoke never gives away a stealthed tank or an unscouted base.
- It costs the graphics card. Three armies and three superweapons on Twilight Flame at 1920x1080, on an RTX 2060: 5.2 ms of GPU time a frame with it Off, 8.6 on Low and 10.0 to 10.2 on High; the frame itself took 5.3, 5.6 and 6.9 to 7.2 ms. Low runs half as many blasts at once in a coarser body of air, so a weak card should leave it Off or take Low.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp
index 32a8488eb..a350c309b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/DX11VolumeSmoke.cpp
@@ -79,7 +79,8 @@
namespace {
// Two atlases: the small one for tanks and shells, the big one for nuclear blasts. The slab
-// counts are the setting's (Quality below); a change of setting builds the atlases again.
+// counts and the small one's height are the setting's (Quality below); a change of setting builds
+// the atlases again.
struct TierShape { unsigned gx, gy, gz, slabs, first; };
TierShape TierShapes[2] = { { 48, 48, 40, 24, 0 }, { 96, 96, 80, 2, 24 } };
const unsigned MaxVolumes = 26; // both tiers' slabs at High, the small tier's first
@@ -93,8 +94,10 @@ const unsigned NoiseSide = 32;
// volumes at once, 8 pressure sweeps for 14, a march step half as long again.
// ponytail: a coarser Low grid needs the timelines' cell constants scaled with it; do that if
// Low still costs too much on a weak card.
-struct Quality { unsigned slabs[2]; unsigned sweeps; float stepCells; };
-const Quality Qualities[3] = { { { 0, 0 }, 0, 0.0f }, { { 12, 1 }, 8, 0.9f }, { { 24, 2 }, 14, 0.6f } }; // sweeps even, so the pressure ends where it started
+// High's small grid is 56 cells tall where Low's is 40, so a tank's plume has room to climb to
+// twice its base's width under the grid's top (Low keeps the shorter plume and the cheaper grid).
+struct Quality { unsigned slabs[2]; unsigned sweeps; float stepCells; unsigned smallHeight; };
+const Quality Qualities[3] = { { { 0, 0 }, 0, 0.0f, 40 }, { { 12, 1 }, 8, 0.9f, 40 }, { { 24, 2 }, 14, 0.6f, 56 } }; // sweeps even, so the pressure ends where it started
int level = 0; // the setting the atlases were last made for
// The world, in game units (a tank is about 30, 7 m: a unit is about 0.23 m).
@@ -803,6 +806,19 @@ float4 main(float4 position : SV_Position) : SV_Target
#endif
continue;
}
+#ifndef AIR
+ // Where a plume is two or three cells across, the trilinear cells came out as a staircase,
+ // flat-topped blocks with square notches. The lookup is pushed about by up to a cell along
+ // noise that drifts upwards, so an edge breaks into ragged, flickering tongues instead.
+ {
+ float3 q = cell / 6 + float3(Slab.x * 0.37, 0, -Camera.w * 0.6);
+ float3 warp = float3(Noise.SampleLevel(Wrap, q, 0), Noise.SampleLevel(Wrap, q + 0.31, 0),
+ Noise.SampleLevel(Wrap, q + 0.67, 0)) - 0.5;
+ clamped = clamp(cell + warp * 2, float3(0, 0, 0), float3(GX - 1, GY - 1, GZ - 1));
+ uvw = float3((clamped.x + 0.5) / GX, (clamped.y + 0.5) / GY, (clamped.z + 0.5 + slabBase) / (GZ * SLABS));
+ dd = Den.SampleLevel(Linear, uvw, 0);
+ }
+#endif
float n = Noise.SampleLevel(Wrap, cell / 9 + float3(Slab.x * 0.37, 0, -Camera.w * 0.04), 0);
// the condensation shell: white, thin, over the upper half, for a second or two
float shell = 0;
@@ -981,6 +997,7 @@ bool requested()
lastReport = 0;
level = want;
TierShapes[0].slabs = Qualities[level].slabs[0];
+ TierShapes[0].gz = Qualities[level].smallHeight;
TierShapes[1].slabs = Qualities[level].slabs[1];
TierShapes[1].first = TierShapes[0].slabs;
DEBUG_LOG(("VOLSMOKE: setting %s\n", level == 0 ? "Off" : level == 1 ? "Low" : "High"));
@@ -1215,8 +1232,8 @@ bool makeState(DX11BackendClass *backend, ID3D11Device *device)
state.refused = true;
return false;
}
- DEBUG_LOG(("VOLSMOKE: programs, %u + %u volumes and a %ux%ux%u air at %.1f units a cell made in %.1f ms\n",
- TierShapes[0].slabs, TierShapes[1].slabs, air.gx, air.gy, air.gz, air.cell, DX11Resource_Milliseconds_Now() - started));
+ DEBUG_LOG(("VOLSMOKE: programs, %u + %u volumes (the small %u cells tall) and a %ux%ux%u air at %.1f units a cell made in %.1f ms\n",
+ TierShapes[0].slabs, TierShapes[1].slabs, TierShapes[0].gz, air.gx, air.gy, air.gz, air.cell, DX11Resource_Milliseconds_Now() - started));
return true;
}
@@ -1348,17 +1365,17 @@ void schedule(const Volume &volume, unsigned slab, float t, DrawConstants *draw)
}
// The plume, the photo's tallest part: ten to twelve thin jets of white-hot fire and dust
// shot up out of the hull top in the first half second, each to its own height, fanning out
- // as they climb, so the flare is ragged and opens upwards. A jet's path is at most 24 cells
- // long and its head never more than 12 cells off the blast's axis, where the grid's round
- // sides start to fade the smoke out. The tallest heads, lifted on by the heat still in them,
- // do reach the fade under the grid's top, which softens them; at 20 the plume stood only
- // half again as high as the hull's top, too low for the photo. Each lays
+ // as they climb, so the flare is ragged and opens upwards. The tallest is set for about
+ // twice the base band's length once the heat has lifted it on, sixteen cells short of the
+ // grid's top (24 on Low's 40, 40 on High's 56), and no head goes more than 15 cells off the
+ // blast's axis, where the grid's round sides fade the smoke out by a few percent. With 12 a
+ // High plume, twice as tall, came out a narrow pillar. Each lays
// down thin smoke at a rate that goes with its speed, the same a cell along the whole jet,
// and pushes the air only lightly. A thick jet, a hard push or a fixed rate carried the
// smoke along with the head and left a round ball at the top with nothing under it. The
// fire burns brighter for the first second (soot[3] below), so the plume flares white and
// then hangs as grey-brown smoke and dust.
- const float reach = (std::min)((std::max)(2.3f * L + 1.7f * W, 12.0f), 24.0f);
+ const float reach = (std::min)((std::max)(2.2f * (2.3f * L + 1.7f * W), 12.0f), TierShapes[0].gz - 16.0f);
const unsigned jets = 10 + unsigned(unit(850) * 2.99f);
for (unsigned j = 0; j < jets; ++j) {
auto field = [&](unsigned f) { return unit(1000 + 16 * j + f); };
@@ -1366,19 +1383,19 @@ void schedule(const Volume &volume, unsigned slab, float t, DrawConstants *draw)
// round ball there
const float age = t - 0.15f * field(0), slows = 0.18f;
if (age < 0 || age > 1.5f * slows) continue;
- const float tilt = 0.05f + 0.65f * field(1);
+ const float tilt = 0.05f + 0.75f * field(1);
const float end = field(2) < 0.5f ? 0.0f : 3.14159265f;
const float azimuth = end + (field(3) - 0.5f) * 2.4f;
float da = std::sin(tilt) * std::cos(azimuth), dc = std::sin(tilt) * std::sin(azimuth);
const float dz = std::cos(tilt);
const float height = reach * (0.6f + 0.4f * field(4)), speed = height / slows;
const float travelled = height * (1 - std::exp(-age / slows)), now = speed * std::exp(-age / slows);
- // A long hull's outer jets lean less, so a whole jet, head and push, ends inside 12 cells
- // (0.78 of its height is as far as it gets before it stops).
+ // A long hull's or a tall jet's lean is cut, so a whole jet, head and push, ends inside 15
+ // cells (0.78 of its height is as far as it gets before it stops).
const float a0 = (field(5) - 0.5f) * L * 1.2f, c0 = (field(6) - 0.5f) * W * 0.6f;
const float lean = std::sqrt(da * da + dc * dc) * 0.78f * height;
if (lean > 1e-3f) {
- const float k = (std::min)(1.0f, (std::max)(0.0f, 12.0f - std::sqrt(a0 * a0 + c0 * c0)) / lean);
+ const float k = (std::min)(1.0f, (std::max)(0.0f, 15.0f - std::sqrt(a0 * a0 + c0 * c0)) / lean);
da *= k;
dc *= k;
}