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(ww3d2): atmosphere fade ends where the shroud's border goes black

Olcay Seygan7a63bb15e5cc
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index 449a502de..4d5d61824 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -851,7 +851,10 @@ static const char * const SKY_SHADER_BODY =
// and left the ground in sight a pale disc inside it, on Alpine Assault's far base at the flat tilt.
// The ring past the map (MapSize, the playable map from the world's origin) has no shroud cells and
// draws black, which against a sky stood as a black wall round the world on every map: it goes into the
-// horizon's colour over BORDER_FADE units from the map's edge. Only depth still at the clear is sky, and
+// horizon's colour across the one shroud cell (SHROUD_CELL, the game's PartitionCellSize) over which the
+// shroud's filter itself falls to the border's black, half inside the map's edge and half out. A fade
+// starting at the edge and running on past that left the black showing first, and at a flat tilt 100 units
+// of a cliff past the edge is a black smear a tenth of the frame high. Only depth still at the clear is sky, and
// takes none; ground in the far plane's last sliver read as sky at 0.99999 and stayed unfaded, a hairline
// tracing a ridge whose body had gone. Below the horizon the same empty depth gets the sky's colour again,
// because the sea runs on past the terrain, writes no depth and draws black out there: Bombardment Beach
@@ -864,7 +867,7 @@ static const char * const ATMOSPHERE_SHADER_BODY =
"static const float FOCUS_MARGIN = 1.1;\n"
"static const float FOCUS_MOST = 2000.0;\n"
"static const float FAR_CLOSE = 0.85;\n"
- "static const float BORDER_FADE = 100.0;\n"
+ "static const float SHROUD_CELL = 40.0;\n"
"\n"
"float4 main(VertexOutput input) : SV_TARGET\n"
"{\n"
@@ -884,7 +887,7 @@ static const char * const ATMOSPHERE_SHADER_BODY =
" float lit = lerp(1.0, Shroud.SampleLevel(Sampler, (here - HazeShroudRect.xy) * HazeShroudRect.zw, 0.0).g, HazeSun.z);\n"
" float2 outside = max(-here, here - MapSize.xy);\n"
" float closing = max(smoothstep(FAR_CLOSE, 1.0, dot(ray, axis) / (axisLength * axisLength)),\n"
- " smoothstep(0.0, BORDER_FADE, max(outside.x, outside.y)));\n"
+ " smoothstep(-0.5 * SHROUD_CELL, 0.5 * SHROUD_CELL, max(outside.x, outside.y)));\n"
" return float4(haze_along(ray.z / max(reach, 0.0001)) * lerp(lit, 1.0, closing), max(amount, closing));\n"
"}\n";
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index 4b430913e..25e857c64 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -803,7 +803,8 @@ TEST(dx11post_the_ground_haze_lies_over_a_scene_under_its_top)
// a unit from the eye, a third of the way into a fade of scale one, and takes the white horizon. With
// depth at the far plane and the eye looking up the fade leaves the frame alone: it is sky by then.
// Looking down, the same empty depth takes the horizon, over the sea that draws past the terrain. The sky
-// itself reads no depth and covers everything, a null texture here, so it goes black.
+// itself reads no depth and covers everything, a null texture here, so it goes black. Half a shroud cell
+// past the map's edge the shroud's border is black, so the ground there is the horizon however near it is.
TEST(dx11post_the_atmosphere_fades_the_far_ground_and_the_sky_fills_the_frame)
{
DeviceFixture fixture;
@@ -819,8 +820,9 @@ TEST(dx11post_the_atmosphere_fades_the_far_ground_and_the_sky_fills_the_frame)
const float identity[16] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
// The eye at height nought looks down its depth, its focus on the ground right there, so no start.
+ // It stands 500 units into the map, or the map's corner closes the fade over the frame's centre.
const float looking_down[16] = {
- 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
+ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 500.0f, 500.0f, 0.0f, 1.0f };
DX11Post_Set_Atmosphere(white, white, 0.0f, 1.0f, 1.0f, 0.0f, 1.0e6f, 1.0e6f, NULL);
unsigned char picture[SURFACE_SIZE * SURFACE_SIZE * BYTES_A_PIXEL];
@@ -829,9 +831,13 @@ TEST(dx11post_the_atmosphere_fades_the_far_ground_and_the_sky_fills_the_frame)
post.Set_Chain(copy_only, 1);
post.Compile_Atmosphere_Programs();
- const float DEPTHS[4] = { 0.5f, 1.0f, 0.5f, 1.0f };
- unsigned char levels[4] = { 0, 0, 0, 0 };
- for (unsigned run = 0; run < 4; ++run) {
+ const float DEPTHS[5] = { 0.5f, 1.0f, 0.5f, 1.0f, 0.5f };
+ unsigned char levels[5] = { 0, 0, 0, 0, 0 };
+ for (unsigned run = 0; run < 5; ++run) {
+ if (run == 4) {
+ // A fade too long to count, and a map whose edge lies 25 units short of the eye.
+ DX11Post_Set_Atmosphere(white, white, 0.0f, 1.0e6f, 1.0f, 0.0f, 475.0f, 475.0f, NULL);
+ }
post.Open_Frame();
post.Begin_Frame();
device.Set_Scene_View(post.Scene_View());
@@ -854,9 +860,12 @@ TEST(dx11post_the_atmosphere_fades_the_far_ground_and_the_sky_fills_the_frame)
DX11Post_Set_Atmosphere(white, white, 0.0f, 1.0f, 0.0f, 0.0f, 1.0e6f, 1.0e6f, NULL);
CHECK(levels[0] >= DARK_LEVEL + LIFTED_BY_AT_LEAST);
+ CHECK(levels[0] < 70);
CHECK(levels[1] == DARK_LEVEL);
CHECK(levels[2] == 0);
CHECK(levels[3] >= DARK_LEVEL + LIFTED_BY_AT_LEAST);
+ // All of the horizon's colour, dimmed below the horizon by BELOW_DIM, 0.55 of white.
+ CHECK(levels[4] >= 130);
// Strength zero is no pass at all.
post.Open_Frame();