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): steady EA laser beams and soft ends on the glow halo

Olcay Seygan247de5484abc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29b2838a3..adcc57417 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -74,7 +74,7 @@ found and fixed — EA's own, not port damage.**
- A missile a point defense laser hits now goes up in a proper burst: a bright flash, sparks falling away and a short orange blast on top of EA's red flash and scrap of casing. It is gone in a second and leaves no smoke, so a run of intercepts does not stack a grey column over the tank. This goes for every point defense laser: the Paladin, the Avenger, the Air Force General's planes and Chinooks, and the Superweapon General's drone.
- The Paladin and the Avenger keep their point defense lasers, and you can see them again. In 2.4.0 they fired an invisible charge: a puff at the hull and a missile bursting in the air with nothing between them. The beam is back, drawn from the same spot on the tank EA drew it from, and a missile it touches still goes in one shot. What 2.4.0 changed stays. The lasers fire in short bursts: a Paladin gets two shots and four seconds to recharge, each of the Avenger's two lasers gets four and three seconds. Under five Tank Hunters an Avenger stops 8 missiles where EA's endless laser stopped 14 or 16, but it dies on the same frame, because fifteen hits kill it either way. A Paladin under four Rocket Buggies stops 4 rockets of 36, as it always did.
- The Paladin's laser also burns any soldier who comes within 65 of the tank, and a soldier it kills burns up again instead of being thrown by a blast. It has a second laser of its own for that, with its own two shots, so firing at a soldier never leaves the tank empty when a missile arrives.
-- Lasers glow now. The Paladin's and the Avenger's point defense, the Laser General's Crusader, Paladin, Avenger and turrets, and the point defense drone each draw a white-hot core down the middle of the beam and a soft halo in the beam's own colour along its whole length, so a pink Laser Avenger beam sits in a pink haze from the tank to its target. On the default renderer the core spills into the screen's bloom; on the Direct3D 9 one the halo carries the glow by itself. The Avenger's marking laser, the one that paints a target for the rest of your army, is not a weapon and keeps EA's thin blue line without a halo. The Glow setting decides how wide the halo burns, and Off gives you EA's plain beam back. Only the picture changed: damage, range and timing are what they were, and replays play back the same.
+- Lasers glow now. The Paladin's and the Avenger's point defense, the Laser General's Crusader, Paladin, Avenger and turrets, and the point defense drone each draw a white-hot core down the middle of the beam and a soft halo in the beam's own colour along its whole length, so a pink Laser Avenger beam sits in a pink haze from the tank to its target. On the default renderer the core spills into the screen's bloom; on the Direct3D 9 one the halo carries the glow by itself. The Avenger's marking laser, the one that paints a target for the rest of your army, is not a weapon and keeps EA's thin blue line without a halo. The Glow setting decides how wide the halo burns, and Off gives you EA's plain beam back. The halo now rounds off past both ends of the beam instead of stopping in a straight cut across it. EA's own beams, the marking laser included, stop blinking: their texture scrolled half its height every frame, so at a steady 30 frames a second they were drawn on one frame and dark the next, in the 2003 game too. Now they hold the lit middle of the texture and show on every frame. Only the picture changed: damage, range and timing are what they were, and replays play back the same.
- A replay recorded before this change plays back differently.
## Helicopters fly like helicopters
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
index 5886ddf84..d5abacc69 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp
@@ -77,6 +77,7 @@ static const Real GLOW_CORE_MIN_WIDTH = 3.0f;
static const Real GLOW_CORE_WHITEN = 0.7f; // how far the core's hue is run toward white
static const Int GLOW_LAYERS = 2; // [0] halo, [1] core
static const Int GLOW_TEXTURE_SIZE = 64;
+static const Int GLOW_LINE_POINTS = 4; // cap tip, start, end, cap tip
static TextureClass *s_glowTexture = NULL;
@@ -92,25 +93,42 @@ static Bool beamGlows( const Thing *thing )
return name.endsWith( "LaserBeam" ) && name != "AvengerTargetingLaserBeam";
}
+// The falloff from one at the middle (0) to zero at the edge (1), across the width and over a cap.
+static Real glowFalloff( Real distance )
+{
+ const Real edge = expf( -4.0f );
+ return MAX( ( expf( -4.0f * distance * distance ) - edge ) / ( 1.0f - edge ), 0.0f );
+}
+
+// u runs across the beam. v runs along a glow line of four points (glowLinePoints): the first third
+// is the cap behind the start, fading in, the middle third the beam at full, the last third the cap
+// past the end, fading out. A cap as long as half the width with the width's own falloff rounds the
+// end, where a line stopping at its last point left a straight cut through the halo.
static TextureClass *acquireGlowTexture()
{
if( !s_glowTexture )
{
- s_glowTexture = MSGNEW("TextureClass") TextureClass( GLOW_TEXTURE_SIZE, 1, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );
+ s_glowTexture = MSGNEW("TextureClass") TextureClass( GLOW_TEXTURE_SIZE, GLOW_TEXTURE_SIZE, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );
SurfaceClass *surf = s_glowTexture->Get_Surface_Level();
if( surf )
{
Int pitch;
- UnsignedInt *pData = (UnsignedInt*)surf->Lock( &pitch );
+ UnsignedByte *pData = (UnsignedByte*)surf->Lock( &pitch );
if( pData )
{
- const Real edge = expf( -4.0f );
- for( Int x = 0; x < GLOW_TEXTURE_SIZE; x++ )
+ const Real third = 1.0f / 3.0f;
+ for( Int y = 0; y < GLOW_TEXTURE_SIZE; y++ )
{
- Real d = ( x + 0.5f ) / GLOW_TEXTURE_SIZE * 2.0f - 1.0f; // -1..1 across the beam
- Real v = ( expf( -4.0f * d * d ) - edge ) / ( 1.0f - edge );
- UnsignedInt c = (UnsignedInt)( MAX( v, 0.0f ) * 255.0f + 0.5f );
- pData[ x ] = ( c << 24 ) | ( c << 16 ) | ( c << 8 ) | c;
+ Real along = ( y + 0.5f ) / GLOW_TEXTURE_SIZE;
+ Real cap = MAX( third - along, along - 2.0f * third ) * 3.0f; // 0 at a beam end, 1 at a cap's tip
+ Real lengthFalloff = glowFalloff( MAX( cap, 0.0f ) );
+ UnsignedInt *row = (UnsignedInt*)( pData + y * pitch );
+ for( Int x = 0; x < GLOW_TEXTURE_SIZE; x++ )
+ {
+ Real across = ( x + 0.5f ) / GLOW_TEXTURE_SIZE * 2.0f - 1.0f; // -1..1 across the beam
+ UnsignedInt c = (UnsignedInt)( glowFalloff( across ) * lengthFalloff * 255.0f + 0.5f );
+ row[ x ] = ( c << 24 ) | ( c << 16 ) | ( c << 8 ) | c;
+ }
}
surf->Unlock();
}
@@ -177,6 +195,19 @@ static ShaderClass glowingAdditiveShader()
return shader;
}
+// A Tile = Yes beam with a TilingScalar of zero or less (every EA laser: -3) asks for a negative tile
+// factor, which the line clamps to zero, so the whole beam samples one row of its texture and the
+// ScrollRate only picks which row. At -2500 a 33 ms frame moves it 82.5 rows' worth, half a texture,
+// and EXLaser4's rows alternate between the lit band and the dark border: at a steady 30 pictures a
+// second, retail's clock included, the beam was there on every other frame. Such a beam holds the
+// texture's middle row instead; a beam that does tile still scrolls.
+static const Real BEAM_TEXTURE_ROW = 0.5f;
+
+static Bool holdsOneTextureRow( const W3DLaserDrawModuleData *data )
+{
+ return data->m_tile && data->m_tilingScalar <= 0.0f && !data->m_textureName.isEmpty();
+}
+
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
@@ -323,6 +354,11 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :
{
line->Set_Texture_Mapping_Mode(SegLineRendererClass::TILED_TEXTURE_MAP); //this tiles the texture across the line
}
+ if( holdsOneTextureRow( data ) )
+ {
+ line->Set_UV_Offset_Rate( Vector2( 0.0f, 0.0f ) );
+ line->Set_Current_UV_Offset( Vector2( 0.0f, BEAM_TEXTURE_ROW ) );
+ }
// add to scene
W3DDisplay::m_3DScene->Add_Render_Object( line ); //add it to our scene so it gets rendered with other objects.
@@ -349,7 +385,9 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :
m_glow3D[ g ] = line;
line->Set_Texture( glowTexture );
line->Set_Shader( glowingAdditiveShader() );
- line->Set_Texture_Mapping_Mode( SegLineRendererClass::UNIFORM_WIDTH_TEXTURE_MAP ); // u runs across the width
+ // u across the width, v a third further at each of the four points (acquireGlowTexture)
+ line->Set_Texture_Mapping_Mode( SegLineRendererClass::TILED_TEXTURE_MAP );
+ line->Set_Texture_Tile_Factor( 1.0f / ( GLOW_LINE_POINTS - 1 ) );
W3DDisplay::m_3DScene->Add_Render_Object( line );
line->Set_Visible( 0 );
}
@@ -596,12 +634,28 @@ void W3DLaserDraw::doDrawModule(const Matrix3D* transformMtx)
hue * ( GLOW_HALO_INTENSITY * brightness ),
( hue * ( 1.0f - GLOW_CORE_WHITEN ) + white * GLOW_CORE_WHITEN ) * brightness
};
+ // ponytail: every segment gets its own caps, so an arc of several segments would double
+ // up at its joints; no glowing laser in the data has more than one
+ Vector3 direction = laserPoints[ 1 ] - laserPoints[ 0 ];
+ const Real length = direction.Length();
for( Int g = 0; g < GLOW_LAYERS; g++ )
{
SegmentedLineClass *line = m_glow3D[ segment * GLOW_LAYERS + g ];
line->Set_Color( colors[ g ] );
line->Set_Width( widths[ g ] );
- line->Set_Points( 2, &laserPoints[0] );
+ if( length > 0.0f )
+ {
+ Vector3 cap = direction * ( widths[ g ] * 0.5f / length );
+ Vector3 glowPoints[ GLOW_LINE_POINTS ] =
+ {
+ laserPoints[ 0 ] - cap, laserPoints[ 0 ], laserPoints[ 1 ], laserPoints[ 1 ] + cap
+ };
+ line->Set_Points( GLOW_LINE_POINTS, glowPoints );
+ }
+ else
+ {
+ line->Set_Points( 2, &laserPoints[0] );
+ }
}
}
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/segline.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/segline.h
index 219bcafe0..77b42f792 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/segline.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/segline.h
@@ -115,6 +115,7 @@ class SegmentedLineClass : public RenderObjClass
//performance impact will result!
void Set_Texture_Tile_Factor(float factor);
void Set_UV_Offset_Rate(const Vector2 &rate);
+ void Set_Current_UV_Offset(const Vector2 &offset) { LineRenderer.Set_Current_UV_Offset(offset); }
void Set_Merge_Intersections(int onoff);
void Set_Freeze_Random(int onoff);
void Set_Disable_Sorting(int onoff);