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
fix(w3ddevice): smoke shade from the plume's front, fire light in fire's colour
Olcay Seygan8f8948e75f89
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex de3b9dd2d..f0b9dc6ab 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -211,6 +211,7 @@ public:Real m_smokeFireRadius; // "-smokefireradius"Real m_smokeFireCap; // "-smokefirecap"Real m_smokeFireFullWeight; // "-smokefirefull"+ Real m_smokeFireHeight; // "-smokefireheight"Bool m_classicGraphics; // "ClassicGraphics": the game's own art, tile, shadows and picture; read at startupBool m_shadowMap; // "-shadowmap": draw the casters into the sun's depth buffer as wellBool m_shadowMapReport; // "-shadowmapreport": log what ended up in that buffer, once a seconddiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 360ad1c16..4c219729d 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1014,13 +1014,16 @@ Int parseNoSmokeFireLight(char *args[], int)own figure (the field stays below zero). All of it is client-side colour and shade, read by therenderer every frame, so a network game and a replay are untouched.-smokeselfshadow <0..1> how dark a particle on a plume's far side goes (0.8)- -smokeselfcurve <0.25..8> how fast that shade grows from the plume's sun side (2: slow at- first, so the sun side keeps its brightness)+ -smokeselfcurve <0.25..32> how fast that shade grows from the plume's sun side (8: the+ sun side keeps its brightness, the back takes it all)-smokegroundshadow <0..1> how dark the thickest smoke leaves the ground and units (0.4)-smokedensity <0..10> scale on every particle's thickness to the sun (1)- -smokefiregain <0..4> glow a full-strength fire adds to the smoke at its centre (0.6)- -smokefireradius <1..1000> reach of a fire's light past its own flames, world units (35)- -smokefirecap <0..1> most the glow raises any colour channel of a particle (0.7)+ -smokefiregain <0..4> fire light a full-strength fire puts on the smoke just above+ it (0.7)+ -smokefireradius <1..1000> reach of a fire's light sideways past its own flames, world+ units (35)+ -smokefireheight <1..2000> height over the flames at which the light is gone (90)+ -smokefirecap <0..1> most fire light any particle takes (0.9)-smokefirefull <1..10000> flame brightness times size at which a fire lights at fullstrength; a smaller fire lights at its share of it (120) */static Int parseSmokeTuning(char *args[], int num, Real *field, Real lo, Real hi)@@ -1043,7 +1046,7 @@ Int parseSmokeSelfShadow(char *args[], int num)Int parseSmokeSelfCurve(char *args[], int num){return TheWritableGlobalData- ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeSelfShadowCurve, 0.25f, 8.0f) : 1;+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeSelfShadowCurve, 0.25f, 32.0f) : 1;}Int parseSmokeGroundShadow(char *args[], int num)@@ -1076,6 +1079,12 @@ Int parseSmokeFireCap(char *args[], int num)? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireCap, 0.0f, 1.0f) : 1;}+Int parseSmokeFireHeight(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireHeight, 1.0f, 2000.0f) : 1;+}+Int parseSmokeFireFull(char *args[], int num){return TheWritableGlobalData@@ -2487,6 +2496,7 @@ static CommandLineParam params[] ={ "-smokefireradius", parseSmokeFireRadius },{ "-smokefirecap", parseSmokeFireCap },{ "-smokefirefull", parseSmokeFireFull },+ { "-smokefireheight", parseSmokeFireHeight },{ "-quickstart", parseQuickStart },/* In every build: EA kept them to Debug and Internal, so a Release run could not skip the logo or themovies. */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 6e80cb778..9804bfcbe 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -697,6 +697,7 @@ GlobalData::GlobalData()m_smokeFireRadius = -1.0f;m_smokeFireCap = -1.0f;m_smokeFireFullWeight = -1.0f;+ m_smokeFireHeight = -1.0f;m_classicGraphics = FALSE;m_shadowMap = TRUE; //the sun's own shadows are what the game draws with nowm_shadowMapOnly = TRUE; //and they replace the stencil volumes rather than joining themdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex 2c32826c4..0f7131541 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -142,11 +142,16 @@ const Real cosAngleToCare = cos ((0.2 * PI) / 180.0); //1.5 degree difference// cloud and the smoke itself scatters some of the sun on. How thick each particle is to the sun is// particleSunMapOpticalDepth's. The self-shade is a particle's own: how dark one on its plume's far// side goes, and the power that keeps the sun side lit (ffshader.h, smoke_reaching). The ground-// figure held up on Golden Oasis on 2026-10-03; the self-shade is a guess at twice what it was.+// figure held up on Golden Oasis on 2026-10-03, and 0.8 and 8 are what the 2026-10-04 sweep picked+// for the self-shade on soot (sun side 6% under the unshaded plume, far side 0.73 of it), before+// the shade was measured from the plume's front rather than from a width ahead of its centre.// -smokegroundshadow, -smokeselfshadow, -smokeselfcurve and -smokedensity overrule them for a run.#define SMOKE_SHADOW_STRENGTH 0.4f#define SMOKE_SELF_SHADOW_GAIN 0.8f-#define SMOKE_SELF_SHADOW_CURVE 2.0f+#define SMOKE_SELF_SHADOW_CURVE 8.0f++// W3DParticleSys.cpp: the fire light values the last particle pass used.+extern void W3DSmokeFireTuningInForce( Real *gain, Real *radius, Real *height, Real *cap, Real *fullWeight );/** A tuning switch's value, or the build's own figure when it was not given (below zero). */static inline Real smokeTuning( Real given, Real builtIn )@@ -3978,12 +3983,17 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus ){nextReportFrame = frame + 10 * LOGICFRAMES_PER_SECOND;systemsLastReport = systemsHeld;+ Real fireGain, fireRadius, fireHeight, fireCap, fireFull;+ W3DSmokeFireTuningInForce( &fireGain, &fireRadius, &fireHeight, &fireCap, &fireFull );DEBUG_LOG(("SMOKEMAP: frame %u, %d casters from %d systems in the sun's map, %d more past its limit;"- " ground %.2f self %.2f curve %.2f density %.2f\n",+ " ground %.2f self %.2f curve %.2f density %.2f; fire light %s gain %.2f radius %.0f height %.0f"+ " cap %.2f full %.0f\n",frame, (Int)found.size(), systemsHeld, (Int)( inBox - found.size() ),smokeTuning( TheGlobalData->m_smokeGroundShadow, SMOKE_SHADOW_STRENGTH ),smokeTuning( TheGlobalData->m_smokeSelfShadowGain, SMOKE_SELF_SHADOW_GAIN ),- smokeTuning( TheGlobalData->m_smokeSelfShadowCurve, SMOKE_SELF_SHADOW_CURVE ), density));+ smokeTuning( TheGlobalData->m_smokeSelfShadowCurve, SMOKE_SELF_SHADOW_CURVE ), density,+ TheGlobalData->m_smokeFireLighting ? "on" : "off", fireGain, fireRadius, fireHeight, fireCap,+ fireFull));}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex 419ba7252..f6b65d7e0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -81,35 +81,47 @@ static Bool particlePresetShader( ParticleSystemInfo::ParticleShaderType type, S//-------------------------------------------------------------------------------------------------// Fire lights the smoke around it. Each frame the additive systems (flames, explosions, muzzle-// flashes) are reduced to one point light apiece at their brightness-weighted centre, the scene's-// enabled light pulses join them, and every alpha-blended particle near one of those gets the-// light's colour added to its own, fading with distance. A plume is lit at its base and goes grey-// as it rises out of reach, and it flickers with the flames because the flames' own particles are-// what measure the light. All of it is client-side colour on the CPU, so both devices draw it.+// flashes) are reduced to one light apiece at their brightness-weighted centre, the scene's enabled+// light pulses join them, and every alpha-blended particle near one of those is lit by it. A fire's+// light is the colour of fire, not of its particles: an additive flame's vertex colour is near white+// and the orange is in its texture, so the hue taken from the vertices made the light grey. It is+// strongest just over the flames and falls away with height above them and sideways from them, so a+// plume is lit at its base and goes grey as it rises; it flickers with the flames because the+// flames' own particles are what measure it. The light a particle takes is reflected by its own+// colour and, past white, keeps its hue rather than clipping, so white smoke turns orange and soot+// dark orange. All of it is client-side colour on the CPU, so both devices draw it. It goes in+// before the shade, being vertex colour, so a plume's own shade dims it too (the shaders have no+// channel to carry it past the shade); a thin particle takes less of it, which keeps the plume's thin+// edge, unshaded, from glowing brighter than its shaded core.//-------------------------------------------------------------------------------------------------static const Int SMOKE_LIGHTS_MAX = 32; ///< lights gathered a frame, the strongest keptstatic const Int SMOKE_LIGHTS_PER_SYSTEM = 4; ///< lights one smoke system evaluates per particlestatic const Real FIRE_LIGHT_FULL_WEIGHT = 120.0f; ///< sum of brightness x size at which a fire is full strengthstatic const Real FIRE_LIGHT_MIN_WEIGHT = 4.0f; ///< below this an additive system lights nothing-static const Real FIRE_LIGHT_RADIUS = 35.0f; ///< reach of a fire's light beyond its own spread+static const Real FIRE_LIGHT_RADIUS = 35.0f; ///< sideways reach of a fire's light beyond its own spreadstatic const Real FIRE_LIGHT_SPREAD_SCALE = 2.0f; ///< times the flames' RMS spread, added to the reachstatic const Real FIRE_LIGHT_MAX_RADIUS = 140.0f;-static const Real FIRE_LIGHT_GAIN = 0.6f; ///< glow a full-strength fire adds at its centre+static const Real FIRE_LIGHT_HEIGHT = 90.0f; ///< height over the flames at which their light is gone+static const Real FIRE_LIGHT_BELOW_SHARE = 0.25f; ///< share of the sideways reach the light goes below them+static const Real FIRE_LIGHT_GAIN = 0.7f; ///< light a full-strength fire puts on the smoke over itstatic const Real PULSE_LIGHT_GAIN = 0.4f; ///< same for an FX light pulse, whose colour is already full-static const Real SMOKE_LIGHT_MAX_GLOW = 0.7f; ///< most any one channel is raised by--/** The figures above that -smokefiregain, -smokefireradius, -smokefirecap and -smokefirefull- * overrule for a run, taken once a frame before the jobs start and only read by them. The gain- * scales the pulses' glow too, and the radius the cap on a big fire's reach. The full weight is- * the one a fire's size is judged against, and a small fire well under it lights at that fraction- * of the gain; whether that is why FireFactionSmall's glow could not be seen is not measured. */+static const Real SMOKE_LIGHT_MAX_GLOW = 0.9f; ///< most light any particle takes, brightest channel+static const Real SMOKE_LIGHT_SOOT_SHARE = 0.35f; ///< share of the light even black smoke gives back+static const Real SMOKE_LIGHT_THIN_ALPHA = 0.25f; ///< a particle thinner than this takes its share of the light+static const Real FIRE_LIGHT_RED = 1.0f, FIRE_LIGHT_GREEN = 0.55f, FIRE_LIGHT_BLUE = 0.24f; ///< 255,140,60++/** The figures above that -smokefiregain, -smokefireradius, -smokefireheight, -smokefirecap and+ * -smokefirefull overrule for a run, taken once a frame before the jobs start and only read by+ * them. The gain scales the pulses' light too, and the radius the cap on a big fire's reach. The+ * full weight is the one a fire's size is judged against, and a small fire well under it lights at+ * that fraction of the gain. */struct SmokeFireTuning{- Real gain, pulseGain, radius, maxRadius, cap, fullWeight;+ Real gain, pulseGain, radius, maxRadius, height, cap, fullWeight;};static SmokeFireTuning theSmokeFire = { FIRE_LIGHT_GAIN, PULSE_LIGHT_GAIN, FIRE_LIGHT_RADIUS,- FIRE_LIGHT_MAX_RADIUS, SMOKE_LIGHT_MAX_GLOW, FIRE_LIGHT_FULL_WEIGHT };+ FIRE_LIGHT_MAX_RADIUS, FIRE_LIGHT_HEIGHT, SMOKE_LIGHT_MAX_GLOW, FIRE_LIGHT_FULL_WEIGHT };static void refreshSmokeFireTuning( void ){@@ -119,16 +131,31 @@ static void refreshSmokeFireTuning( void )theSmokeFire.pulseGain = PULSE_LIGHT_GAIN * gain / FIRE_LIGHT_GAIN;theSmokeFire.radius = radius;theSmokeFire.maxRadius = FIRE_LIGHT_MAX_RADIUS * radius / FIRE_LIGHT_RADIUS;+ theSmokeFire.height = TheGlobalData->m_smokeFireHeight >= 1.0f ? TheGlobalData->m_smokeFireHeight : FIRE_LIGHT_HEIGHT;theSmokeFire.cap = TheGlobalData->m_smokeFireCap >= 0.0f ? TheGlobalData->m_smokeFireCap : SMOKE_LIGHT_MAX_GLOW;theSmokeFire.fullWeight = TheGlobalData->m_smokeFireFullWeight >= 1.0f? TheGlobalData->m_smokeFireFullWeight : FIRE_LIGHT_FULL_WEIGHT;}-/** A light as the smoke sees it: its colour is already scaled by its strength and gain. */+/** The fire light values in force this frame, for the SMOKEMAP line in the log. */+void W3DSmokeFireTuningInForce( Real *gain, Real *radius, Real *height, Real *cap, Real *fullWeight )+{+ *gain = theSmokeFire.gain;+ *radius = theSmokeFire.radius;+ *height = theSmokeFire.height;+ *cap = theSmokeFire.cap;+ *fullWeight = theSmokeFire.fullWeight;+}++/** A light as the smoke sees it: its colour is already scaled by its strength and gain. A fire's+ * reaches its radius sideways, its height upwards and a share of the radius downwards; a pulse's+ * (invHeight zero) is a ball. reachSq is the ball that holds either, for picking. */struct SmokeLight{Real x, y, z;Real radiusSq, invRadiusSq;+ Real invHeight, invBelow;+ Real reachSq;Real r, g, b;Real strength; ///< orders the list, strongest first};@@ -155,7 +182,7 @@ static void addSmokeLight( SmokeLight *lights, Int &count, const SmokeLight &ligstatic void gatherFireLight( ParticleSystem *sys, SmokeLight *lights, Int &count,const AABoxClass &view ){- Real w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f, sq = 0.0f, r = 0.0f, g = 0.0f, b = 0.0f;+ Real w = 0.0f, x = 0.0f, y = 0.0f, z = 0.0f, sq = 0.0f;for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext){const RGBColor *c = p->getColor();@@ -168,9 +195,6 @@ static void gatherFireLight( ParticleSystem *sys, SmokeLight *lights, Int &county += pw * pos->y;z += pw * pos->z;sq += pw * (pos->x * pos->x + pos->y * pos->y + pos->z * pos->z);- r += pw * c->red;- g += pw * c->green;- b += pw * c->blue;}if (w < FIRE_LIGHT_MIN_WEIGHT)return;@@ -185,22 +209,24 @@ static void gatherFireLight( ParticleSystem *sys, SmokeLight *lights, Int &countif (radius > theSmokeFire.maxRadius)radius = theSmokeFire.maxRadius;- if (WWMath::Fabs( light.x - view.Center.X ) > view.Extent.X + radius- || WWMath::Fabs( light.y - view.Center.Y ) > view.Extent.Y + radius- || WWMath::Fabs( light.z - view.Center.Z ) > view.Extent.Z + radius)+ const Real height = theSmokeFire.height;+ const Real reach = radius > height ? radius : height;+ if (WWMath::Fabs( light.x - view.Center.X ) > view.Extent.X + reach+ || WWMath::Fabs( light.y - view.Center.Y ) > view.Extent.Y + reach+ || WWMath::Fabs( light.z - view.Center.Z ) > view.Extent.Z + reach)return;- // the hue from the flames' average colour, the strength from how much of them there is+ // fire's own colour, and the strength from how much of the flames there islight.strength = w < theSmokeFire.fullWeight ? w / theSmokeFire.fullWeight : 1.0f;- Real peak = r > g ? r : g;- if (b > peak)- peak = b;- const Real scale = light.strength * theSmokeFire.gain / peak;- light.r = r * scale;- light.g = g * scale;- light.b = b * scale;+ const Real scale = light.strength * theSmokeFire.gain;+ light.r = FIRE_LIGHT_RED * scale;+ light.g = FIRE_LIGHT_GREEN * scale;+ light.b = FIRE_LIGHT_BLUE * scale;light.radiusSq = radius * radius;light.invRadiusSq = 1.0f / light.radiusSq;+ light.invHeight = 1.0f / height;+ light.invBelow = 1.0f / (radius * FIRE_LIGHT_BELOW_SHARE);+ light.reachSq = reach * reach;addSmokeLight( lights, count, light );}@@ -236,6 +262,9 @@ static void gatherPulseLights( SmokeLight *lights, Int &count, const AABoxClasslight.z = pos.Z;light.radiusSq = farRange * farRange;light.invRadiusSq = 1.0f / light.radiusSq;+ light.invHeight = 0.0f; // a ball+ light.invBelow = 0.0f;+ light.reachSq = light.radiusSq;light.r = diffuse.X * theSmokeFire.pulseGain;light.g = diffuse.Y * theSmokeFire.pulseGain;light.b = diffuse.Z * theSmokeFire.pulseGain;@@ -298,15 +327,19 @@ static Int pickSmokeLights( ParticleSystem *sys, const SmokeLight *lights, Int cconst Real dx = l.x < minX ? minX - l.x : (l.x > maxX ? l.x - maxX : 0.0f);const Real dy = l.y < minY ? minY - l.y : (l.y > maxY ? l.y - maxY : 0.0f);const Real dz = l.z < minZ ? minZ - l.z : (l.z > maxZ ? l.z - maxZ : 0.0f);- if (dx * dx + dy * dy + dz * dz < l.radiusSq)+ if (dx * dx + dy * dy + dz * dz < l.reachSq)picked[ n++ ] = l;}return n;}-/** A smoke particle's colour with the picked lights added: (1 - d^2/R^2)^2 of each light's colour,- * each channel raised by at most SMOKE_LIGHT_MAX_GLOW and the result clamped to 1. */-static inline void lightSmoke( const Coord3D *pos, const SmokeLight *lights, Int count,+/** A smoke particle's colour lit by the picked lights. A fire's light falls as (1 - h^2/R^2)^2+ * sideways and (1 - dz/H)^2 above the flames, much faster below them; a pulse's as (1 - d^2/R^2)^2+ * all round. The sum is held to SMOKE_LIGHT_MAX_GLOW in its brightest channel, scaled down by how+ * thin the particle is, and reflected by the particle's own colour (lifted by the soot share, so+ * black smoke still shows the fire); a result past white is scaled back whole, which keeps its+ * hue. */+static inline void lightSmoke( const Coord3D *pos, Real alpha, const SmokeLight *lights, Int count,Real &red, Real &green, Real &blue ){Real r = 0.0f, g = 0.0f, b = 0.0f;@@ -314,17 +347,45 @@ static inline void lightSmoke( const Coord3D *pos, const SmokeLight *lights, Int{const SmokeLight &l = lights[ i ];const Real dx = pos->x - l.x, dy = pos->y - l.y, dz = pos->z - l.z;- const Real t = 1.0f - (dx * dx + dy * dy + dz * dz) * l.invRadiusSq;- if (t <= 0.0f)- continue;- const Real f = t * t;+ Real f;+ if (l.invHeight > 0.0f)+ {+ const Real side = 1.0f - (dx * dx + dy * dy) * l.invRadiusSq;+ const Real up = (dz >= 0.0f) ? 1.0f - dz * l.invHeight : 1.0f + dz * l.invBelow;+ if (side <= 0.0f || up <= 0.0f)+ continue;+ f = side * side * up * up;+ }+ else+ {+ const Real t = 1.0f - (dx * dx + dy * dy + dz * dz) * l.invRadiusSq;+ if (t <= 0.0f)+ continue;+ f = t * t;+ }r += f * l.r;g += f * l.g;b += f * l.b;}- red = WWMath::Min( 1.0f, red + WWMath::Min( r, theSmokeFire.cap ) );- green = WWMath::Min( 1.0f, green + WWMath::Min( g, theSmokeFire.cap ) );- blue = WWMath::Min( 1.0f, blue + WWMath::Min( b, theSmokeFire.cap ) );++ Real peak = WWMath::Max( r, WWMath::Max( g, b ) );+ if (peak <= 0.0f)+ return;+ Real scale = (peak > theSmokeFire.cap) ? theSmokeFire.cap / peak : 1.0f;+ if (alpha < SMOKE_LIGHT_THIN_ALPHA)+ scale *= alpha / SMOKE_LIGHT_THIN_ALPHA;++ const Real soot = SMOKE_LIGHT_SOOT_SHARE;+ red += r * scale * (soot + (1.0f - soot) * red);+ green += g * scale * (soot + (1.0f - soot) * green);+ blue += b * scale * (soot + (1.0f - soot) * blue);+ peak = WWMath::Max( red, WWMath::Max( green, blue ) );+ if (peak > 1.0f)+ {+ red /= peak;+ green /= peak;+ blue /= peak;+ }}/** What every job of one frame's billboard fill reads. */@@ -373,7 +434,7 @@ static void fillBillboards( Int index, void *context )const RGBColor *color = p->getColor();Real red = color->red, green = color->green, blue = color->blue;if (lightCount > 0)- lightSmoke( pos, lights, lightCount, red, green, blue );+ lightSmoke( pos, p->getAlpha(), lights, lightCount, red, green, blue );const unsigned packed = DX8Wrapper::Convert_Color_Clamp( Vector4( red, green, blue, p->getAlpha() ) );// The orientation table's index wraps, as it did on Windows (Platform/MsvcFloatCasts.h).const uint8 orientation = floatToByteAsMsvc( p->getAngle() * 255.0f / (2.0f * PI) );@@ -660,7 +721,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)RGBAArray[count].Z = color->blue;RGBAArray[count].W = p->getAlpha();if (lightCount > 0)- lightSmoke( pos, lights, lightCount, RGBAArray[count].X, RGBAArray[count].Y, RGBAArray[count].Z );+ lightSmoke( pos, RGBAArray[count].W, lights, lightCount, RGBAArray[count].X, RGBAArray[count].Y, RGBAArray[count].Z );angleArray[count] = floatToByteAsMsvc( p->getAngle() * 255.0f / (2.0f * PI) );diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex 0ea097c74..cb17af0f3 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -321,7 +321,7 @@ DX11BackendClass::DX11BackendClass()SmokeMapFilled = false;SmokeStrength = 0.0f;SmokeSelfGain = 0.8f;- SmokeSelfCurve = 2.0f;+ SmokeSelfCurve = 8.0f;for (unsigned stage = 0; stage < DX11_BACKEND_TEXTURE_STAGES; ++stage) {set_identity(TextureTransforms[stage]);}@@ -639,8 +639,11 @@ static const char SMOKE_SPLAT_VERTEX_PROGRAM[] =" return splat;\n""}\n";-// The three sums VOLUMETRIC_SAMPLING reads back, added up by the blend. The disc is thickest in its-// middle and thins to nothing at its rim, which is the shape every smoke sprite in the game has.+// The three sums VOLUMETRIC_SAMPLING reads back, added up by the blend, and in alpha the depth of+// the particle nearest the sun, kept by a minimum blend: the plume's own front, which a particle+// with nothing ahead of it is measured from. The disc is thickest in its middle and thins to+// nothing at its rim, which is the shape every smoke sprite in the game has; outside it the quad's+// corners leave the front alone.static const char SMOKE_SPLAT_PIXEL_PROGRAM[] ="struct Splat\n""{\n"@@ -654,7 +657,8 @@ static const char SMOKE_SPLAT_PIXEL_PROGRAM[] =" float thickness = splat.Moment.x * rim * rim;\n"" float depth = splat.Moment.y;\n"" float spread = splat.Moment.z;\n"- " return float4(thickness, thickness * depth, thickness * (depth * depth + spread * spread), 0.0);\n"+ " return float4(thickness, thickness * depth, thickness * (depth * depth + spread * spread),\n"+ " rim > 0.0 ? depth : 1.0);\n""}\n";void DX11BackendClass::Release_Smoke_Map()@@ -725,7 +729,7 @@ bool DX11BackendClass::Make_Smoke_Map()blend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;blend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;blend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;- blend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;+ blend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MIN; // the front, nearest the sunblend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;D3D11_RASTERIZER_DESC rasterizer;@@ -864,7 +868,7 @@ bool DX11BackendClass::Fill_Smoke_Map(const float * casters, unsigned count, floconst unsigned saved_width = ViewportWidth;const unsigned saved_height = ViewportHeight;- const float empty[4] = { 0.0f, 0.0f, 0.0f, 0.0f };+ const float empty[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; // no smoke, and its front at the far planecontext->OMSetRenderTargets(1, &SmokeMapTarget, NULL);context->ClearRenderTargetView(SmokeMapTarget, empty);Set_Viewport(0, 0, SMOKE_MAP_TEXELS, SMOKE_MAP_TEXELS);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.hindex 497c12fbf..e482c9cee 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h@@ -215,7 +215,8 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;//// The smoke has a map of its own over the same sun (DX11BackendClass::Fill_Smoke_Map). Each texel// holds three sums over the particles the sun sees through it: their optical depth, that times-// their depth, and that times their depth squared plus their own thickness squared. Taken+// their depth, and that times their depth squared plus their own thickness squared; its alpha holds+// the depth of the one nearest the sun, which the particles' own shade is measured from. Taken// together that is the smoke along the ray as one bell curve, with an amount, a centre and a// width, and how much of it lies between the sun and a pixel is the curve's integral up to the// pixel's depth. A pixel under a plume gets all of it, a particle on the plume's near side gets@@ -257,11 +258,16 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;" float behind = (sun.z - centre) / width;\n" \" float ahead;\n" \" if (particle) {\n" \- " // A particle inside its own plume: none of the plume ahead of it at the near edge, a\n" \- " // width in front of the centre, and all of it at the far edge, a width behind. The\n" \- " // bell curve's tails darkened the sun side too, which greyed the whole plume; raised to\n" \- " // a power the share stays near nothing on the sun side and climbs at the back.\n" \- " ahead = pow(saturate(behind * 0.5 + 0.5), VolumeParameters.w);\n" \+ " // A particle inside its own plume, measured from the plume's front: the particle\n" \+ " // nearest the sun in this texel (the map's alpha) has none of it ahead, and the share\n" \+ " // reaches all of it as far behind the centre as the front is ahead of it. Raised to a\n" \+ " // power the sun side stays at nothing and the back darkens. The bell curve's tails, and\n" \+ " // a ramp from a width in front of the centre, both darkened the sun side as well. A\n" \+ " // front that bilinear filtering pulled back past the centre, at the plume's edge in the\n" \+ " // map, falls back to a width in front of it.\n" \+ " float front = (sums.w < centre) ? sums.w : centre - width;\n" \+ " float span = max(2.0 * (centre - front), 1e-6);\n" \+ " ahead = pow(saturate((sun.z - front) / span), VolumeParameters.w);\n" \" }\n" \" else {\n" \" // the bell curve's integral up to here, the logistic stand-in for the normal distribution\n" \diff --git a/GeneralsMD/Code/Tests/test_dx11backend.cpp b/GeneralsMD/Code/Tests/test_dx11backend.cppindex 5bba55b73..88dbf9827 100644--- a/GeneralsMD/Code/Tests/test_dx11backend.cpp+++ b/GeneralsMD/Code/Tests/test_dx11backend.cpp@@ -738,7 +738,10 @@ TEST(dx11backend_the_smoke_map_holds_each_casters_three_sums)CHECK_NEAR(middle[0], 2.0f, 0.05f);CHECK_NEAR(middle[1] / middle[0], 0.6f, 0.0001f);CHECK_NEAR(middle[2] / middle[0], 0.6f * 0.6f + 0.025f * 0.025f, 0.0001f);+ // the front, nearest the sun: the one caster's depth, and the far plane where nothing stands+ CHECK_NEAR(middle[3], 0.6f, 0.0001f);CHECK_EQ(corner[0], 0.0f);+ CHECK_EQ(corner[3], 1.0f);device.Get_Context()->Unmap(staging, 0);// Nothing handed over is a frame without smoke: the receivers stop reading the map.