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.

fix(w3ddevice): keep the scene stand-in to heat haze, blur needs its frame

Olcay Seyganbf4a7f6ecc9e
diff --git a/GeneralsMD/Code/Data/Cinema/filterblur.txt b/GeneralsMD/Code/Data/Cinema/filterblur.txt
new file mode 100644
index 000000000..1da483f4b
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/filterblur.txt
@@ -0,0 +1,8 @@
+# A map script's motion blur zoom over the Glow option's fight, for checking that the screen
+# filters still draw on Direct3D 11. Use with -scenario glowfight, -freecam 3150 3660 420 45 -40 and
+# -screenshot 172. The list's clock starts about eleven frames into the match, so the blur starts
+# near frame 161; it builds for twelve logic frames and ends by itself, and frame 172 is near its
+# peak.
+
+0 hud off
+4.9 filter blur
diff --git a/GeneralsMD/Code/Data/Cinema/filterbw.txt b/GeneralsMD/Code/Data/Cinema/filterbw.txt
new file mode 100644
index 000000000..3366cadea
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/filterbw.txt
@@ -0,0 +1,6 @@
+# A map script's black and white view over the Glow option's fight, for checking that the screen
+# filters still draw on Direct3D 11. Use with -scenario glowfight, -freecam 3150 3660 420 45 -40 and
+# -screenshot 172; the view goes black and white at 4 seconds on the list's clock, near frame 131.
+
+0 hud off
+4 filter bw
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h
index 11861a9e6..05d15d93a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CinemaDirector.h
@@ -41,6 +41,7 @@ enum CinemaVerb
CINEMA_VERB_UNFOLLOW, ///< unfollow: stop following, stay where the camera is
CINEMA_VERB_HUD, ///< hud on|off
CINEMA_VERB_LETTERBOX, ///< letterbox on|off
+ CINEMA_VERB_FILTER, ///< filter bw|blur|off: a map script's black and white view or motion blur zoom
CINEMA_VERB_SHOT, ///< shot: one screenshot
CINEMA_VERB_END, ///< end: quit the game
@@ -59,7 +60,7 @@ struct CinemaShot
Real routeX[ CINEMA_MAX_ROUTE_POINTS ];
Real routeY[ CINEMA_MAX_ROUTE_POINTS ];
Int routePoints;
- AsciiString name; ///< follow's template
+ AsciiString name; ///< follow's template, filter's bw, blur or off
Bool on; ///< hud and letterbox
};
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
index 89a03b2a6..60b7d3919 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/CinemaDirector.cpp
@@ -44,6 +44,7 @@
#include "Common/Recorder.h"
#include "Common/ThingTemplate.h"
#include "GameClient/CinemaDirector.h"
+#include "GameClient/CommandXlat.h"
#include "Common/NameKeyGenerator.h"
#include "GameClient/Display.h"
#include "GameClient/GameWindow.h"
@@ -262,6 +263,13 @@ Bool CinemaDirector_parseLine( const char *line, CinemaShot *shot, Bool *isShot,
if (args != 1 || !parseCinemaSwitch( tokens[ 2 ], &shot->on ))
return refuseCinemaLine( reason, "hud and letterbox take on or off" );
}
+ else if (verb == "filter")
+ {
+ shot->verb = CINEMA_VERB_FILTER;
+ if (args != 1 || (tokens[ 2 ] != "bw" && tokens[ 2 ] != "blur" && tokens[ 2 ] != "off"))
+ return refuseCinemaLine( reason, "filter takes bw, blur or off" );
+ shot->name = tokens[ 2 ];
+ }
else
{
return refuseCinemaLine( reason, "unknown verb" );
@@ -708,6 +716,27 @@ static void runShot( const CinemaShot &shot )
theCinemaLetterbox = shot.on;
break;
+ // what ScriptActions::doBlackWhiteMode and doCameraMotionBlur set, with no fade
+ case CINEMA_VERB_FILTER:
+ if (shot.name == "bw")
+ {
+ TheTacticalView->setViewFilterMode( FM_VIEW_BW_BLACK_AND_WHITE );
+ TheTacticalView->setViewFilter( FT_VIEW_BW_FILTER );
+ TheTacticalView->setFadeParameters( 0, 1 );
+ }
+ else if (shot.name == "blur")
+ {
+ if (TheTacticalView->setViewFilter( FT_VIEW_MOTION_BLUR_FILTER )
+ && !TheTacticalView->setViewFilterMode( FM_VIEW_MB_IN_ALPHA ))
+ TheTacticalView->setViewFilter( FT_NULL_FILTER );
+ }
+ else
+ {
+ TheTacticalView->setViewFilterMode( FM_NULL_MODE );
+ TheTacticalView->setViewFilter( FT_NULL_FILTER );
+ }
+ break;
+
case CINEMA_VERB_SHOT:
{
Coord3D pos;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
index 6948361b3..3507a8fbf 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
@@ -117,7 +117,11 @@ public:
// Support routines for filter methods.
static Bool canRenderToTexture(void) { return (m_oldRenderSurface && m_newRenderSurface);}
- static void startRenderToTexture(void); ///< Sets render target to texture.
+ /// Sets render target to texture. sceneStandIn: the texture is only sampled while the scene goes
+ /// into it (heat haze) and never shown afterwards, so Direct3D 11 may keep the scene in its own
+ /// float target (Direct3D11_Set_Scene_Stand_In). A filter that shows the texture on a later
+ /// frame (motion blur, cross fade) needs the real copy and passes FALSE.
+ static void startRenderToTexture(Bool sceneStandIn = FALSE);
static IDirect3DTexture9 * endRenderToTexture(void); ///< Ends render to texture, & returns texture.
static IDirect3DTexture9 * getRenderTexture(void); ///< returns last used render target texture
static Bool isRenderingToTexture(void) {return m_renderingToTexture; }
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index ba5428d43..3d88ca291 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -457,7 +457,7 @@ Bool ScreenDefaultFilter::preRender(Bool &skipRender, CustomScenePassModes &scen
{ if (((W3DSmudgeManager *)TheSmudgeManager)->getSmudgeCountLastFrame() == 0)
return FALSE;
}
- W3DShaderManager::startRenderToTexture();
+ W3DShaderManager::startRenderToTexture(TRUE); //the smudges only sample it, mid-scene
return true;
}
@@ -2935,10 +2935,6 @@ void W3DShaderManager::init(void)
}
}
}
- // Direct3D 11 keeps the scene in its own float target while this texture is the target, so the
- // smudges' redirect does not clip the Glow option's fires at white.
- Direct3D11_Set_Scene_Stand_In(m_renderTexture, m_newRenderSurface);
-
W3DShaderInterface **shaders;
for (i=0; MasterShaderList[i] != NULL; i++)
@@ -3141,8 +3137,8 @@ void W3DShaderManager::drawViewport(Int color)
/** Starts rendering to a texture.
*/
//=============================================================================
-void W3DShaderManager::startRenderToTexture(void)
-{
+void W3DShaderManager::startRenderToTexture(Bool sceneStandIn)
+{
DEBUG_ASSERTCRASH(!m_renderingToTexture, ("Already rendering to texture - cannot nest calls."));
if (m_renderingToTexture || m_newRenderSurface==NULL || m_oldDepthSurface==NULL)
@@ -3159,6 +3155,8 @@ void W3DShaderManager::startRenderToTexture(void)
//texture. Ask the wrapper for a matching one (NULL = not multisampling, nothing to do).
IDirect3DSurface9 *depthSurface = DX8Wrapper::_Get_Non_MultiSampled_Depth_Buffer();
if (depthSurface == NULL) depthSurface = m_oldDepthSurface;
+ if (sceneStandIn)
+ Direct3D11_Set_Scene_Stand_In(m_renderTexture, m_newRenderSurface);
DX8Wrapper::_Set_DX8_Render_Target(m_newRenderSurface,depthSurface);
RenderResult hr = D3D_OK;
DEBUG_ASSERTCRASH(hr==D3D_OK, ("Set target failed unexpectedly."));
@@ -3218,6 +3216,7 @@ IDirect3DTexture9 *W3DShaderManager::endRenderToTexture(void)
return NULL;
}
DX8Wrapper::_Set_DX8_Render_Target(m_oldRenderSurface,m_oldDepthSurface); //restore original render target
+ Direct3D11_Set_Scene_Stand_In(NULL, NULL);
RenderResult hr = D3D_OK;
DEBUG_ASSERTCRASH(hr==D3D_OK, ("Set target failed unexpectedly."));
if (hr != D3D_OK)
diff --git a/GeneralsMD/Code/Tests/test_cinema.inc b/GeneralsMD/Code/Tests/test_cinema.inc
index 6f5540e68..e0b9706f0 100644
--- a/GeneralsMD/Code/Tests/test_cinema.inc
+++ b/GeneralsMD/Code/Tests/test_cinema.inc
@@ -48,6 +48,10 @@ TEST(cinema_parses_a_route_follow_and_switches)
CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_HUD );
CHECK( shot.on );
+ CHECK( CinemaDirector_parseLine( "4 filter blur", &shot, &isShot, &reason ) );
+ CHECK_EQ( (Int)shot.verb, (Int)CINEMA_VERB_FILTER );
+ CHECK_STR( shot.name.str(), "blur" );
+
CHECK( CinemaDirector_parseLine( " # only a comment", &shot, &isShot, &reason ) );
CHECK( !isShot );
}
@@ -66,6 +70,7 @@ TEST(cinema_refuses_what_it_cannot_read)
CHECK( !CinemaDirector_parseLine( "3 pitch 50 2", &shot, &isShot, &reason ) );
CHECK( !CinemaDirector_parseLine( "3 route 5 100", &shot, &isShot, &reason ) );
CHECK( !CinemaDirector_parseLine( "3 hud maybe", &shot, &isShot, &reason ) );
+ CHECK( !CinemaDirector_parseLine( "3 filter sepia", &shot, &isShot, &reason ) );
CHECK( !CinemaDirector_parseLine( "3 dolly 1 2", &shot, &isShot, &reason ) );
CHECK( !CinemaDirector_parseLine( "-1 shot", &shot, &isShot, &reason ) );
}