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
feat(w3ddevice): glowing core and soft halo on weapon laser beams
Olcay Seygan1f0ec38eb290
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ec83710b4..2f31fb359 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -70,6 +70,7 @@ found and fixed — EA's own, not port damage.**- Flares cannot do everything the laser did. A Chinook sitting on the ground has no missile defence at all, an Aurora on its supersonic run is too fast to throw them, and no flare fools a SCUD or a Tomahawk, which the laser used to shoot down near these aircraft. Bought anyway, Countermeasures still gives the Air Force General's planes its armor.- 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 with a small burst. 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. 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 helicoptersdiff --git a/GeneralsMD/Code/Data/Scenarios/laserglow.txt b/GeneralsMD/Code/Data/Scenarios/laserglow.txtnew file mode 100644index 000000000..e04ed47a8--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/laserglow.txt@@ -0,0 +1,24 @@+# Laser beams in one view, for pictures of the beam glow: a Paladin under four Rocket Buggies, an+# Avenger under five Tank Hunters (both point defense lasers burst missiles), and a Laser General+# Crusader and Avenger firing their own beams at the buggies. Draws, so -win and not -headless:+#+# generals.exe -win -xres 1920 -yres 1080 -msaa 0 -quickstart -noshellmap -observer -multiInstance+# -noFPSLimit -turbo -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionGLA -seed 7 -maxframes 260 -camera 3330 3900+# -video 130 230 laserglow_d3d11 -scenario laserglow -logPrefix laserglow_d3d11_+#+# The same with -d3d9 and the names changed is the reference device. Positions are the Paladin and+# Avenger fights of missiledefence.txt pulled together.++30 spawn 0 AmericaTankPaladin 1 3260 3820+30 spawn 1 GLAVehicleRocketBuggy 4 3260 4100 30+60 attackmove 1 GLAVehicleRocketBuggy 3260 3820++30 spawn 0 AmericaTankAvenger 1 3400 3820+30 spawn 1 ChinaInfantryTankHunter 5 3400 4060 18+60 attack 1 ChinaInfantryTankHunter 0 AmericaTankAvenger++30 spawn 0 Lazr_AmericaTankCrusader 1 3300 3740+30 spawn 0 Lazr_AmericaTankAvenger 1 3360 3740+60 attack 0 Lazr_AmericaTankCrusader 1 GLAVehicleRocketBuggy+60 attack 0 Lazr_AmericaTankAvenger 1 ChinaInfantryTankHunterdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.hindex 82c79c0b9..07cbbeb06 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h@@ -97,6 +97,7 @@ public:protected:SegmentedLineClass **m_line3D; ///< line 3D for effect+ SegmentedLineClass **m_glow3D; ///< halo and hot core per segment, NULL for beams that do not glowTextureClass *m_texture;Real m_textureAspectRatio; ///< aspect ratio of textureBool m_selfDirty; // not saveddiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cppindex 9d9508306..8ded58844 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp@@ -60,6 +60,98 @@//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")#endif+// BEAM GLOW //////////////////////////////////////////////////////////////////////////////////////+// Weapon lasers get two more additive lines per segment over EA's beams: a wide halo in the beam's+// own hue and a narrow core run toward white. Both draw through one texture made here, a falloff+// across the width that reaches zero at the edge, so the halo has no visible border. The core+// stacks past white on top of EA's layers, which the Direct3D 11 bloom then picks up; under -d3d9+// the halo alone is the glow. Draw side only: nothing here is read by GameLogic or parsed from INI.+static const Real GLOW_HALO_WIDTH_SCALE = 1.6f; // halo width over the beam's widest layer+static const Real GLOW_HALO_MIN_WIDTH = 8.0f;+static const Real GLOW_HALO_INTENSITY = 0.45f;+static const Real GLOW_CORE_WIDTH_SCALE = 0.15f;+static const Real GLOW_CORE_MIN_WIDTH = 1.5f;+static const Real GLOW_CORE_WHITEN = 0.6f; // 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 TextureClass *s_glowTexture = NULL;++// ponytail: chosen by template name so no INI field and no checksum change; a "Glow" field in+// W3DLaserDraw is the upgrade if a mod ever wants it per beam. Every weapon laser in ZH ends in+// LaserBeam; the data streams, the waypoint line and the Particle Cannon's beams do not.+static Bool beamGlows( const Thing *thing )+{+ return thing && thing->getTemplate() && thing->getTemplate()->getName().endsWith( "LaserBeam" );+}++static TextureClass *acquireGlowTexture()+{+ if( !s_glowTexture )+ {+ s_glowTexture = MSGNEW("TextureClass") TextureClass( GLOW_TEXTURE_SIZE, 1, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1 );+ SurfaceClass *surf = s_glowTexture->Get_Surface_Level();+ if( surf )+ {+ Int pitch;+ UnsignedInt *pData = (UnsignedInt*)surf->Lock( &pitch );+ if( pData )+ {+ const Real edge = expf( -4.0f );+ for( Int x = 0; x < GLOW_TEXTURE_SIZE; x++ )+ {+ 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;+ }+ surf->Unlock();+ }+ REF_PTR_RELEASE( surf );+ }+ s_glowTexture->Get_Filter().Set_U_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );+ s_glowTexture->Get_Filter().Set_V_Addr_Mode( TextureFilterClass::TEXTURE_ADDRESS_CLAMP );+ }+ s_glowTexture->Add_Ref();+ return s_glowTexture;+}++static void releaseGlowTexture()+{+ if( !s_glowTexture )+ return;+ // the static pointer holds one reference of its own; the last beam takes it with it+ s_glowTexture->Release_Ref();+ if( s_glowTexture->Num_Refs() == 1 )+ REF_PTR_RELEASE( s_glowTexture );+}++// The beam's hue at full brightness: whichever of the two INI colours is more saturated, so a+// white-cored red laser glows red and a grey-edged orange one glows orange.+static Vector3 glowHue( Color inner, Color outer )+{+ Real c[ 2 ][ 4 ];+ GameGetColorComponentsReal( inner, &c[0][0], &c[0][1], &c[0][2], &c[0][3] );+ GameGetColorComponentsReal( outer, &c[1][0], &c[1][1], &c[1][2], &c[1][3] );+ Int best = 0;+ Real bestSat = -1.0f;+ for( Int i = 0; i < 2; i++ )+ {+ Real hi = MAX( c[i][0], MAX( c[i][1], c[i][2] ) );+ Real lo = MIN( c[i][0], MIN( c[i][1], c[i][2] ) );+ Real sat = ( hi > 0.0f ) ? ( hi - lo ) / hi : -1.0f;+ if( sat > bestSat )+ {+ bestSat = sat;+ best = i;+ }+ }+ Real hi = MAX( c[best][0], MAX( c[best][1], c[best][2] ) );+ if( hi <= 0.0f )+ return Vector3( 1.0f, 1.0f, 1.0f );+ return Vector3( c[best][0] / hi, c[best][1] / hi, c[best][2] / hi );+}+// PUBLIC FUNCTIONS /////////////////////////////////////////////////////////////////////////////////-------------------------------------------------------------------------------------------------@@ -118,6 +210,7 @@ void W3DLaserDrawModuleData::buildFieldParse(MultiIniFieldParse& p)W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :DrawModule( thing, moduleData ),m_line3D(NULL),+ m_glow3D(NULL),m_texture(NULL),m_textureAspectRatio(1.0f),m_selfDirty(TRUE)@@ -219,6 +312,29 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :} //end segment loop+ if( beamGlows( thing ) )+ {+ TextureClass *glowTexture = acquireGlowTexture();+ Vector3 hue = glowHue( data->m_innerColor, data->m_outerColor );+ Vector3 white( 1.0f, 1.0f, 1.0f );+ Vector3 colors[ GLOW_LAYERS ] = { hue * GLOW_HALO_INTENSITY, hue * ( 1.0f - GLOW_CORE_WHITEN ) + white * GLOW_CORE_WHITEN };++ const Int glowCount = (Int)data->m_segments * GLOW_LAYERS;+ m_glow3D = NEW SegmentedLineClass *[ glowCount ];+ for( Int g = 0; g < glowCount; g++ )+ {+ SegmentedLineClass *line = NEW SegmentedLineClass;+ m_glow3D[ g ] = line;+ line->Set_Texture( glowTexture );+ line->Set_Shader( ShaderClass::_PresetAdditiveShader );+ line->Set_Color( colors[ g % GLOW_LAYERS ] );+ line->Set_Texture_Mapping_Mode( SegLineRendererClass::UNIFORM_WIDTH_TEXTURE_MAP ); // u runs across the width+ W3DDisplay::m_3DScene->Add_Render_Object( line );+ line->Set_Visible( 0 );+ }+ // this beam's reference on glowTexture is given back by releaseGlowTexture in the destructor+ }+}//-------------------------------------------------------------------------------------------------@@ -239,6 +355,17 @@ W3DLaserDraw::~W3DLaserDraw( void )} // end for idelete [] m_line3D;++ if( m_glow3D )+ {+ for( Int g = 0; g < (Int)data->m_segments * GLOW_LAYERS; g++ )+ {+ W3DDisplay::m_3DScene->Remove_Render_Object( m_glow3D[ g ] );+ REF_PTR_RELEASE( m_glow3D[ g ] );+ }+ delete [] m_glow3D;+ releaseGlowTexture();+ }}//-------------------------------------------------------------------------------------------------@@ -425,6 +552,23 @@ void W3DLaserDraw::doDrawModule(const Matrix3D* transformMtx)m_line3D[ index ]->Set_Width( width );m_line3D[ index ]->Set_Points( 2, &laserPoints[0] );}++ if( m_glow3D )+ {+ Real widest = MAX( data->m_innerBeamWidth, data->m_outerBeamWidth );+ Real widthScale = update->getWidthScale();+ Real widths[ GLOW_LAYERS ] =+ {+ MAX( widest * GLOW_HALO_WIDTH_SCALE, GLOW_HALO_MIN_WIDTH ) * widthScale,+ MAX( widest * GLOW_CORE_WIDTH_SCALE, GLOW_CORE_MIN_WIDTH ) * widthScale+ };+ for( Int g = 0; g < GLOW_LAYERS; g++ )+ {+ SegmentedLineClass *line = m_glow3D[ segment * GLOW_LAYERS + g ];+ line->Set_Width( widths[ g ] );+ line->Set_Points( 2, &laserPoints[0] );+ }+ }}}