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(ww3d2): heat haze along laser beams and behind missile exhaust
Olcay Seygan22a606196483
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.hindex 565144405..bcb31bbc3 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ParticleSys.h@@ -731,7 +731,11 @@ public:void attachToDrawable( const Drawable *draw ); ///< attach this particle system to a Drawablevoid attachToObject( const Object *obj ); ///< attach this particle system to an Object- void attachToObjectID( ObjectID id ) { m_attachedToObjectID = id; } ///< the same, for an object that may be gone already+ void attachToObjectID( ObjectID id ) { m_attachedToObjectID = id; if (id != INVALID_ID) m_rodeObject = TRUE; } ///< the same, for an object that may be gone already+ /// attached to an Object at some point, still true once the object has died (-heathaze's missile+ /// exhausts keep their haze while the trail fades). Not saved; a load sets it again for a system+ /// still attached to its object.+ Bool hasRiddenObject( void ) const { return m_rodeObject; }/** LOGIC-THREAD.md phase 2, M5. A system made inside a tick is a shell until the end of the tick:* its ID and everything copied from the template, so logic can place it, attach it, stop it and@@ -933,6 +937,7 @@ protected:DrawableID m_attachedToDrawableID; ///< if non-zero, system is parented to this DrawableObjectID m_attachedToObjectID; ///< if non-zero, system is parented to this Object+ Bool m_rodeObject; ///< hasRiddenObjectDrawableID m_attachedObjectDrawableForDraw; ///< that Object's drawable at the last update, for getStealthFade inside the overlap windowMatrix3D m_localTransform; ///< local orientation & position of systemdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cppindex 5ddf225b7..b735ee45a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp@@ -1466,6 +1466,7 @@ ParticleSystem::ParticleSystem( const ParticleSystemTemplate *sysTemplate,m_attachedToDrawableID = INVALID_DRAWABLE_ID;m_attachedToObjectID = INVALID_ID;+ m_rodeObject = FALSE;m_attachedObjectDrawableForDraw = INVALID_DRAWABLE_ID;m_isLocalIdentity = true;@@ -1850,7 +1851,10 @@ void ParticleSystem::attachToDrawable( const Drawable *draw )void ParticleSystem::attachToObject( const Object *obj ){if (obj)+ {m_attachedToObjectID = obj->getID();+ m_rodeObject = TRUE;+ }elsem_attachedToObjectID = INVALID_ID;}@@ -3349,6 +3353,8 @@ void ParticleSystem::xfer( Xfer *xfer )// attached to object idxfer->xferObjectID( &m_attachedToObjectID );+ if( xfer->getXferMode() == XFER_LOAD && m_attachedToObjectID != INVALID_ID )+ m_rodeObject = TRUE; // not saved; a trail still riding its missile is one that rode it// is local identityxfer->xferBool( &m_isLocalIdentity );diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.hindex c087ffed7..6b29c63ec 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h@@ -39,9 +39,21 @@#include "GameClient/Color.h"#include "WWMath/vector3.h"+#include <vector>+class SegmentedLineClass;class TextureClass;+/// -heathaze: a glowing beam on show, for the air round it to bend (gatherHeatHaze)+struct LaserHeat+{+ Vector3 start;+ Vector3 end;+ Real glowWidth; ///< the halo's whole width, world units+ Real coreRadius; ///< half the body's width: the beam a viewer sees, which must not move+ Real light; ///< the glow's brightness with the fade, 0 to 1+};+class W3DLaserDrawModuleData : public ModuleData{public:@@ -97,6 +109,8 @@ public:virtual LaserDrawInterface* getLaserDrawInterface() { return this; }virtual const LaserDrawInterface* getLaserDrawInterface() const { return this; }+ static void gatherHeat( std::vector<LaserHeat> &beams ); ///< every glowing beam on show, appended+protected:void drawGlow( Real widthScale, Real sinceArrivalMs );@@ -106,6 +120,9 @@ protected:SegmentedLineClass *m_flare3D[ 4 ]; ///< muzzle glow and core, impact glow and core; made beside m_glow3DVector3 m_beamStart; ///< the first segment's start and the last one's end, for the flaresVector3 m_beamEnd;+ Real m_glowWidth; ///< the halo's and the body's widths as last placed, for gatherHeat+ Real m_bodyWidth;+ Real m_light; ///< the glow's brightness on the last draw, for gatherHeatUnsignedInt m_birthFrame; ///< logic frame the lines were built on, for the fade in and outUnsignedInt m_lifetimeFrames; ///< the template's LifetimeUpdate, 0 when it has none (no fade out)UnsignedInt m_birthMs; ///< picture clock of the first draw, for the traveldiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.hindex aa6038a83..75d18bba1 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h@@ -155,6 +155,8 @@ private:std::vector<SystemView> m_frameView;std::vector<ParticleSystem *> m_frameFires; ///< the additive and Emissive FireLook systems among them, for the Firelight optionstd::vector<Real> m_frameFireFades; ///< and their fades+ std::vector<ParticleSystem *> m_frameExhausts; ///< -heathaze: the additive weapon trails riding a projectile, a missile's flame+ std::vector<Real> m_frameExhaustFades;std::vector<ParticleSystem *> m_fieldSystems; ///< the contamination fields' systems, empty ones toostd::vector<SunMapCaster> m_sunMapCasters;Bool m_frameViewValid;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cppindex 3173c3e67..ff5e317bb 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp@@ -239,6 +239,10 @@ static void releaseGlowTexture()REF_PTR_RELEASE( s_glowTexture );}+// -heathaze: the beams gatherHeat reports, added when their glow is built and taken out with it+// ponytail: a linear erase per beam destroyed; fine for the tens of beams a fight holds+static std::vector<W3DLaserDraw *> s_glowingBeams;+// A flicker of one on average, varying by up to depth: a value per FLICKER_STEP_MS for each seed,// blended into the next, so it shimmers rather than strobes. On the picture's clock, so a -video// recording gets the same flicker every run.@@ -408,6 +412,9 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :m_glow3D(NULL),m_beamStart(0.0f, 0.0f, 0.0f),m_beamEnd(0.0f, 0.0f, 0.0f),+ m_glowWidth(0.0f),+ m_bodyWidth(0.0f),+ m_light(0.0f),m_birthFrame(0),m_lifetimeFrames(0),m_birthMs(0),@@ -522,6 +529,7 @@ void W3DLaserDraw::buildRenderObjects( Bool madeInTick )W3DDisplay::m_3DScene->Add_Render_Object( line );line->Set_Visible( 0 );}+ s_glowingBeams.push_back( this );m_lifetimeFrames = beamLifetimeFrames( getDrawable() );// the beam's birth, so one the camera only reaches mid-life still fades out on timem_birthFrame = TheGameLogic->getFrame();@@ -562,6 +570,15 @@ W3DLaserDraw::~W3DLaserDraw( void )W3DDisplay::m_3DScene->Remove_Render_Object( m_flare3D[ f ] );REF_PTR_RELEASE( m_flare3D[ f ] );}+ for( size_t b = 0; b < s_glowingBeams.size(); b++ )+ {+ if( s_glowingBeams[ b ] == this )+ {+ s_glowingBeams[ b ] = s_glowingBeams.back();+ s_glowingBeams.pop_back();+ break;+ }+ }releaseGlowTexture();}}@@ -819,6 +836,8 @@ void W3DLaserDraw::doDrawModule(const Matrix3D* transformMtx)line->Set_Points( 2, &laserPoints[0] );}}+ m_glowWidth = widths[ 0 ];+ m_bodyWidth = widths[ 1 ];if( segment == 0 )m_beamStart = laserPoints[ 0 ];m_beamEnd = laserPoints[ 1 ];@@ -870,6 +889,7 @@ void W3DLaserDraw::drawGlow( Real widthScale, Real sinceArrivalMs )m_glow3D[ g ]->Set_Color( Vector3( 0.0f, 0.0f, 0.0f ) );for( Int f = 0; f < FLARE_COUNT; f++ )m_flare3D[ f ]->Set_Color( Vector3( 0.0f, 0.0f, 0.0f ) );+ m_light = 0.0f;return;}@@ -888,6 +908,7 @@ void W3DLaserDraw::drawGlow( Real widthScale, Real sinceArrivalMs )const Vector3 hue = glowHue( data->m_innerColor, data->m_outerColor );const Vector3 white( 1.0f, 1.0f, 1.0f );const Real light = brightness * fade;+ m_light = light;// glowHue's brightest channel is one, so no colour passes one before the flickerconst Vector3 colors[ GLOW_LAYERS ] =@@ -944,6 +965,30 @@ void W3DLaserDraw::drawGlow( Real widthScale, Real sinceArrivalMs )}}+//-------------------------------------------------------------------------------------------------+/** -heathaze: every glowing beam the viewer can see, as last placed. Read from the beams themselves+ * rather than a list filled while drawing, because a render pass draws the drawables only when the+ * logic clock moved and the haze is gathered on every one. The test is smoothMotionApply's. */+//-------------------------------------------------------------------------------------------------+void W3DLaserDraw::gatherHeat( std::vector<LaserHeat> &beams )+{+ for( size_t b = 0; b < s_glowingBeams.size(); b++ )+ {+ W3DLaserDraw *laser = s_glowingBeams[ b ];+ Drawable *draw = laser->getDrawable();+ if( laser->m_light <= 0.0f || ( laser->m_beamEnd - laser->m_beamStart ).Length2() <= 0.0f+ || draw->isDrawableEffectivelyHidden() || draw->getFullyObscuredByShroud() )+ continue;+ LaserHeat heat;+ heat.start = laser->m_beamStart;+ heat.end = laser->m_beamEnd;+ heat.glowWidth = laser->m_glowWidth;+ heat.coreRadius = laser->m_bodyWidth * 0.5f;+ heat.light = laser->m_light;+ beams.push_back( heat );+ }+}+// ------------------------------------------------------------------------------------------------/** CRC */// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex 2a6c95a77..908280d7c 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -41,6 +41,7 @@#include "W3DDevice/GameClient/W3DScene.h"#include "W3DDevice/GameClient/W3DDynamicLight.h"#include "W3DDevice/GameClient/W3DWater.h"+#include "W3DDevice/GameClient/Module/W3DLaserDraw.h"#include "WW3D2/camera.h"#include "WW3D2/ww3d.h"#include "W3DDevice/GameClient/W3DSmoothMotion.h"@@ -363,9 +364,44 @@ static const Real HEAT_HAZE_FULL = 40.0f; ///< summed brightness times size astatic const Real HEAT_HAZE_CLEARANCE = 12.0f; ///< world units behind the flames before a surface bends at allstatic const Real HEAT_HAZE_SOFTNESS = 20.0f; ///< and the further distance over which it comes up to full+// A missile's exhaust (m_frameExhausts) the same way, smaller: a round splat over the trail it has+// left behind it, not lifted, since a moving flame leaves its heat where it was. A trail's centre+// starts at the launcher, so the haze comes up only as the trail grows (HEAT_EXHAUST_GROWN), and a+// surface must lie further behind it than behind a fire before it bends: a launcher seen past the+// trail kept its outline neither way alone.+static const Real HEAT_EXHAUST_MIN_RADIUS = 3.0f;+static const Real HEAT_EXHAUST_MAX_RADIUS = 7.0f;+static const Real HEAT_EXHAUST_AMPLITUDE = 0.24f;+static const Real HEAT_EXHAUST_MAX_SHIFT = 0.005f;+static const Real HEAT_EXHAUST_FULL = 6.0f; ///< an exhaust's particles are small and few+static const Real HEAT_EXHAUST_GROWN = 20.0f; ///< world units of the trail's spread at which it shimmers fully+static const Real HEAT_EXHAUST_CLEARANCE = 25.0f;++struct HeatLook+{+ Real minRadius, maxRadius, lift, stretch, amplitude, maxShift, full, grown, clearance;+};+static const HeatLook HEAT_LOOKS[ 2 ] =+{+ { HEAT_HAZE_MIN_RADIUS, HEAT_HAZE_MAX_RADIUS, HEAT_HAZE_LIFT, HEAT_HAZE_STRETCH, HEAT_HAZE_AMPLITUDE, HEAT_HAZE_MAX_SHIFT, HEAT_HAZE_FULL, 0.0f, HEAT_HAZE_CLEARANCE },+ { HEAT_EXHAUST_MIN_RADIUS, HEAT_EXHAUST_MAX_RADIUS, 0.0f, 1.0f, HEAT_EXHAUST_AMPLITUDE, HEAT_EXHAUST_MAX_SHIFT, HEAT_EXHAUST_FULL, HEAT_EXHAUST_GROWN, HEAT_EXHAUST_CLEARANCE }+};++// A glowing laser's air (W3DLaserDraw::gatherHeat). No depth to hide behind, so the beam is kept+// still by a band along it instead; HEAT_HAZE_CLEARANCE still keeps the unit it hits.+static const Real HEAT_BEAM_RADIUS_SCALE = 0.5f; ///< a splat's radius over the halo's whole width: 5 to 11 for EA's lasers+static const Real HEAT_BEAM_MIN_RADIUS = 5.0f; ///< world units+static const Int HEAT_BEAM_MAX_SPLATS = 96; ///< a beam longer than that many radii spaces them wider+static const Real HEAT_BEAM_AMPLITUDE = 0.25f; ///< as HEAT_HAZE_AMPLITUDE, larger because the sleeve is a third as wide+static const Real HEAT_BEAM_MAX_SHIFT = 0.003f;+static const Real HEAT_BEAM_STILL_SCALE = 1.0f; ///< the still band's half width over the body's half width+static const Real HEAT_BEAM_STILL_FADE = 0.75f; ///< and the distance beyond it over which the bending comes up+static std::vector<float> s_heatSplats; ///< kept so the gather does not allocate+static std::vector<LaserHeat> s_heatBeams;-static void gatherHeatHaze( CameraClass &camera, const std::vector<ParticleSystem *> &systems, const std::vector<Real> &fades )+static void gatherHeatHaze( CameraClass &camera, const std::vector<ParticleSystem *> &fires, const std::vector<Real> &fireFades,+ const std::vector<ParticleSystem *> &exhausts, const std::vector<Real> &exhaustFades ){s_heatSplats.clear();Matrix4x4 projection;@@ -380,24 +416,29 @@ static void gatherHeatHaze( CameraClass &camera, const std::vector<ParticleSysteconst Real viewHeight = viewport.Max.Y - viewport.Min.Y;const float seconds = (float)( WW3D::Get_Sync_Time() % 3600000u ) * 0.001f;Int count = 0;- for (size_t i = 0; i < systems.size() && count < (Int)DIRECT3D11_HEAT_SPLAT_LIMIT; ++i)+ // the fires first, then the exhausts+ for (Int kind = 0; kind < 2; ++kind)+ for (size_t i = 0; i < ( kind ? exhausts : fires ).size() && count < (Int)DIRECT3D11_HEAT_SPLAT_LIMIT; ++i){+ const HeatLook &look = HEAT_LOOKS[ kind ];FireLights::Flames flames;- sumFlames( systems[ i ], flames );+ sumFlames( ( kind ? exhausts : fires )[ i ], flames );if (flames.w <= 0.0f)continue;- Real strength = flames.w * fades[ i ] / HEAT_HAZE_FULL;+ Real strength = flames.w * ( kind ? exhaustFades : fireFades )[ i ] / look.full;if (strength > 1.0f)strength = 1.0f;const Vector3 centre( flames.x / flames.w, flames.y / flames.w, flames.z / flames.w );const Real spread = flames.sq / flames.w - centre.Length2();Real radius = spread > 0.0f ? WWMath::Sqrt( spread ) : 0.0f;- radius = radius < HEAT_HAZE_MIN_RADIUS ? HEAT_HAZE_MIN_RADIUS : radius > HEAT_HAZE_MAX_RADIUS ? HEAT_HAZE_MAX_RADIUS : radius;+ if (look.grown > 0.0f && radius < look.grown)+ strength *= radius / look.grown;+ radius = radius < look.minRadius ? look.minRadius : radius > look.maxRadius ? look.maxRadius : radius;// the flames' own depth decides what stands in front; the column is drawn above themVector3 eye, columnEye;Matrix3D::Transform_Vector( view, centre, &eye );- Matrix3D::Transform_Vector( view, Vector3( centre.X, centre.Y, centre.Z + radius * HEAT_HAZE_LIFT ), &columnEye );+ Matrix3D::Transform_Vector( view, Vector3( centre.X, centre.Y, centre.Z + radius * look.lift ), &columnEye );if (-eye.Z <= zNear || -columnEye.Z <= zNear)continue;const Vector4 flameClip = projection * eye;@@ -407,22 +448,75 @@ static void gatherHeatHaze( CameraClass &camera, const std::vector<ParticleSysteconst Real x = clip.X / clip.W;const Real y = clip.Y / clip.W;const Real rx = radius * projection[ 0 ][ 0 ] / clip.W;- const Real ry = radius * HEAT_HAZE_STRETCH * projection[ 1 ][ 1 ] / clip.W;+ const Real ry = radius * look.stretch * projection[ 1 ][ 1 ] / clip.W;if (WWMath::Fabs( x ) - rx > 1.0f || WWMath::Fabs( y ) - ry > 1.0f)continue;- Real shift = HEAT_HAZE_AMPLITUDE * ry * 0.5f * viewHeight;- if (shift > HEAT_HAZE_MAX_SHIFT)- shift = HEAT_HAZE_MAX_SHIFT;+ Real shift = look.amplitude * ry * 0.5f * viewHeight;+ if (shift > look.maxShift)+ shift = look.maxShift;const float splat[ DIRECT3D11_HEAT_SPLAT_FLOATS ] = {// the camera's clip space into the frame's(viewport.Min.X + ( x * 0.5f + 0.5f ) * viewWidth) * 2.0f - 1.0f,1.0f - (viewport.Min.Y + ( 0.5f - y * 0.5f ) * viewHeight) * 2.0f,rx * viewWidth, ry * viewHeight,flameClip.Z / flameClip.W, shift * strength, seconds, 0.0f,- zNear, zFar, HEAT_HAZE_CLEARANCE, HEAT_HAZE_SOFTNESS };+ zNear, zFar, look.clearance, HEAT_HAZE_SOFTNESS,+ 0.0f, 0.0f, 0.0f, 0.0f };s_heatSplats.insert( s_heatSplats.end(), splat, splat + DIRECT3D11_HEAT_SPLAT_FLOATS );++count;}++ // The lasers, after the fires so a crowd of beams cannot crowd a fire out: a row of round splats+ // down each beam, a radius apart so they blur into one sleeve, each with the beam's direction on+ // the screen so the band the beam is drawn in stays still (dx11post.cpp, Across).+ s_heatBeams.clear();+ W3DLaserDraw::gatherHeat( s_heatBeams );+ for (size_t b = 0; b < s_heatBeams.size() && count < (Int)DIRECT3D11_HEAT_SPLAT_LIMIT; ++b)+ {+ const LaserHeat &beam = s_heatBeams[ b ];+ Real radius = beam.glowWidth * HEAT_BEAM_RADIUS_SCALE;+ if (radius < HEAT_BEAM_MIN_RADIUS)+ radius = HEAT_BEAM_MIN_RADIUS;+ const Vector3 run = beam.end - beam.start;+ const Real length = run.Length();+ Int steps = (Int)( length / radius ) + 1;+ if (steps > HEAT_BEAM_MAX_SPLATS)+ steps = HEAT_BEAM_MAX_SPLATS;+ const Vector3 ahead = run * ( radius / length ); // gatherHeat leaves out a beam of no length+ for (Int s = 0; s < steps && count < (Int)DIRECT3D11_HEAT_SPLAT_LIMIT; ++s)+ {+ const Vector3 at = beam.start + run * ( ( s + 0.5f ) / steps );+ Vector3 eye, aheadEye;+ Matrix3D::Transform_Vector( view, at, &eye );+ Matrix3D::Transform_Vector( view, at + ahead, &aheadEye );+ if (-eye.Z <= zNear || -aheadEye.Z <= zNear)+ continue;+ const Vector4 clip = projection * eye;+ const Vector4 aheadClip = projection * aheadEye;+ if (clip.W <= 0.0f || aheadClip.W <= 0.0f)+ continue;+ const Real x = clip.X / clip.W;+ const Real y = clip.Y / clip.W;+ const Real rx = radius * projection[ 0 ][ 0 ] / clip.W;+ const Real ry = radius * projection[ 1 ][ 1 ] / clip.W;+ if (WWMath::Fabs( x ) - rx > 1.0f || WWMath::Fabs( y ) - ry > 1.0f)+ continue;+ Real shift = HEAT_BEAM_AMPLITUDE * ry * 0.5f * viewHeight;+ if (shift > HEAT_BEAM_MAX_SHIFT)+ shift = HEAT_BEAM_MAX_SHIFT;+ const Real still = beam.coreRadius * projection[ 1 ][ 1 ] / clip.W * 0.5f * viewHeight;+ const float splat[ DIRECT3D11_HEAT_SPLAT_FLOATS ] = {+ (viewport.Min.X + ( x * 0.5f + 0.5f ) * viewWidth) * 2.0f - 1.0f,+ 1.0f - (viewport.Min.Y + ( 0.5f - y * 0.5f ) * viewHeight) * 2.0f,+ rx * viewWidth, ry * viewHeight,+ clip.Z / clip.W, shift * beam.light, seconds, 0.0f,+ zNear, zFar, HEAT_HAZE_CLEARANCE, HEAT_HAZE_SOFTNESS,+ ( aheadClip.X / aheadClip.W - x ) * viewWidth, ( aheadClip.Y / aheadClip.W - y ) * viewHeight,+ still * HEAT_BEAM_STILL_SCALE, still * HEAT_BEAM_STILL_FADE };+ s_heatSplats.insert( s_heatSplats.end(), splat, splat + DIRECT3D11_HEAT_SPLAT_FLOATS );+ ++count;+ }+ }Direct3D11_Set_Heat_Splats( s_heatSplats.empty() ? NULL : &s_heatSplats[ 0 ], (unsigned)count );}@@ -1967,6 +2061,8 @@ void W3DParticleSystemManager::reset()m_frameView.clear();m_frameFires.clear();m_frameFireFades.clear();+ m_frameExhausts.clear();+ m_frameExhaustFades.clear();m_fieldSystems.clear();m_sunMapCasters.clear();invalidateGroundFields(); // the object IDs it holds belong to the game that ended@@ -2028,6 +2124,8 @@ void W3DParticleSystemManager::refreshFrameView( void )m_frameView.clear();m_frameFires.clear();m_frameFireFades.clear();+ m_frameExhausts.clear();+ m_frameExhaustFades.clear();m_fieldSystems.clear();for (ParticleSystemListIt it = m_allParticleSystemList.begin(); it != m_allParticleSystemList.end(); ++it){@@ -2060,6 +2158,17 @@ void W3DParticleSystemManager::refreshFrameView( void )m_frameFires.push_back( sys );m_frameFireFades.push_back( fade );}+ // A missile's flame: a weapon's ProjectileExhaust is created attached to the projectile object+ // (MissileAIUpdate, NeutronMissileUpdate) at WEAPON_TRAIL priority. The additive ones are the+ // flame (MissileExhaust, the Stinger's, the Raptor's); the smoke trails (Scud, Tomahawk, TOW)+ // blend, and laser flares are placed rather than attached to an object. hasRiddenObject stays+ // set once the missile has hit, so the trail's haze fades with it instead of going in a frame.+ else if (sys->getPriority() == WEAPON_TRAIL && sys->getShaderType() == ParticleSystemInfo::ADDITIVE+ && sys->hasRiddenObject())+ {+ m_frameExhausts.push_back( sys );+ m_frameExhaustFades.push_back( fade );+ }}refreshGpuSystems();@@ -2299,7 +2408,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)if (TheGlobalData->m_firelight && Direct3D11_Lights_Per_Pixel())gatherFirelights( bbox, m_lastLogicFrameUpdate, m_frameFires, m_frameFireFades );if (TheGlobalData->m_heatHaze && !TheGlobalData->m_classicGraphics && Direct3D11_Present_Is_Enabled())- gatherHeatHaze( rinfo.Camera, m_frameFires, m_frameFireFades );+ gatherHeatHaze( rinfo.Camera, m_frameFires, m_frameFireFades, m_frameExhausts, m_frameExhaustFades );}// Only a CPU drawn smoke system takes a light (pickSmokeLights); with none, the walk over every// fire, a GPU one's samples aged in closed form, is a third of a frame thrown away.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cppindex 09c4db85d..c53edbc53 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp@@ -1004,10 +1004,12 @@ static const char * const WARP_SHADER_BODY ="}\n";// -heathaze. Every flame particle is a splat, six vertices made out of SV_VertexID like the full-// screen triangle, its numbers read out of a buffer three float4 a splat (dx11runtime.h has the+// screen triangle, its numbers read out of a buffer four float4 a splat (dx11runtime.h has the// layout). The splat writes a shift in texture coordinates into rg and its weight into b, added up// over every splat that covers the pixel; the composite divides by the weight once it passes one,-// so a stack of flames shimmers as hard as one does and only the edges fade.+// so a stack of flames shimmers as hard as one does and only the edges fade. A laser's splats+// carry the beam's direction on the screen and leave a band along it with no weight, so the air+// round a beam bends and the beam itself, which wrote no depth to hide it, stays where it is.//// The shift is one field over the whole screen rather than per splat, so overlapping flames bend// the same way and add up instead of cancelling. Its waves run up the screen with the time: heat@@ -1023,6 +1025,8 @@ static const char * const HEAT_SPLAT_VERTEX_SOURCE =" float2 Screen : TEXCOORD1;\n"" float4 Heat : TEXCOORD2;\n"" float4 Planes : TEXCOORD3;\n"+ " float4 Across : TEXCOORD4;\n"+ " float2 Offset : TEXCOORD5;\n""};\n""\n""static const float2 CORNERS[6] =\n"@@ -1035,14 +1039,16 @@ static const char * const HEAT_SPLAT_VERTEX_SOURCE ="{\n"" uint splat = index / 6;\n"" float2 corner = CORNERS[index % 6];\n"- " float4 shape = Splats.Load(splat * 3);\n"+ " float4 shape = Splats.Load(splat * 4);\n"" SplatOutput output;\n"" float2 clip = shape.xy + corner * shape.zw;\n"" output.Position = float4(clip, 0.0, 1.0);\n"" output.Corner = corner;\n"" output.Screen = clip * float2(0.5, -0.5) + 0.5;\n"- " output.Heat = Splats.Load(splat * 3 + 1);\n"- " output.Planes = Splats.Load(splat * 3 + 2);\n"+ " output.Heat = Splats.Load(splat * 4 + 1);\n"+ " output.Planes = Splats.Load(splat * 4 + 2);\n"+ " output.Across = Splats.Load(splat * 4 + 3);\n"+ " output.Offset = corner * shape.zw;\n"" return output;\n""}\n";@@ -1055,6 +1061,8 @@ static const char * const HEAT_SPLAT_SHADER_BODY =" float2 Screen : TEXCOORD1;\n"" float4 Heat : TEXCOORD2;\n"" float4 Planes : TEXCOORD3;\n"+ " float4 Across : TEXCOORD4;\n"+ " float2 Offset : TEXCOORD5;\n""};\n""\n""static const float HEAT_FREQUENCY = 50.0;\n"@@ -1078,8 +1086,21 @@ static const char * const HEAT_SPLAT_SHADER_BODY =// Only what lies well behind the flames bends: a unit standing in the fire, or in front of// it, keeps its outline." weight *= saturate((scene - flame - input.Planes.z) / max(input.Planes.w, 0.0001));\n"- " if (weight <= 0.0) discard;\n"" float aspect = (float)width / (float)height;\n"+ // A beam's splat: no weight within Across.z of the beam's line, in shares of the frame's+ // height, coming up to full over Across.w further out. The composite reads nothing where the+ // weight is nought, so the beam is neither moved nor smeared onto the air beside it. Never+ // narrower than one texel of the half size target, or its bilinear read leaks weight onto a+ // beam seen from far off and the beam wobbles.+ " if (dot(input.Across.xy, input.Across.xy) > 0.0)\n"+ " {\n"+ " float2 along = normalize(input.Across.xy * float2(aspect, 1.0));\n"+ " float2 offset = input.Offset * float2(aspect, 1.0) * 0.5;\n"+ " float off = abs(offset.x * along.y - offset.y * along.x);\n"+ " float still = max(input.Across.z, 2.0 / (float)height);\n"+ " weight *= saturate((off - still) / max(input.Across.w, 0.0001));\n"+ " }\n"+ " if (weight <= 0.0) discard;\n"" float2 p = float2(input.Screen.x * aspect, input.Screen.y) * HEAT_FREQUENCY;\n"" float t = input.Heat.z * HEAT_RISE;\n"// Bands across the column climbing it, each swaying sideways a little along its length, so thediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex 4ed89011c..07427f909 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -242,9 +242,12 @@ void Direct3D11_Set_Fire_Look(bool fire);// DIRECT3D11_HEAT_SPLAT_FLOATS floats: centre x, y and half width, half height in the frame's// clip space; the hardware depth that hides it, its strongest shift in texture coordinates, the// time in seconds, 0; the near and far planes, then in world units how far behind the flame a-// surface starts to bend and over how much further it comes up to full. Past-// DIRECT3D11_HEAT_SPLAT_LIMIT the rest are dropped. A count of zero clears them.-const unsigned DIRECT3D11_HEAT_SPLAT_FLOATS = 12;+// surface starts to bend and over how much further it comes up to full; last, for a laser's+// splat, the beam's direction in the frame's clip space, then the half width of the band along it+// left still and the width over which the bending comes up beyond it, both as shares of the+// frame's height (all four nought for a flame). Past DIRECT3D11_HEAT_SPLAT_LIMIT the rest are+// dropped. A count of zero clears them.+const unsigned DIRECT3D11_HEAT_SPLAT_FLOATS = 16;const unsigned DIRECT3D11_HEAT_SPLAT_LIMIT = 2048;void Direct3D11_Set_Heat_Splats(const float * splats, unsigned count);diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cppindex f306c5d78..0236c1845 100644--- a/GeneralsMD/Code/Tests/test_dx11post.cpp+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp@@ -401,10 +401,20 @@ TEST(dx11post_a_heat_splat_bends_the_picture_under_it_and_none_leaves_it_alone)const float splat[DIRECT3D11_HEAT_SPLAT_FLOATS] = {0.0f, 0.0f, 0.5f, 0.5f,0.5f, 0.05f, 0.0f, 0.0f,- 1.0f, 100.0f, 5.0f, 10.0f };+ 1.0f, 100.0f, 5.0f, 10.0f,+ 0.0f, 0.0f, 0.0f, 0.0f };+ // A laser's splat, the same with a level beam through the middle row and a still band 6% of+ // the frame's height either side of it (3.8 pixels), full past another 2%: the rows on the beam+ // keep every pixel, and the diagonal still bends in rows clear of the band.+ float beam[DIRECT3D11_HEAT_SPLAT_FLOATS];+ memcpy(beam, splat, sizeof(beam));+ beam[12] = 1.0f;+ beam[14] = 0.06f;+ beam[15] = 0.02f;+ const unsigned middle = SURFACE_SIZE / 2;// Frame 2 sets the splat again over a depth of a half, the flame's own: a unit standing in the- // fire, which has to keep every pixel.- for (unsigned frame = 0; frame < 3; ++frame) {+ // fire, which has to keep every pixel. Frame 3 sets the beam's.+ for (unsigned frame = 0; frame < 4; ++frame) {post.Open_Frame();post.Begin_Frame();device.Set_Scene_View(post.Scene_View());@@ -412,7 +422,7 @@ TEST(dx11post_a_heat_splat_bends_the_picture_under_it_and_none_leaves_it_alone)(frame == 2) ? 0.5f : 1.0f, 0);CHECK(write_scene(device, post, picture));if (frame != 1) {- post.Set_Heat_Splats(splat, 1);+ post.Set_Heat_Splats((frame == 3) ? beam : splat, 1);}CHECK_EQ(frame != 1, post.Heat_Haze_Scene(device.Get_Depth_Texture()));CHECK(post.Run_Chain());@@ -424,6 +434,23 @@ TEST(dx11post_a_heat_splat_bends_the_picture_under_it_and_none_leaves_it_alone)CHECK(differing_pixels(picture, result, pitch) > 8u);CHECK_EQ(DARK_LEVEL, pixel_level(result, pitch, 1, SURFACE_SIZE - 2));CHECK_EQ(LIGHT_LEVEL, pixel_level(result, pitch, SURFACE_SIZE - 2, 1));+ } else if (frame == 3) {+ unsigned on_beam = 0;+ unsigned clear_of_it = 0;+ for (unsigned y = 0; y < SURFACE_SIZE; ++y) {+ for (unsigned x = 0; x < SURFACE_SIZE; ++x) {+ if (pixel_level(picture, SURFACE_SIZE * BYTES_A_PIXEL, x, y) == pixel_level(result, pitch, x, y)) {+ continue;+ }+ if (y + 2 >= middle && y <= middle + 1) {+ ++on_beam;+ } else if (y + 6 <= middle || y >= middle + 6) {+ ++clear_of_it;+ }+ }+ }+ CHECK_EQ(0u, on_beam);+ CHECK(clear_of_it > 2u);} else {CHECK_EQ(0u, differing_pixels(picture, result, pitch));}