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.

test(ww3d2): keep the alpha sweep off the driver's half-level tie

Olcay Seygan5342a6e1b63b
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
index 63c6d2404..ab38051bd 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
@@ -168,10 +168,12 @@ static bool operation_expression(DWORD operation, const std::string & argument0,
// Both sides of that subtraction are whole levels. Direct3D 9's alpha test compared the eight bit
// alpha about to be written against an eight bit reference, so the comparison this replaces is an
// integer one, and doing it in floats moves every alpha tested edge in the frame by up to half a
-// level. On a quad whose alpha runs from nothing to full across 64 pixels, tested at reference 128,
-// Direct3D 9 keeps from column 32 and the float comparison kept from 33 - one pixel along every
+// level. On a quad whose alpha runs from nothing to full across 64 pixels, tested at reference 64,
+// Direct3D 9 keeps from column 16 and the float comparison kept from 17 - one pixel along every
// foliage edge there is, and the views that carry the most of them are the ones that were still
-// outside the margin. test_pixelcentre draws exactly that quad on both runtimes.
+// outside the margin. test_pixelcentre draws exactly that quad on both runtimes. An alpha that
+// lands exactly on half a level is rounded whichever way the Direct3D 9 driver likes, so nothing
+// here can match every card there and the test stays off that case.
//
// Rounding to a level first also makes the strict comparisons and the two equalities exact. A
// strict greater is one whole level further along; an equality is a level either side rather than
diff --git a/GeneralsMD/Code/Tests/test_pixelcentre.cpp b/GeneralsMD/Code/Tests/test_pixelcentre.cpp
index e6b1aa746..b299f20f8 100644
--- a/GeneralsMD/Code/Tests/test_pixelcentre.cpp
+++ b/GeneralsMD/Code/Tests/test_pixelcentre.cpp
@@ -109,10 +109,17 @@ static void build_edge_quad(float screen, EdgeVertex quad[4])
// builds carry an alpha test, and all eight are the greater-or-equal one.
static DWORD AlphaTestReference = 128;
-// One knife-edge reference proves the rounding and nothing else. A sweep proves the rule, which
-// matters because what is left of the difference between the two frames sits on thin alpha tested
-// foliage: a palm trunk a pixel wide is exactly where a threshold half a level out shows.
-static const DWORD ALPHA_REFERENCES[] = { 1, 16, 32, 64, 96, 128, 160, 192, 224, 254 };
+// A sweep proves the rule, which matters because what is left of the difference between the two
+// frames sits on thin alpha tested foliage: a palm trunk a pixel wide is exactly where a threshold
+// half a level out shows.
+//
+// Column c of this quad is sampled at alpha c * 255 / 64, and 128 is left out because column 32 lands
+// on 127.5, exactly half a level. Which way an eight bit alpha rounds there is the Direct3D 9
+// driver's choice, not the backend's: the RTX 4060 Ti rounds it down and keeps from column 33, and the
+// same test passed against a driver that rounded it up. A float comparison is still caught at 16,
+// 32, 64 and 96, whose first kept columns sample a little under the reference: 15.94, 31.88, 63.75
+// and 95.63 round up to it and fall short of it as fractions.
+static const DWORD ALPHA_REFERENCES[] = { 1, 16, 32, 64, 96, 160, 192, 224, 254 };
static const unsigned ALPHA_REFERENCE_COUNT =
sizeof(ALPHA_REFERENCES) / sizeof(ALPHA_REFERENCES[0]);