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(gameengine): fade particles out over their last frames

Olcay Seyganfdea15b69d64
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c36310ca0..ed45b000f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1340,6 +1340,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean 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.
+- 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 steady 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. 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.
- 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.
- The shake knows how close you are. A shell landing in the middle of the screen kicks the camera half as hard again as it used to, one at the edge of the range barely moves it, and a heavy hit settles over about a second instead of stopping dead after half of one. The cut that put a pile of shakes back to a mild one is gone too: past the limit the camera holds at full shake.
diff --git a/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini b/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
index fdb220b0d..4502449f9 100644
--- a/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
+++ b/GeneralsMD/Code/Data/INI/ParticleSystemReforged.ini
@@ -263,7 +263,7 @@ ParticleSystem APSBlastFragments
Alpha8 = 0.00 0.00 0
Color1 = R:255 G:255 B:220 0
Color2 = R:255 G:160 B:60 5
- Color3 = R:0 G:0 B:0 16
+ Color3 = R:0 G:0 B:0 10
Color4 = R:0 G:0 B:0 0
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
@@ -1377,7 +1377,7 @@ ParticleSystem ReforgedHotCore
Color1 = R:255 G:255 B:255 0
Color2 = R:255 G:228 B:175 3
Color3 = R:215 G:105 B:30 8
- Color4 = R:0 G:0 B:0 14
+ Color4 = R:0 G:0 B:0 11
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
Color7 = R:0 G:0 B:0 0
@@ -1426,7 +1426,7 @@ ParticleSystem ReforgedHotCoreFireball
Color1 = R:255 G:255 B:255 0
Color2 = R:255 G:222 B:160 3
Color3 = R:190 G:85 B:20 7
- Color4 = R:0 G:0 B:0 11
+ Color4 = R:0 G:0 B:0 9
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
Color7 = R:0 G:0 B:0 0
@@ -1478,7 +1478,7 @@ ParticleSystem ReforgedHotCoreStructure
Color1 = R:255 G:255 B:255 0
Color2 = R:255 G:225 B:170 3
Color3 = R:200 G:95 B:25 7
- Color4 = R:0 G:0 B:0 11
+ Color4 = R:0 G:0 B:0 9
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
Color7 = R:0 G:0 B:0 0
@@ -1534,7 +1534,7 @@ ParticleSystem ReforgedHotCoreLarge
Color1 = R:255 G:255 B:255 0
Color2 = R:255 G:228 B:175 3
Color3 = R:215 G:105 B:30 8
- Color4 = R:0 G:0 B:0 14
+ Color4 = R:0 G:0 B:0 12
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
Color7 = R:0 G:0 B:0 0
@@ -1584,7 +1584,7 @@ ParticleSystem ReforgedHotCoreHuge
Color1 = R:150 G:135 B:110 0
Color2 = R:235 G:215 B:170 4
Color3 = R:200 G:100 B:32 10
- Color4 = R:0 G:0 B:0 18
+ Color4 = R:0 G:0 B:0 16
Color5 = R:0 G:0 B:0 0
Color6 = R:0 G:0 B:0 0
Color7 = R:0 G:0 B:0 0
@@ -1637,7 +1637,7 @@ ParticleSystem ReforgedHeatRingLarge
Alpha1 = 0.00 0.00 0
Alpha2 = 1.00 1.00 3
Alpha3 = 0.75 0.75 26
- Alpha4 = 0.00 0.00 46
+ Alpha4 = 0.00 0.00 42
Alpha5 = 0.00 0.00 0
Alpha6 = 0.00 0.00 0
Alpha7 = 0.00 0.00 0
@@ -1687,7 +1687,7 @@ ParticleSystem ReforgedHeatRingHuge
Alpha1 = 0.00 0.00 0
Alpha2 = 1.00 1.00 3
Alpha3 = 0.75 0.75 36
- Alpha4 = 0.00 0.00 62
+ Alpha4 = 0.00 0.00 58
Alpha5 = 0.00 0.00 0
Alpha6 = 0.00 0.00 0
Alpha7 = 0.00 0.00 0
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
index 35d47f882..4eebedcc0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp
@@ -78,6 +78,15 @@ static UnsignedInt particleTimerFrames( Real value )
return (UnsignedInt)value;
}
+//-------------------------------------------------------------------------------------------------
+/* A particle whose keys never reach zero alpha (or black, or white for MULTIPLY) would vanish with
+ whatever it showed on its last frame. Over the last frames of its life its strength is capped by
+ an envelope falling linearly to zero, so it fades instead. The window is a quarter of the
+ lifetime, at most eight frames. A cap rather than a multiplier: a particle already fading below
+ the envelope is left exactly as authored. */
+static const UnsignedInt PARTICLE_FADE_MAX_FRAMES = 8;
+static const UnsignedInt PARTICLE_FADE_LIFETIME_DIVISOR = 4;
+
//-------------------------------------------------------------------------------------------------
// the singleton
@@ -705,9 +714,60 @@ Bool Particle::update( const ParticleUpdateContext &context )
// reset the acceleration for accumulation next frame
m_accel.z=m_accel.y=m_accel.x= 0.0f;
- // monitor lifetime
- if (m_lifetimeLeft && --m_lifetimeLeft == 0)
- return false;
+ // monitor lifetime, and fade out over the last frames of it
+ if (m_lifetimeLeft)
+ {
+ if (--m_lifetimeLeft == 0)
+ return false;
+
+ UnsignedInt fadeFrames = m_lifetime / PARTICLE_FADE_LIFETIME_DIVISOR;
+ if (fadeFrames > PARTICLE_FADE_MAX_FRAMES)
+ fadeFrames = PARTICLE_FADE_MAX_FRAMES;
+ else if (fadeFrames == 0)
+ fadeFrames = 1;
+
+ if (m_lifetimeLeft <= fadeFrames)
+ {
+ // zero on the last frame, so isInvisible below retires it on the frame it would die anyway
+ const Real envelope = (Real)(m_lifetimeLeft - 1) / (Real)fadeFrames;
+ switch (context.shaderType)
+ {
+ case ParticleSystemInfo::ALPHA:
+ case ParticleSystemInfo::ALPHA_TEST:
+ if (m_alpha > envelope)
+ m_alpha = envelope;
+ break;
+
+ case ParticleSystemInfo::ADDITIVE:
+ {
+ // scale the brightest channel down to the envelope, keeping the hue
+ const Real brightest = max( m_color.red, max( m_color.green, m_color.blue ) );
+ if (brightest > envelope)
+ {
+ const Real k = envelope / brightest;
+ m_color.red *= k;
+ m_color.green *= k;
+ m_color.blue *= k;
+ }
+ break;
+ }
+
+ case ParticleSystemInfo::MULTIPLY:
+ {
+ // the same toward white, which multiplies to nothing
+ const Real darkest = 1.0f - min( m_color.red, min( m_color.green, m_color.blue ) );
+ if (darkest > envelope)
+ {
+ const Real k = envelope / darkest;
+ m_color.red = 1.0f - (1.0f - m_color.red) * k;
+ m_color.green = 1.0f - (1.0f - m_color.green) * k;
+ m_color.blue = 1.0f - (1.0f - m_color.blue) * k;
+ }
+ break;
+ }
+ }
+ }
+ }
DEBUG_ASSERTCRASH( m_lifetimeLeft, ( "A particle has an infinite lifetime..." ));