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(ww3d2): draw the campaign briefing grey under direct3d 11
Olcay Seygan78f1d8704779
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04dd89f65..ea4538a64 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -507,6 +507,7 @@ found and fixed — EA's own, not port damage.**- Embers and sparks that trail an effect finish their run. When the effect that owned them ended first, they lost track of where it was, were drawn at the corner of the map and died early.- Heat haze wobbles in both directions. The vertical part of the distortion was rolled, clipped against the top and bottom of the screen, and then never used - every shimmer pulled the picture along one diagonal.- The Microwave Tank's heat haze no longer wears a black cloud. The shimmer bends a copy of the picture behind it, and on the new renderer it read that copy while the picture was still being painted into it, which the graphics card answers with nothing at all: a dark blot, fading out towards its edges. It now reads the picture as it stood the moment before the shimmer was drawn.+- Campaign briefings go grey again instead of black. The first American mission opens on Baikonur and the train depot in black and white, with the briefing lettered over the top; on the new renderer the grey step was the one draw it had no version of, so the picture went away to be greyed and never came back, and only the lettering was left on a black screen. The grey is drawn there now, and the fade into it and out of it with it.- One tree in ten stood dead still in the breeze. The number that picks which way a tree sways was drawn from a range one short at the bottom, and the bottom of that range is the slot meaning "no sway at all".- Police car lights flash at their own speed instead of your monitor's. On a fast screen with the frame cap off they were cycling five and a half times too quickly.- Ten more places that wrote terrain, roads, bridges, trees, foundations and scorch marks into a buffer the graphics card had refused to hand over. Every one of them wrote to address zero instead, and a graphics device pulled out from under the game is all it takes; the frame is simply skipped now.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cppindex 757f8076f..c2c6d4228 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp@@ -672,6 +672,9 @@ Int ScreenBWFilter::set(enum FilterModes mode)DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(1, color, 1);DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(2, D3DXVECTOR4(m_curFadeValue, m_curFadeValue, m_curFadeValue, 1.0f), 1);+ //the Direct3D 11 transcription of monochrome.pso never sees c1 and c2, so it reads the+ //tint from the texture factor's colour and the fade from its alpha+ DX8Wrapper::Set_DX8_Render_State(D3DRS_TEXTUREFACTOR, DX8Wrapper::Convert_Color(Vector4(color.x, color.y, color.z, m_curFadeValue)));/* DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(2, D3DXVECTOR4(150.0f/255.0f, 150.0f/255.0f, 150.0f/255.0f, 0.0f), 1);DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(3, D3DXVECTOR4((765.0f/450.0f)/3, (765.0f/450.0f)/3, (765.0f/450.0f)/3, 1.0f), 1);DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(4, D3DXVECTOR4(0.5f, 0.5f, 0.5f, 0), 1);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cppindex 7bb159ea5..8819df26f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.cpp@@ -83,7 +83,8 @@ static const EngineShaderEntry ENGINE_SHADERS[] = {{ ENGINE_SHADER_FLAT_TERRAIN_NOISE_2, "fterrainnoise2.pso", "engine:flatterrainnoise2",FLAT_TERRAIN_OPENING, TERRAIN_NOISE_2_CHAIN },{ ENGINE_SHADER_ROAD_NOISE_2, "roadnoise2.pso", "engine:roadnoise2",- ROAD_NOISE_2_OPENING, ROAD_NOISE_2_CHAIN }+ ROAD_NOISE_2_OPENING, ROAD_NOISE_2_CHAIN },+ { ENGINE_SHADER_MONOCHROME, "monochrome.pso", "engine:monochrome", NULL, NULL }};static const unsigned ENGINE_SHADER_COUNT = sizeof(ENGINE_SHADERS) / sizeof(ENGINE_SHADERS[0]);@@ -309,6 +310,27 @@ static void write_water_reflection(std::string & hlsl)" float4 current = float4((1.0 - TextureFactor.a * coverage).xxx, TextureFactor.a);\n";}+/*+** The grey the campaign briefings and some cutscenes lay over the whole view, ScreenBWFilter's:+**+** tex t0 ; the frame, rendered into a texture first+** dp3 r1, t0, c0 ; c0 is (0.3, 0.59, 0.11), the luminance+** mul r1, r1, c1 ; c1 tints it: white, red or green, alpha one+** lrp r0, c2, r1, t0 ; c2 is the fade, the same value in all four+**+** D3D9 reads the tint and the fade out of c1 and c2. Here they ride in the texture factor, tint in+** the colour and fade in the alpha, which ScreenBWFilter sets beside the constants. c2.w is one+** whatever the fade, so the alpha comes out as the luminance at every step of it.+*/+static void write_monochrome(std::string & hlsl)+{+ write_pixel_preamble(hlsl);+ hlsl +=+ " float luminance = saturate(dot(texel0.rgb, float3(0.3, 0.59, 0.11)));\n"+ " float4 tinted = saturate(luminance * float4(TextureFactor.rgb, 1.0));\n"+ " float4 current = lerp(texel0, tinted, float4(TextureFactor.aaa, 1.0));\n";+}+// Every ps_1_1 instruction clamps its result to zero and one, so each step saturates and not only// the last: a chain that overflows in the middle and comes back down is a different colour with the// clamps than without them.@@ -391,6 +413,9 @@ bool EngineShader_Pixel_Program(EngineShaderProgram program,else if (program == ENGINE_SHADER_WATER_REFLECTION) {write_water_reflection(hlsl);}+ else if (program == ENGINE_SHADER_MONOCHROME) {+ write_monochrome(hlsl);+ }else {return false;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.hindex 6e73bc83b..08aed41cb 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.h@@ -67,7 +67,8 @@ enum EngineShaderProgramENGINE_SHADER_FLAT_TERRAIN_BASE,ENGINE_SHADER_FLAT_TERRAIN_NOISE,ENGINE_SHADER_FLAT_TERRAIN_NOISE_2,- ENGINE_SHADER_ROAD_NOISE_2+ ENGINE_SHADER_ROAD_NOISE_2,+ ENGINE_SHADER_MONOCHROME};// The name the engine loaded the shader under: a path for the ones that ship as filesdiff --git a/GeneralsMD/Code/Tests/test_engineshader.cpp b/GeneralsMD/Code/Tests/test_engineshader.cppindex a458c3c50..34d8b2286 100644--- a/GeneralsMD/Code/Tests/test_engineshader.cpp+++ b/GeneralsMD/Code/Tests/test_engineshader.cpp@@ -68,6 +68,7 @@ TEST(engineshader_names_a_shader_by_its_file_whatever_case_the_path_is_in)CHECK(EngineShader_From_File("shaders\\terrainnoise2.pso") == ENGINE_SHADER_TERRAIN_NOISE_2);CHECK(EngineShader_From_File("shaders\\fterrain0.pso") == ENGINE_SHADER_FLAT_TERRAIN_BASE);CHECK(EngineShader_From_File("shaders\\roadnoise2.pso") == ENGINE_SHADER_ROAD_NOISE_2);+ CHECK(EngineShader_From_File("shaders\\monochrome.pso") == ENGINE_SHADER_MONOCHROME);}// Every program the table names has to write something, or a draw that binds it is refused with a@@ -79,7 +80,7 @@ TEST(engineshader_writes_every_program_it_names)ENGINE_SHADER_TERRAIN, ENGINE_SHADER_TERRAIN_NOISE, ENGINE_SHADER_TERRAIN_NOISE_2,ENGINE_SHADER_FLAT_TERRAIN, ENGINE_SHADER_FLAT_TERRAIN_BASE,ENGINE_SHADER_FLAT_TERRAIN_NOISE, ENGINE_SHADER_FLAT_TERRAIN_NOISE_2,- ENGINE_SHADER_ROAD_NOISE_2+ ENGINE_SHADER_ROAD_NOISE_2, ENGINE_SHADER_MONOCHROME};for (unsigned index = 0; index < sizeof(PIXEL_PROGRAMS) / sizeof(PIXEL_PROGRAMS[0]); ++index) {@@ -94,7 +95,6 @@ TEST(engineshader_writes_every_program_it_names)TEST(engineshader_has_no_program_for_a_shader_nobody_transcribed){CHECK(EngineShader_From_File("shaders\\wave.vso") == ENGINE_SHADER_NONE);- CHECK(EngineShader_From_File("shaders\\monochrome.pso") == ENGINE_SHADER_NONE);CHECK(EngineShader_From_File("environment water ps.1.1") == ENGINE_SHADER_NONE);CHECK(EngineShader_From_File("Treesomething.vso") == ENGINE_SHADER_NONE);CHECK(EngineShader_From_File(NULL) == ENGINE_SHADER_NONE);@@ -150,6 +150,17 @@ TEST(engineshader_fades_the_water_reflection_towards_white_by_the_texture_factorCHECK(!contains(hlsl, "* texel3"));}+// dp3 r1, t0, c0 ; mul r1, r1, c1 ; lrp r0, c2, r1, t0. Without it the briefing grey was a refused+// draw over a frame that went into a texture and never came out, which is a black screen.+TEST(engineshader_greys_the_frame_by_the_texture_factors_tint_and_fade)+{+ std::string hlsl;+ CHECK(EngineShader_Pixel_Program(ENGINE_SHADER_MONOCHROME, plain_pipeline(), hlsl));+ CHECK(contains(hlsl, "float luminance = saturate(dot(texel0.rgb, float3(0.3, 0.59, 0.11)));"));+ CHECK(contains(hlsl, "float4 tinted = saturate(luminance * float4(TextureFactor.rgb, 1.0));"));+ CHECK(contains(hlsl, "float4 current = lerp(texel0, tinted, float4(TextureFactor.aaa, 1.0));"));+}+// D3D9 applies the alpha test and the fog around a bound pixel shader and D3D11 applies neither, so// a transcription that leaves them out draws water through the fog at full strength.TEST(engineshader_writes_the_alpha_test_and_the_fog_into_a_water_program)@@ -365,4 +376,8 @@ TEST(engineshader_writes_programs_the_compiler_accepts)CHECK(EngineShader_Pixel_Program(ENGINE_SHADER_WATER_REFLECTION, pipeline, reflection));CHECK(compiles(compile, reflection, EngineShader_Name(ENGINE_SHADER_WATER_REFLECTION),PIXEL_PROFILE));++ std::string monochrome;+ CHECK(EngineShader_Pixel_Program(ENGINE_SHADER_MONOCHROME, pipeline, monochrome));+ CHECK(compiles(compile, monochrome, EngineShader_Name(ENGINE_SHADER_MONOCHROME), PIXEL_PROFILE));}