Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(w3ddevice): drive the D3D11 bloom from the Bloom option

Olcay Seygan6d4d65f4eb6f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b74302460..11cfd32e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1255,7 +1255,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
water covers, and only every other frame while the camera holds still. On one 1280x720 view of
Golden Oasis, where the river fills the screen, a frame takes 6.7ms against 5.8ms with no
reflection; before that work it took 8.3ms.
-- Bright things can bleed light into the air. Off by default, because the artwork was painted in 2003 for a screen that had no glow at all.
+- Bright things can bleed light into the air. The glow setting works on the new renderer now: it used to glow at one fixed strength there whatever the box said, and Off did not turn it off. On top of that, picking any level stacked the old renderer's glow over the new one, so the battlefield got two hazes at once. Now there is one, it follows the box the moment you change it, and a fresh install starts on Medium, which is the look the new renderer always had.
- Two dropdowns on the display page, not two percentages. Glow is off, subtle, normal or strong; what glows is only the brightest, bright things, or most of the picture. The numbers underneath were a strength you had to find by experiment and a brightness that ran backwards, where turning it down put more of the screen in the haze, and nothing on screen told you that.
- Scorch marks follow the texture quality setting like everything else. The terrain and the trees
dropped to the resolution you asked for and the burn marks did not, so on Low the ground went soft
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 5e1fca97e..30358b9eb 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1189,13 +1189,13 @@ GlobalData::GlobalData()
m_detailedBuildTooltips = TRUE;
m_archiveReplays = TRUE;
- // Bloom is the one that does NOT default on: it changes how the game looks rather than what it
- // can do, and the artwork was painted in 2003 for a screen with no glow at all. Both fields are
- // percentages and GameData.ini sets them as such - the strength, and the brightness below which
- // nothing glows. The options screen offers levels instead and stores one of those in
- // Options.ini; OptionsCatalog.cpp holds the percentage each level stands for, and 0 and 65 here
- // are two of them.
- m_bloomIntensity = 0;
+ // Bloom defaults to the options screen's Medium: 60 percent, which the Direct3D 11 post chain
+ // turns into the 1.5 strength it used to apply unconditionally. Both fields are percentages and
+ // GameData.ini sets them as such - the strength, and the brightness below which nothing glows.
+ // The options screen offers levels instead and stores one of those in Options.ini;
+ // OptionsCatalog.cpp holds the percentage each level stands for, and 60 and 65 here are two of
+ // them.
+ m_bloomIntensity = 60;
m_bloomThreshold = 65;
m_animateWindows = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 80550a656..37a9bb37f 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -339,9 +339,9 @@ const OptionDef TheOptionCatalog[] =
// constructor, so there is nothing left to load or save. Gameplay is health bars and nothing
// else.
- // Off, subtle, normal, strong. Off is the default, which is what GameData.ini says: the game's
- // artwork has no HDR range in it, so how much glow looks right is a matter of taste rather than
- // something to pick on the player's behalf. The key is "Bloom", not "BloomLevel" - it predates
+ // Off, subtle, normal, strong. Normal (60, the menu's Medium) is the default, set in
+ // GlobalData's constructor: it is the strength the Direct3D 11 frame applied before there was a
+ // setting at all, so a fresh install looks the way it did. The key is "Bloom", not "BloomLevel" - it predates
// the levels and an Options.ini in the wild already spells it this way.
{ "Bloom", OPT_WND( "ComboBoxBloom" ), "GUI:Bloom",
OPTION_ENUM, APPLY_LIVE, 0, BLOOM_LEVEL_COUNT - 1,
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index a67ba71ba..c2d5b60ed 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -75,6 +75,10 @@
#include "Common/GlobalData.h"
#include "Common/GameLOD.h"
#include "d3dx9runtime.h"
+#include "WW3D2/dx11runtime.h"
+#if defined(_WIN32)
+#include "dx11post.h" //DX11Post_Set_Bloom; the library is not built off Windows
+#endif
#include "d3d8shadertranslate.h"
#include "dx8caps.h"
#include "Common/GameLOD.h"
@@ -189,9 +193,9 @@ W3DFilterInterface *ScreenDefaultFilterList[]=
};
/*========= Bloom =============================================================*/
-/// Retail had no bloom and every texture in the game is LDR, so this is opt-in and tunable
-/// rather than a fixed look: m_bloomIntensity is the strength in percent (0, off, which is the
-/// default) and m_bloomThreshold the brightness, in percent, below which nothing glows. The
+/// Retail had no bloom and every texture in the game is LDR, so this is tunable rather than a
+/// fixed look: m_bloomIntensity is the strength in percent (0 is off, 60 the default) and
+/// m_bloomThreshold the brightness, in percent, below which nothing glows. The
/// options screen sets both from one of a handful of named levels; nothing here knows that.
/// It rides on ScreenDefaultFilter, which already renders the scene into a full-screen texture
/// on the frames the smudge effects need one, so the only new work is a quarter-size bright
@@ -205,7 +209,7 @@ static IDirect3DTexture9 *s_bloomTexture[2]; ///< ping-pong render targets for t
static IDirect3DSurface9 *s_bloomSurface[2];
static Int s_bloomWidth, s_bloomHeight;
-/** Bloom strength in percent - Options.ini's "Bloom" - 0 when it was never set. Read every
+/** Bloom strength in percent - Options.ini's "Bloom" - 60 when it was never set. Read every
frame rather than cached, so editing the key and reloading the options takes effect. */
static Int bloomIntensity(void)
{
@@ -226,6 +230,26 @@ static Int bloomThreshold(void)
return threshold;
}
+/** The fixed-function bloom's strength, which is zero on Direct3D 11: there the post chain's own
+ bloom in dx11post.cpp follows the option instead, and running this one too would stack two
+ glows. Everywhere else it is the option. */
+static Int fixedFunctionBloomIntensity(void)
+{
+ if (Direct3D11_Is_Active())
+ {
+#if defined(_WIN32)
+ //The option in the post chain's units, where 1.0 is white. The chain was tuned at a
+ //threshold of 1.0 and an intensity of 1.5, so the default threshold (65%) lands on 1.0 and
+ //the middle level (60%) on 1.5; 35% and 85% fall either side, 45% and 85% thresholds at
+ //0.69 and 1.31. Pushed every frame, so a change on the options screen shows at once.
+ const Int percent = TheGlobalData != NULL ? TheGlobalData->m_bloomThreshold : 65;
+ DX11Post_Set_Bloom((Real)percent / 65.0f, (Real)bloomIntensity() * 0.025f);
+#endif
+ return 0;
+ }
+ return bloomIntensity();
+}
+
static void releaseBloomTargets(void)
{
for (Int i = 0; i < 2; i++)
@@ -389,7 +413,9 @@ Bool ScreenDefaultFilter::preRender(Bool &skipRender, CustomScenePassModes &scen
{
//Right now this filter is only used for smudges, so don't bother if none are present -
//unless bloom is on, which needs the scene in a texture on every frame.
- if (TheSmudgeManager && bloomIntensity() == 0)
+ //Called before the smudge check so the Direct3D 11 chain gets the option every frame.
+ const Int fixedBloom = fixedFunctionBloomIntensity();
+ if (TheSmudgeManager && fixedBloom == 0)
{ if (((W3DSmudgeManager *)TheSmudgeManager)->getSmudgeCountLastFrame() == 0)
return FALSE;
}
@@ -443,7 +469,7 @@ Bool ScreenDefaultFilter::postRender(enum FilterModes mode, Coord2D &scrollDelta
DX8Wrapper::_Draw_DX8_Primitive_UP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(_TRANS_LIT_TEX_VERTEX));
//v[3] is the top left corner of the viewport inside the scene texture, v[0] the bottom right
- if (bloomIntensity() > 0)
+ if (fixedFunctionBloomIntensity() > 0)
renderBloom(tex, (Real)xpos, (Real)ypos, (Real)width, (Real)height,
v[3].u, v[3].v, v[0].u, v[0].v);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index e310c7ff5..39cc9ce49 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -71,10 +71,21 @@ static const unsigned BLOOM_BLUR_PASSES = 2;
//
// An intensity of 1.5 against a quiet frame with nothing burning costs half a level a channel,
// which is the cost of having this on when there is nothing for it to do.
+//
+// Those two are the defaults. The game replaces them every frame from its Bloom option.
static const float BLOOM_THRESHOLD = 1.0f;
static const float BLOOM_INTENSITY = 1.5f;
static const float TONE_CURVE_KNEE = 0.8f;
+static float BloomThreshold = BLOOM_THRESHOLD;
+static float BloomIntensity = BLOOM_INTENSITY;
+
+void DX11Post_Set_Bloom(float threshold, float intensity)
+{
+ BloomThreshold = (threshold > 0.0f) ? threshold : 0.0f;
+ BloomIntensity = (intensity > 0.0f) ? intensity : 0.0f;
+}
+
// How dark a fully occluded pixel goes, how far a neighbour may be in front before it counts as a
// different object rather than a corner, and how wide the ring reaches at one unit of depth. The
// clip planes come from the frame itself.
@@ -782,8 +793,8 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
block.BlurDirection[1] = pass.BlurY;
block.BlurDirection[2] = 0.0f;
block.BlurDirection[3] = 0.0f;
- block.Tuning[0] = BLOOM_THRESHOLD;
- block.Tuning[1] = BLOOM_INTENSITY;
+ block.Tuning[0] = BloomThreshold;
+ block.Tuning[1] = BloomIntensity;
block.Tuning[2] = TONE_CURVE_KNEE;
block.Tuning[3] = 0.0f;
if (pass.Occlusion) {
@@ -898,7 +909,25 @@ bool DX11PostProcessClass::Finish(const DX11PostEffect * effects, unsigned count
// Bloom is the only effect that reads the half float scene, and the frame is eight bits by
// the time it hands over. If it is also the last thing in the chain it writes the screen.
const bool alone = (count == 1);
- source = Run_Bloom(alone ? back_buffer : ChainTargets[0].View);
+ ID3D11RenderTargetView * bloom_destination = alone ? back_buffer : ChainTargets[0].View;
+ if (BloomIntensity > 0.0f) {
+ source = Run_Bloom(bloom_destination);
+ } else {
+ // Bloom switched off in the options: no glow, but the scene is still half floats and
+ // still has to come down to eight bits, the same way Copy_Through brings it down. The
+ // chain keeps its shape so turning it back on costs no rebuild of the targets.
+ PassSetup tone;
+ memset(&tone, 0, sizeof(tone));
+ tone.Shader = ToneMapShader;
+ tone.Source = SceneTarget.Resource;
+ tone.Destination = bloom_destination;
+ tone.DestinationWidth = Width;
+ tone.DestinationHeight = Height;
+ tone.SourceWidth = Width;
+ tone.SourceHeight = Height;
+ Draw_Pass(tone);
+ source = ChainTargets[0].Resource;
+ }
if (alone) {
Resolved = true;
return true;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 71a181da6..2ba1c2619 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -101,6 +101,13 @@ bool DX11Post_Parse_Chain(const char * text, DX11PostEffect effects[DX11_POST_CH
// The name a parsed effect goes back to, for the report line.
const char * DX11Post_Effect_Name(DX11PostEffect effect);
+// Bloom's threshold and strength in the scene's own units, where one is white. The game's Bloom
+// option sets them every frame through W3DShaderManager, since nothing in this library may read
+// GlobalData. An intensity of zero skips the bright pass and the blur and leaves only the tone
+// curve, so the half float scene still reaches eight bits. Until somebody calls this the chain
+// runs at the values it was tuned at, which is what the tests measure.
+void DX11Post_Set_Bloom(float threshold, float intensity);
+
class DX11PostProcessClass
{
public:
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 9a543d256..1fd376793 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -12692,6 +12692,7 @@ TEST(bloom_levels_carry_the_percentages_the_shader_reads)
// what GlobalData's constructor put there, before anything below scribbles on it
const Int shippedIntensity = TheGlobalData->m_bloomIntensity;
const Int shippedThreshold = TheGlobalData->m_bloomThreshold;
+ CHECK_EQ( bloom->get(), 2 ); // a fresh install starts on Medium, not Off
// off is off, and nothing else is: a level that mapped to 0 would be a silent second Off entry
bloom->set( 0 );