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.

feat(w3ddevice): shockwave warp rises as a dome

Olcay Seygan9bb4fa6a2534
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a2746f9b..e0b06173e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1336,7 +1336,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Explosions open on a white-hot flash. A tank shell, a rocket, a bomb truck or a dying tank now starts with a white core that cools through yellow and orange in a third of a second before EA's fireball takes over, and the core is as big as the blast: about a tank's width for a shell, much wider for a Scud Storm missile, a MOAB or a Daisy Cutter. On the default renderer the core spills into the screen's glow.
- Big blasts light the ground further and for longer. Every explosion's light is warmer and holds a little longer, and a bomb truck, a Scud, a bunker buster, a carpet bomb or a nuke throws a wide orange glow that fades over one to two seconds. Falling buildings, the Daisy Cutter, the MOAB, nukes, exploding cars and suicide bombers used to light nothing at all.
- The heaviest blasts leave bigger craters and send a ring of heat haze out across the ground for a second and a half to two seconds, if Heat Effects is on. Heat haze bends what is behind it by a few pixels now. On a blast that size it used to lay a second copy of the ground over the first, shifted by as much as twenty pixels, so the trees and ridges inside a nuke's ring came out doubled.
-- A nuke pulls the picture into itself. For a quarter of a second the ground around the blast bends inward toward it, then a ring rolls out well past the fireball and shoves the battlefield aside as it passes, weaker the further it gets. Each Scud Storm missile does a smaller version of the same, and Nuke Cannon shells, Scud Launcher missiles, Tomahawks and bomb trucks give a short kick that is gone in half a second, so a battery firing all match never turns the screen to jelly. This is the default renderer; Classic and the old renderer keep only the heat ring.
+- A nuke pulls the picture into itself. For a quarter of a second the ground around the blast bends inward toward it, then a dome of shock rises out of it, running flat across the ground in front and standing up behind, rolling well past the fireball and shoving the battlefield aside as it passes, weaker the further it gets. Each Scud Storm missile does a smaller version of the same, and Nuke Cannon shells, Scud Launcher missiles, Tomahawks and bomb trucks give a short kick that is gone in half a second, so a battery firing all match never turns the screen to jelly. This is the default renderer; Classic and the old renderer keep only the heat ring.
- Up to a thousand craters stay on the ground in a long match, where the game kept five hundred and quietly dropped the oldest.
- 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.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 8c3f716cb..71ce95dca 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -4350,6 +4350,28 @@ void W3DView::updateScreenDistortions( void )
if (screenRadius < 1.0f)
continue;
+ // The dome's footprint on the ground toward the camera: a radius along the camera's
+ // backward direction laid flat, which the pitch shortens on screen. Looking straight down
+ // there is no such direction and the footprint is as deep as it is wide.
+ Real squash = 1.0f;
+ const Vector3 back = m_3DCamera->Get_Transform().Get_Z_Vector();
+ const Real flatLength = sqrtf(back.X * back.X + back.Y * back.Y);
+ if (flatLength > 0.01f)
+ {
+ Coord3D front = blast.m_epicenter;
+ front.x += back.X / flatLength * info.m_radius;
+ front.y += back.Y / flatLength * info.m_radius;
+ ICoord2D frontScreen;
+ if (worldToScreenTriReturn(&front, &frontScreen) != WTS_INVALID)
+ {
+ const Real fx = (Real)(frontScreen.x - centre.x);
+ const Real fy = (Real)(frontScreen.y - centre.y);
+ squash = sqrtf(fx * fx + fy * fy) / screenRadius;
+ if (squash > 1.0f)
+ squash = 1.0f;
+ }
+ }
+
DX11PostWarp &warp = warps[warpCount++];
warp.CentreX = (Real)centre.x / displayWidth;
warp.CentreY = (Real)centre.y / displayHeight;
@@ -4362,6 +4384,7 @@ void W3DView::updateScreenDistortions( void )
warp.RingRadius = warp.Radius * ringReach;
warp.RingWidth = warp.Radius * ringWidth;
warp.RingStrength = ringStrength;
+ warp.RingSquash = squash;
}
m_distortionCount = kept;
DX11Post_Set_Warps(warps, (unsigned)warpCount);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index aed91aec6..2549bca2a 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -383,6 +383,13 @@ static const char * const BLOOM_COMPOSITE_SHADER_BODY =
// reads from nearer the centre, so what was inside it is carried outward on its crest, and across
// its width it falls off as a gaussian, which keeps the band soft rather than a cut line.
//
+// The ring is a dome's outline rather than a circle. Above the centre a hemisphere seen from a
+// raised camera shows its round top, as tall as it is wide; below the centre what shows is its
+// footprint on the ground nearest the camera, flattened by the pitch. So the lower half of the
+// ring is measured with the vertical squeezed by RingSquash, and it pushes along that ellipse's
+// normal, which is what makes the wave run flat across the ground in front of the blast and stand
+// up behind it.
+//
// The whole shift dies away over the last 8% of the frame toward every edge. A read past the edge
// comes back as the edge's own texel, and on film that drew the border out into streaks thirty to
// forty pixels long; held to zero at the edge, a pixel near it never reads further out than it is
@@ -402,9 +409,14 @@ static const char * const WARP_SHADER_BODY =
" float2 outward = away / max(span, 0.0001);\n"
" float reach = saturate(span / max(centre.z, 0.0001));\n"
" float inward = centre.w * centre.z * 6.75 * reach * (1.0 - reach) * (1.0 - reach);\n"
- " float across = (span - ring.x) / max(ring.y, 0.0001);\n"
+ " float squash = (away.y > 0.0) ? max(ring.w, 0.05) : 1.0;\n"
+ " float2 domed = float2(away.x, away.y / squash);\n"
+ " float domeSpan = length(domed);\n"
+ " float2 domeNormal = float2(domed.x, domed.y / squash);\n"
+ " domeNormal /= max(length(domeNormal), 0.0001);\n"
+ " float across = (domeSpan - ring.x) / max(ring.y, 0.0001);\n"
" float push = ring.z * centre.z * exp(-across * across);\n"
- " shift += outward * (inward - push);\n"
+ " shift += outward * inward - domeNormal * push;\n"
" }\n"
" shift.x /= aspect;\n"
" float2 border = min(input.Texture, 1.0 - input.Texture);\n"
@@ -890,7 +902,7 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
block.WarpRing[index][0] = warp.RingRadius;
block.WarpRing[index][1] = warp.RingWidth;
block.WarpRing[index][2] = warp.RingStrength;
- block.WarpRing[index][3] = 0.0f;
+ block.WarpRing[index][3] = warp.RingSquash;
}
memcpy(mapped.pData, &block, sizeof(block));
context->Unmap(ConstantBuffer, 0);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 1babf6899..928d6e2ad 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -127,6 +127,11 @@ struct DX11PostWarp
float RingRadius;
float RingWidth;
float RingStrength;
+ // The ring is the outline of a dome standing on the ground, not a circle on the glass. Above
+ // the centre it is the dome's own round silhouette, rising as high as it is wide; below it, it
+ // is the dome's footprint on the ground, which the camera's pitch flattens. This is how far it
+ // is flattened there: the footprint's depth on screen over its width, one looking straight down.
+ float RingSquash;
};
// Four blasts on one screen at once is already more than anyone can read.
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index 2c9189982..4561109a7 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -346,6 +346,7 @@ TEST(dx11post_a_warp_bends_the_edge_its_ring_crosses_and_clearing_it_gives_the_f
warp.RingRadius = 0.28f;
warp.RingWidth = 0.05f;
warp.RingStrength = 0.1f;
+ warp.RingSquash = 1.0f;
DX11Post_Set_Warps(&warp, 1);
const DX11PostEffect chain[] = { DX11_POST_COPY };