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): smoke shades itself apart from the ground, with tuning switches
Olcay Seygan8bc25cf184ee
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex a6dfe70c9..de3b9dd2d 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -201,6 +201,16 @@ public:Bool m_shadowsForParticles; // "ShadowsForParticles": big alpha-blended particle clouds drop a soft blob on the groundBool m_volumetricSmokeShadows; // "VolumetricSmokeShadows": smoke and dust shade the world and themselves through the sun's map (Direct3D 11)Bool m_smokeFireLighting; // "SmokeFireLighting": smoke takes light from the fire beside it+ // Temporary tuning switches for the two above, client-only and read every frame; below zero means+ // the build's own figure. See the -smoke... switches in CommandLine.cpp.+ Real m_smokeSelfShadowGain; // "-smokeselfshadow"+ Real m_smokeSelfShadowCurve; // "-smokeselfcurve"+ Real m_smokeGroundShadow; // "-smokegroundshadow"+ Real m_smokeShadowDensity; // "-smokedensity"+ Real m_smokeFireGain; // "-smokefiregain"+ Real m_smokeFireRadius; // "-smokefireradius"+ Real m_smokeFireCap; // "-smokefirecap"+ Real m_smokeFireFullWeight; // "-smokefirefull"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 31c026d3b..360ad1c16 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1009,6 +1009,79 @@ Int parseNoSmokeFireLight(char *args[], int)return 1;}+/* Temporary: the smoke's light and shade swept from the command line without a rebuild. Each takes+ one number, clamped to its range; a switch with no number, or one never given, leaves the build's+ own figure (the field stays below zero). All of it is client-side colour and shade, read by the+ renderer 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)+ -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)+ -smokefirefull <1..10000> flame brightness times size at which a fire lights at full+ strength; a smaller fire lights at its share of it (120) */+static Int parseSmokeTuning(char *args[], int num, Real *field, Real lo, Real hi)+{+ if (num > 1 && args[1][0] != '-')+ {+ Real value = (Real)atof(args[1]);+ *field = value < lo ? lo : (value > hi ? hi : value);+ return 2;+ }+ return 1;+}++Int parseSmokeSelfShadow(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeSelfShadowGain, 0.0f, 1.0f) : 1;+}++Int parseSmokeSelfCurve(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeSelfShadowCurve, 0.25f, 8.0f) : 1;+}++Int parseSmokeGroundShadow(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeGroundShadow, 0.0f, 1.0f) : 1;+}++Int parseSmokeDensity(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeShadowDensity, 0.0f, 10.0f) : 1;+}++Int parseSmokeFireGain(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireGain, 0.0f, 4.0f) : 1;+}++Int parseSmokeFireRadius(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireRadius, 1.0f, 1000.0f) : 1;+}++Int parseSmokeFireCap(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireCap, 0.0f, 1.0f) : 1;+}++Int parseSmokeFireFull(char *args[], int num)+{+ return TheWritableGlobalData+ ? parseSmokeTuning(args, num, &TheWritableGlobalData->m_smokeFireFullWeight, 1.0f, 10000.0f) : 1;+}+Int parseNoShaders(char *args[], int){if (TheWritableGlobalData)@@ -2406,6 +2479,14 @@ static CommandLineParam params[] ={ "-noparticleshadows", parseNoParticleShadows },{ "-novolumetricsmoke", parseNoVolumetricSmoke },{ "-nosmokefirelight", parseNoSmokeFireLight },+ { "-smokeselfshadow", parseSmokeSelfShadow },+ { "-smokeselfcurve", parseSmokeSelfCurve },+ { "-smokegroundshadow", parseSmokeGroundShadow },+ { "-smokedensity", parseSmokeDensity },+ { "-smokefiregain", parseSmokeFireGain },+ { "-smokefireradius", parseSmokeFireRadius },+ { "-smokefirecap", parseSmokeFireCap },+ { "-smokefirefull", parseSmokeFireFull },{ "-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 5e1fca97e..6e80cb778 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -689,6 +689,14 @@ GlobalData::GlobalData()m_shadowsForParticles = TRUE; //on by default: the shipped INI has no entry for itm_volumetricSmokeShadows = TRUE;m_smokeFireLighting = TRUE;+ m_smokeSelfShadowGain = -1.0f; //below zero: the build's own figure+ m_smokeSelfShadowCurve = -1.0f;+ m_smokeGroundShadow = -1.0f;+ m_smokeShadowDensity = -1.0f;+ m_smokeFireGain = -1.0f;+ m_smokeFireRadius = -1.0f;+ m_smokeFireCap = -1.0f;+ m_smokeFireFullWeight = -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 493d13ab7..2c32826c4 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -140,8 +140,19 @@ const Real cosAngleToCare = cos ((0.2 * PI) / 180.0); //1.5 degree difference// The smoke in the sun's light. The strength is how dark the thickest cloud leaves the ground and// the smoke behind it, under the solid casters' 0.45 because the sky still lights the ground under a// cloud and the smoke itself scatters some of the sun on. How thick each particle is to the sun is-// particleSunMapOpticalDepth's. Untuned: chosen from the arithmetic, not from a frame.+// 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.+// -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++/** 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 )+{+ return given >= 0.0f ? given : builtIn;+}// Whether the sun's map took this frame. The volumes read it to know whether to stand down, and it// is false on a machine with no Direct3D 11 device, which is what keeps that machine's shadows.@@ -3878,7 +3889,8 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus )found.clear();packed.clear();- if (TheGlobalData->m_volumetricSmokeShadows && TheParticleSystemManager != NULL)+ const Real density = smokeTuning( TheGlobalData->m_smokeShadowDensity, 1.0f );+ if (TheGlobalData->m_volumetricSmokeShadows && TheParticleSystemManager != NULL && density > 0.0f){ParticleSystemManager::ParticleSystemList &systems = TheParticleSystemManager->getAllParticleSystems();for (ParticleSystemManager::ParticleSystemListIt it = systems.begin(); it != systems.end(); ++it)@@ -3894,7 +3906,7 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus )const UnsignedInt layers = sys->getVolumeParticleDepth();for (Particle *p = sys->getFirstParticle(); p; p = p->m_systemNext){- const Real opticalDepth = particleSunMapOpticalDepth( p->getAlpha(), layers );+ const Real opticalDepth = particleSunMapOpticalDepth( p->getAlpha(), layers ) * density;if (opticalDepth <= 0.0f)continue;const Coord3D *pos = p->getPosition();@@ -3942,8 +3954,10 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus )packed.push_back( found[ i ].opticalDepth );}+ Direct3D11_Set_Smoke_Self_Shadow( smokeTuning( TheGlobalData->m_smokeSelfShadowGain, SMOKE_SELF_SHADOW_GAIN ),+ smokeTuning( TheGlobalData->m_smokeSelfShadowCurve, SMOKE_SELF_SHADOW_CURVE ) );const Bool held = Direct3D11_Fill_Smoke_Map( packed.empty() ? NULL : &packed[ 0 ],- (unsigned)found.size(), SMOKE_SHADOW_STRENGTH );+ (unsigned)found.size(), smokeTuning( TheGlobalData->m_smokeGroundShadow, SMOKE_SHADOW_STRENGTH ) );if (!held)return;@@ -3964,8 +3978,12 @@ static void fillSmokeMap( const Matrix3D &sunTransform, const Vector3 &focus ){nextReportFrame = frame + 10 * LOGICFRAMES_PER_SECOND;systemsLastReport = systemsHeld;- DEBUG_LOG(("SMOKEMAP: frame %u, %d casters from %d systems in the sun's map, %d more past its limit\n",- frame, (Int)found.size(), systemsHeld, (Int)( inBox - found.size() )));+ 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",+ 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));}}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex db1d9ce28..419ba7252 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -99,6 +99,31 @@ static const Real FIRE_LIGHT_GAIN = 0.6f; ///< glow a full-strength firestatic const Real PULSE_LIGHT_GAIN = 0.4f; ///< same for an FX light pulse, whose colour is already fullstatic 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. */+struct SmokeFireTuning+{+ Real gain, pulseGain, radius, maxRadius, 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 };++static void refreshSmokeFireTuning( void )+{+ const Real gain = TheGlobalData->m_smokeFireGain >= 0.0f ? TheGlobalData->m_smokeFireGain : FIRE_LIGHT_GAIN;+ const Real radius = TheGlobalData->m_smokeFireRadius >= 0.0f ? TheGlobalData->m_smokeFireRadius : FIRE_LIGHT_RADIUS;+ theSmokeFire.gain = gain;+ theSmokeFire.pulseGain = PULSE_LIGHT_GAIN * gain / FIRE_LIGHT_GAIN;+ theSmokeFire.radius = radius;+ theSmokeFire.maxRadius = FIRE_LIGHT_MAX_RADIUS * radius / FIRE_LIGHT_RADIUS;+ 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. */struct SmokeLight{@@ -156,9 +181,9 @@ static void gatherFireLight( ParticleSystem *sys, SmokeLight *lights, Int &countlight.y = y * inv;light.z = z * inv;const Real variance = sq * inv - (light.x * light.x + light.y * light.y + light.z * light.z);- Real radius = FIRE_LIGHT_RADIUS + FIRE_LIGHT_SPREAD_SCALE * (variance > 0.0f ? sqrtf( variance ) : 0.0f);- if (radius > FIRE_LIGHT_MAX_RADIUS)- radius = FIRE_LIGHT_MAX_RADIUS;+ Real radius = theSmokeFire.radius + FIRE_LIGHT_SPREAD_SCALE * (variance > 0.0f ? sqrtf( variance ) : 0.0f);+ if (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@@ -166,11 +191,11 @@ static void gatherFireLight( ParticleSystem *sys, SmokeLight *lights, Int &countreturn;// the hue from the flames' average colour, the strength from how much of them there is- light.strength = w < FIRE_LIGHT_FULL_WEIGHT ? w / FIRE_LIGHT_FULL_WEIGHT : 1.0f;+ light.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 * FIRE_LIGHT_GAIN / peak;+ const Real scale = light.strength * theSmokeFire.gain / peak;light.r = r * scale;light.g = g * scale;light.b = b * scale;@@ -211,9 +236,9 @@ static void gatherPulseLights( SmokeLight *lights, Int &count, const AABoxClasslight.z = pos.Z;light.radiusSq = farRange * farRange;light.invRadiusSq = 1.0f / light.radiusSq;- light.r = diffuse.X * PULSE_LIGHT_GAIN;- light.g = diffuse.Y * PULSE_LIGHT_GAIN;- light.b = diffuse.Z * PULSE_LIGHT_GAIN;+ light.r = diffuse.X * theSmokeFire.pulseGain;+ light.g = diffuse.Y * theSmokeFire.pulseGain;+ light.b = diffuse.Z * theSmokeFire.pulseGain;light.strength = WWMath::Max( diffuse.X, WWMath::Max( diffuse.Y, diffuse.Z ) );if (light.strength > 0.0f)addSmokeLight( lights, count, light );@@ -297,9 +322,9 @@ static inline void lightSmoke( const Coord3D *pos, const SmokeLight *lights, Intg += f * l.g;b += f * l.b;}- red = WWMath::Min( 1.0f, red + WWMath::Min( r, SMOKE_LIGHT_MAX_GLOW ) );- green = WWMath::Min( 1.0f, green + WWMath::Min( g, SMOKE_LIGHT_MAX_GLOW ) );- blue = WWMath::Min( 1.0f, blue + WWMath::Min( b, SMOKE_LIGHT_MAX_GLOW ) );+ 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 ) );}/** What every job of one frame's billboard fill reads. */@@ -518,6 +543,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)fillJob.extentX = beX;fillJob.extentY = beY;fillJob.extentZ = beZ;+ refreshSmokeFireTuning();fillJob.lightCount = TheGlobalData->m_smokeFireLighting ? gatherSmokeLights( fillJob.lights, bbox ) : 0;JobSystem::parallel_for( (Int)m_billboardFills.size(), BILLBOARD_FILLS_PER_CLAIM, fillBillboards, &fillJob );size_t nextFill = 0;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex f59edc1b2..0ea097c74 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -320,6 +320,8 @@ DX11BackendClass::DX11BackendClass()SmokeMapRefused = false;SmokeMapFilled = false;SmokeStrength = 0.0f;+ SmokeSelfGain = 0.8f;+ SmokeSelfCurve = 2.0f;for (unsigned stage = 0; stage < DX11_BACKEND_TEXTURE_STAGES; ++stage) {set_identity(TextureTransforms[stage]);}@@ -772,8 +774,8 @@ bool DX11BackendClass::Fill_Smoke_Map(const float * casters, unsigned count, floreturn false;}// Nothing to draw is not a reason to make the map; whether it could be made is answered the- // first time there is.- if (casters == NULL || count == 0 || strength <= 0.0f) {+ // first time there is. A ground strength of nought still fills it for the smoke's own shade.+ if (casters == NULL || count == 0 || (strength <= 0.0f && SmokeSelfGain <= 0.0f)) {return !SmokeMapRefused;}if (!Make_Smoke_Map()) {@@ -909,6 +911,15 @@ void DX11BackendClass::Set_Scene_View(const float view[16])}}+void DX11BackendClass::Set_Smoke_Self_Shadow(float gain, float curve)+{+ if (gain != SmokeSelfGain || curve != SmokeSelfCurve) {+ SmokeSelfGain = gain;+ SmokeSelfCurve = curve;+ ConstantsChanged = true;+ }+}+bool DX11BackendClass::Views_Current_Target(unsigned stage, ID3D11ShaderResourceView * texture) const{if (texture == NULL || CurrentTarget == NULL) {@@ -2106,7 +2117,9 @@ void DX11BackendClass::Upload_Constants()}}pixel_block.VolumeParameters[0] = SmokeMapFilled ? SmokeStrength : 0.0f;+ pixel_block.VolumeParameters[1] = SmokeMapFilled ? SmokeSelfGain : 0.0f;pixel_block.VolumeParameters[2] = camera_space ? 1.0f : 0.0f;+ pixel_block.VolumeParameters[3] = SmokeSelfCurve;memcpy(pixel_block.ShadowFromClip, ShadowFromClip, sizeof(pixel_block.ShadowFromClip));pixel_block.ShadowParameters[0] = (ShadowMapSize > 0)? 1.0f / static_cast<float>(ShadowMapSize) : 0.0f;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.hindex ae059d56c..176321abf 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h@@ -203,6 +203,11 @@ public:// frame's camera is back; until the first one, such a draw uses the view it was drawn with.void Set_Scene_View(const float view[16]);+ // How a smoke particle shades itself, apart from what the smoke does to the ground: how dark a+ // particle on its plume's far side goes, and the power the share of the plume in front of it is+ // raised to, which keeps the sun side lit (VOLUMETRIC_SAMPLING, smoke_reaching).+ void Set_Smoke_Self_Shadow(float gain, float curve);+// What is in the map, read back through a staging copy: how much of it was drawn into and how// near the nearest thing is. A caster pass that drew nothing leaves a map that is all one// value, and no draw count tells that apart from a pass that drew the world.@@ -330,7 +335,8 @@ private:float Sky[4];float SkyUp[4];// The smoke in the sun's light (VOLUMETRIC_SAMPLING): how dark the thickest smoke leaves- // what is behind it, zero on a frame without; and in z, one for a draw in camera space.+ // what is behind it, zero on a frame without; the same for a particle shading itself; one+ // for a draw in camera space; and the power on the self-shade.float VolumeParameters[4];};// A model under directional lights, drawn by generated programs.@@ -446,6 +452,8 @@ private:bool SmokeMapRefused;bool SmokeMapFilled;float SmokeStrength;+ float SmokeSelfGain;+ float SmokeSelfCurve;bool Make_Smoke_Map();void Release_Smoke_Map();diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cppindex 6904b6d2f..27c137bfe 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp@@ -327,6 +327,13 @@ bool Direct3D11_Fill_Smoke_Map(const float * casters, unsigned count, float strereturn Active ? Backend.Fill_Smoke_Map(casters, count, strength) : false;}+void Direct3D11_Set_Smoke_Self_Shadow(float gain, float curve)+{+ if (Active) {+ Backend.Set_Smoke_Self_Shadow(gain, curve);+ }+}+void Direct3D11_Set_Scene_View(const float view[16]){if (Active) {diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex 2d9a8ae36..990713fd6 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -152,6 +152,10 @@ bool Direct3D11_Fill_Smoke_Map(const float * casters, unsigned count, float stre// looks its shadow up through it.void Direct3D11_Set_Scene_View(const float view[16]);+// How a smoke particle shades itself: the darkness on its plume's far side and the power on the+// share of the plume in front of it. Set every frame the smoke map is filled.+void Direct3D11_Set_Smoke_Self_Shadow(float gain, float curve);+// The CPU has just written this surface. The next bind of its texture fills the Direct3D 11 copy// again. A no-op when the backend is not running.void Direct3D11_Mark_Surface_Dirty(struct IDirect3DSurface9 * surface);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cppindex c4f4e732c..4c584c86f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp@@ -73,6 +73,7 @@ void Direct3D11_Set_Shadow_Parameters(float, float, float, float, float, float,void Direct3D11_Clear_Shadow_Parameters() {}bool Direct3D11_Fill_Smoke_Map(const float *, unsigned, float) { return false; }void Direct3D11_Set_Scene_View(const float [16]) {}+void Direct3D11_Set_Smoke_Self_Shadow(float, float) {}void Direct3D11_Mark_Surface_Dirty(struct IDirect3DSurface9 *) {}void Direct3D11_Mirror_Render_Target(struct IDirect3DSurface9 *) {}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.hindex 1be1f7f70..497c12fbf 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h@@ -224,7 +224,8 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;// sums.//// VolumeParameters.x is how dark a pixel behind the thickest smoke goes, zero on a frame with no-// smoke in the map. .z is one for a draw whose vertices are in camera space already, which is the+// smoke in the map, and .y the same for a particle shading itself, with .w the power that keeps its+// plume's sun side lit. .z is one for a draw whose vertices are in camera space already, which is the// particles: they take the sun's map through four wide taps, because a smoke sprite drawn twenty// deep would otherwise pay the fifty taps the ground pays, twenty times over.#define VOLUMETRIC_SAMPLING \@@ -246,14 +247,27 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;"float smoke_reaching(float4 position)\n" \"{\n" \" float3 sun;\n" \- " if (VolumeParameters.x <= 0.0 || !sun_point(position, sun)) return 1.0;\n" \+ " bool particle = VolumeParameters.z > 0.5;\n" \+ " float gain = particle ? VolumeParameters.y : VolumeParameters.x;\n" \+ " if (gain <= 0.0 || !sun_point(position, sun)) return 1.0;\n" \" float4 sums = SmokeMap.SampleLevel(SmokeSampler, sun.xy, 0);\n" \" if (sums.x < 0.001) return 1.0;\n" \" float centre = sums.y / sums.x;\n" \" float width = sqrt(max(sums.z / sums.x - centre * centre, 1e-10));\n" \- " // the bell curve's integral up to here, the logistic stand-in for the normal distribution\n" \- " float ahead = 1.0 / (1.0 + exp(-1.702 * (sun.z - centre) / width));\n" \- " return 1.0 - VolumeParameters.x * (1.0 - exp(-sums.x * ahead));\n" \+ " 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" \+ " }\n" \+ " else {\n" \+ " // the bell curve's integral up to here, the logistic stand-in for the normal distribution\n" \+ " ahead = 1.0 / (1.0 + exp(-1.702 * behind));\n" \+ " }\n" \+ " return 1.0 - gain * (1.0 - exp(-sums.x * ahead));\n" \"}\n" \"\n" \"float sun_reaching_coarse(float4 position)\n" \@@ -284,8 +298,11 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;#define VOLUMETRIC_CONSTANTS \" float4 VolumeParameters;\n"-// SHADOW_APPLY with the smoke in it.+// SHADOW_APPLY with the smoke in it. A particle takes the shade whatever its own brightness: the+// threshold is there for ground under the shroud, and on smoke it tied the shade to the colour, so+// the fire's glow, lifting a dark plume over the threshold, made it take more shade and go darker.#define VOLUMETRIC_SHADOW_APPLY SHADOW_LIT \+ " if (VolumeParameters.z > 0.5) shadow_lit = 1.0;\n" \" current.rgb *= lerp(1.0, light_reaching(input.Position), shadow_lit);\n"// The HLSL for one description, or false when the description names an operation or an argument