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): corners and the ground under units darken, as an option

Olcay Seyganb47bb741cc03
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14e900fbd..8a99ff0e3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## Tanks sit on the ground
+
+- Ambient Occlusion, under Options, Effects, is a new setting, off by default until it has been played. EA gave a unit one shadow, the sun's, so on its shaded side a tank met the sand with nothing between them and read as hovering. Now the ground at the tracks of a tank on Golden Oasis loses about 40% of its light and has it all back 130 pixels out, the foot of a War Factory's wall and the crease under a turret go dark the same way, and open ground stays exactly as it was. The water and the fog of war stay out of it. In a battle of three armies and three superweapons the graphics card's frame goes from 7.9 ms to 8.2 ms. The Direct3D 9 picture and Classic Graphics keep the old look.
+
## Shadows reach the far ground
- Pull the camera right out, tilt it flat, and shadows used to stop along a line across the far ground. On Twilight Flame a whole base stood past that line with its power plants, trees and tanks on bare lit earth, each with no shadow under it. They were drawn for 2400 units round the spot you were looking at, while the far corner of that view is 3343 away. The shadows now go round what is on the screen and reach the top of it.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index bddc4754a..e8060b1e7 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1524,6 +1524,14 @@ TOOLTIP:HemiAmbient
"Models take the map's ambient light from the sky above and the ground below instead of evenly, so a tank's deck is lighter than its belly. Walls keep the light they had and a night map stays dark. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
END
+GUI:AmbientOcclusion
+"Ambient Occlusion"
+END
+
+TOOLTIP:AmbientOcclusion
+"Corners and the ground under what stands on it go darker, so a tank sits on the sand instead of hovering over it. Water and the fog of war stay out of it. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
+END
+
GUI:FormationDrag
"Drag Out A Formation"
END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index cab6e3116..ff6d2f779 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15917,6 +15917,14 @@ TOOLTIP:HemiAmbient
"Modeller haritanın ortam ışığını eşit almak yerine yukarıdan gökyüzünden, aşağıdan zeminden alır, böylece bir tankın üstü altından açık görünür. Duvarlar aynı ışıkta kalır, gece haritası karanlık kalır. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
END
+GUI:AmbientOcclusion
+"Ortam Gölgeleme"
+END
+
+TOOLTIP:AmbientOcclusion
+"Köşeler ve bir şeyin üstünde durduğu zemin koyulaşır, böylece tank kumun üstünde uçuyormuş gibi değil kumda duruyormuş gibi görünür. Su ve savaş sisi bundan etkilenmez. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
+END
+
GUI:FormationDrag
"Sürükleyerek Düzen Kur"
END
diff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
index 642439ac8..4d09c8459 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
@@ -6954,6 +6954,53 @@ WINDOW
WINDOW
WINDOWTYPE = CHECKBOX;
SCREENRECT = UPPERLEFT: 288 322, BOTTOMRIGHT: 512 346, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckAmbientOcclusion";
+ STATUS = ENABLED+IMAGE+BORDER;
+ STYLE = CHECKBOX+MOUSETRACK;
+ SYSTEMCALLBACK = "[None]";
+ INPUTCALLBACK = "[None]";
+ TOOLTIPCALLBACK = "[None]";
+ DRAWCALLBACK = "[None]";
+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;
+ HEADERTEMPLATE = "MinorTitle";
+ TOOLTIPTEXT = "TOOLTIP:AmbientOcclusion";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:AmbientOcclusion";
+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,
+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,
+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;
+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,
+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,
+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ END
+ CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 288 350, BOTTOMRIGHT: 512 374, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckExtraAnimations";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
@@ -7000,7 +7047,7 @@ WINDOW
CHILD
WINDOW
WINDOWTYPE = CHECKBOX;
- SCREENRECT = UPPERLEFT: 288 350, BOTTOMRIGHT: 512 374, CREATIONRESOLUTION: 800 600;
+ SCREENRECT = UPPERLEFT: 288 378, BOTTOMRIGHT: 512 402, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckTreeSway";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
@@ -7047,7 +7094,7 @@ WINDOW
CHILD
WINDOW
WINDOWTYPE = CHECKBOX;
- SCREENRECT = UPPERLEFT: 288 378, BOTTOMRIGHT: 512 402, CREATIONRESOLUTION: 800 600;
+ SCREENRECT = UPPERLEFT: 288 406, BOTTOMRIGHT: 512 430, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckBehindBuilding";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 80e46f0dd..0d23bb097 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -709,6 +709,7 @@ public:
Bool m_groundMarks; ///< "GroundMarks": craters, stains and longer treads that fade over minutes (Direct3D 11, client only)
Bool m_firelight; ///< "Firelight": flames light the ground, walls and units around them (Direct3D 11, client only)
Bool m_hemiAmbient; ///< "HemiAmbient": models take the ambient from the sky above and the ground below (Direct3D 11, client only)
+ Bool m_ambientOcclusion; ///< "AmbientOcclusion": corners and the ground under what stands on it darken, half size in world units (Direct3D 11, client only)
Int m_maxParticleCount; ///< maximum number of particles that can exist
Int m_maxFieldParticleCount; ///< maximum number of field-type particles that can exist (roughly)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index cf5aaf768..8f55f126b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1138,6 +1138,7 @@ GlobalData::GlobalData()
m_groundMarks = FALSE;
m_firelight = FALSE;
m_hemiAmbient = FALSE;
+ m_ambientOcclusion = FALSE;
m_horizontalScrollSpeedFactor = 1.0;
m_verticalScrollSpeedFactor = 1.0;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 1ebc57609..9c9f098d5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -145,6 +145,7 @@ OPTION_BOOL_ACCESSORS( m_waterFoam )
OPTION_BOOL_ACCESSORS( m_groundMarks )
OPTION_BOOL_ACCESSORS( m_firelight )
OPTION_BOOL_ACCESSORS( m_hemiAmbient )
+OPTION_BOOL_ACCESSORS( m_ambientOcclusion )
OPTION_INT_ACCESSORS( m_shadowQuality )
OPTION_INT_ACCESSORS( m_graphicsQuality )
@@ -635,6 +636,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_hemiAmbient, set_m_hemiAmbient },
+ // Corners and the ground under what stands on it darken. The scene reads it every frame. Off under
+ // Classic graphics and -d3d9, and no row in the quality table: an opt-in until it has been seen. On
+ // Options > Effects.
+ { "AmbientOcclusion", OPT_WND( "CheckAmbientOcclusion" ), "GUI:AmbientOcclusion",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_ambientOcclusion, set_m_ambientOcclusion },
+
// The size of the sun's depth map. The shadow pass asks for it every frame and the backend makes
// the map again when the size changes, so a new level shows on the next frame. On Options >
// Effects. Classic graphics and -d3d9 draw no map at all.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index 38033eeb3..bb904115c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -2961,7 +2961,7 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
// three looks only the Direct3D 11 picture draws; under -d3d9 their boxes keep the saved value, greyed
if( !TheGlobalData->m_direct3D11 )
{
- static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient" };
+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion" };
for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )
findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index b6e7ec301..57e0984cc 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -1102,6 +1102,12 @@ void RTS3DScene::Flush(RenderInfoClass & rinfo)
//don't draw shadows in this mode because they interfere with destination alpha
if (m_customPassMode == SCENE_PASS_DEFAULT && Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
DoShadows(rinfo, true); //draw all stencil shadows
+
+ // The Ambient Occlusion option goes on under the water and every translucent draw, none of which
+ // writes depth: the water takes no corner's shade from its bed and only the bed's shows through it.
+ if (TheGlobalData->m_ambientOcclusion && m_customPassMode == SCENE_PASS_DEFAULT && Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
+ Direct3D11_Ambient_Occlusion();
+
WW3D::Render_And_Clear_Static_Sort_Lists(rinfo); //draws things like water
if (m_customPassMode == SCENE_PASS_DEFAULT && Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index 59e3bf15f..b6c158cdb 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -379,9 +379,13 @@ static void pushProtoHazeFrame(void)
warmth = max(min(daylight, 1.0f), 0.0f);
}
DX11Post_Set_Haze(colour, top, rise, strength, PROTO_HAZE_REACH, water, towardSun, warmth);
+}
- // The fog the terrain draws, through the terrain's own mapping (ShroudTextureShader::set): the
- // texture starts a cell before the draw origin, a texel to a cell.
+// The fog the terrain draws, through the terrain's own mapping (ShroudTextureShader::set): the
+// texture starts a cell before the draw origin, a texel to a cell. The haze and the Ambient Occlusion
+// option read it.
+static void pushShroudFrame(void)
+{
W3DShroud *shroud = (TheTerrainRenderObject != NULL) ? TheTerrainRenderObject->getShroud() : NULL;
if (shroud != NULL && shroud->getShroudTexture() != NULL)
{
@@ -402,6 +406,8 @@ void W3DShaderManager::pushProtoHaze(void)
#if defined(_WIN32)
if (TheGlobalData->m_mapLight && Direct3D11_Is_Active())
pushProtoHazeFrame();
+ if ((TheGlobalData->m_mapLight || TheGlobalData->m_ambientOcclusion) && Direct3D11_Is_Active())
+ pushShroudFrame();
#endif
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
index 75aefd4c5..72482710e 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
@@ -379,6 +379,8 @@ public:
// haze). False when Set_Scene_View has not run since Open_Frame, when that projection is not a
// perspective one or the matrix has no inverse.
bool Scene_World_From_Clip(float world_from_clip[16]) const;
+ // How that projection scales x and y: a world unit at eye distance d is x / d and y / d of half the frame.
+ void Scene_Projection_Scale(float & x, float & y) const { x = SceneProjection[0]; y = SceneProjection[5]; }
// The top of a frame, before any scene of it: Scene_World_From_Clip waits for this frame's view.
void Open_Frame();
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index 318d20794..92ddaf704 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -206,6 +206,9 @@ struct PostConstantBlock
float HazeSun[4];
// The shroud light's world rectangle (origin, one over size).
float HazeShroudRect[4];
+ // How the scene's projection scales x and y, for the occlusion in world units to find its reach
+ // on the screen. Only that program declares it.
+ float WorldAoProjection[4];
};
// A triangle big enough to cover the screen, made out of nothing. No vertex buffer and no input
@@ -470,6 +473,155 @@ static const char * const AO_SCENE_SHADER_BODY =
" return float4((1.0 - occlusion * AO_STRENGTH).xxx, 1.0);\n"
"}\n";
+// The Ambient Occlusion option, in three programs compiled on first use. The depth goes back to the
+// world, so the reach is in world units and a corner reads the same at every zoom: a tank's skirt is
+// dark to the same few units of ground whether it fills the frame or is thirty pixels long. A tap
+// that stands higher over the pixel's own surface than the bias closes off sky, weighted by how
+// steeply and fading out at the radius, so open ground and a flat roof come out untouched and a
+// tall building behind a unit's feet casts nothing on them. The surface comes from the depth
+// itself, from whichever neighbour on each axis lies nearer, or a pixel on a silhouette would take
+// the slope between the two objects for its own.
+//
+// All of it runs at half size. Each half size pixel reads one full size depth texel, and it keeps
+// the distance along the eye's axis beside its occlusion so the blur and the upsample need not
+// read depth again per tap. Depth is Load, never Sample: filtered depth across a silhouette is a
+// surface nobody drew.
+#define WORLD_AO_CONSTANTS \
+ "cbuffer WorldAoConstants : register(b1)\n" \
+ "{\n" \
+ " row_major float4x4 WorldFromClip : packoffset(c15);\n" \
+ " float4 HazeSun : packoffset(c19);\n" \
+ " float4 HazeShroudRect : packoffset(c20);\n" \
+ " float4 WorldAoProjection : packoffset(c21);\n" \
+ "};\n" \
+ "Texture2D WorldAoShroud : register(t2);\n" \
+ "\n" \
+ "float eye_distance(float raw)\n" \
+ "{\n" \
+ " return 1.0 / (raw * WorldFromClip[2][3] + WorldFromClip[3][3]);\n" \
+ "}\n" \
+ "\n"
+
+static const char * const WORLD_AO_SHADER_BODY =
+ WORLD_AO_CONSTANTS
+ "static const int AO_TAPS = 14;\n"
+ "static const float AO_RADIUS = 22.0;\n"
+ "static const float AO_MOST_PIXELS = 120.0;\n"
+ "static const float AO_BIAS = 0.12;\n"
+ "static const float AO_STRENGTH = 2.8;\n"
+ "\n"
+ "float3 world_at(int2 texel, float raw)\n"
+ "{\n"
+ " float2 ndc = float2((texel.x + 0.5) * TexelSize.x * 2.0 - 1.0, 1.0 - (texel.y + 0.5) * TexelSize.y * 2.0);\n"
+ " float4 world = mul(float4(ndc, raw, 1.0), WorldFromClip);\n"
+ " return world.xyz / world.w;\n"
+ "}\n"
+ "\n"
+ // Past the frame's edge Load reads 0, the near plane, a long way off, so the slope never takes it.
+ "float3 world_of(int2 texel)\n"
+ "{\n"
+ " return world_at(texel, Extra.Load(int3(texel, 0)).r);\n"
+ "}\n"
+ "\n"
+ "float3 shorter(float3 a, float3 b)\n"
+ "{\n"
+ " return dot(a, a) < dot(b, b) ? a : b;\n"
+ "}\n"
+ "\n"
+ "float4 main(VertexOutput input) : SV_TARGET\n"
+ "{\n"
+ " int2 texel = min(int2(input.Position.xy) * 2 + 1, int2(TexelSize.zw) - 1);\n"
+ " float raw = Extra.Load(int3(texel, 0)).r;\n"
+ " float distance_along = eye_distance(raw);\n"
+ " if (raw >= 0.99999) return float4(1.0, distance_along, 0.0, 0.0);\n"
+ " float3 here = world_at(texel, raw);\n"
+ " float3 across = shorter(here - world_of(texel - int2(1, 0)), world_of(texel + int2(1, 0)) - here);\n"
+ " float3 down = shorter(here - world_of(texel - int2(0, 1)), world_of(texel + int2(0, 1)) - here);\n"
+ " float3 facing = normalize(cross(across, down));\n"
+ " if (dot(facing, world_at(texel, 0.0) - here) < 0.0) facing = -facing;\n"
+ "\n"
+ " float2 reach = AO_RADIUS * 0.5 * WorldAoProjection.xy * TexelSize.zw / distance_along;\n"
+ " reach *= min(1.0, AO_MOST_PIXELS / reach.y);\n"
+ " float turn = frac(52.9829189 * frac(dot(input.Position.xy, float2(0.06711056, 0.00583715)))) * 6.2831853;\n"
+ " float closed = 0.0;\n"
+ " for (int tap = 0; tap < AO_TAPS; ++tap)\n"
+ " {\n"
+ " float angle = turn + 2.39996 * (float)tap;\n"
+ " float along = ((float)tap + 0.5) / (float)AO_TAPS;\n"
+ // A tap off the frame knows nothing and closes nothing. Given the edge's depth instead, a tap above
+ // the frame stood over ground that recedes that way, and the whole top of the frame went dark.
+ " int2 at = texel + int2(float2(cos(angle), sin(angle)) * reach * along);\n"
+ " if (any(at < 0) || any(at >= int2(TexelSize.zw))) continue;\n"
+ " float3 to = world_of(at) - here;\n"
+ " float squared = dot(to, to);\n"
+ " float fade = saturate(1.0 - squared / (AO_RADIUS * AO_RADIUS));\n"
+ " closed += fade * fade * saturate(dot(to, facing) * rsqrt(squared + 0.01) - AO_BIAS);\n"
+ " }\n"
+ " float kept = saturate(1.0 - AO_STRENGTH * closed / (float)AO_TAPS);\n"
+ // The fog the terrain draws, as the haze reads it: under the shroud nothing, in the fog little.
+ " float lit = lerp(1.0, WorldAoShroud.SampleLevel(Sampler, (here.xy - HazeShroudRect.xy) * HazeShroudRect.zw, 0.0).g, HazeSun.z);\n"
+ " return float4(lerp(1.0, kept, lit * lit * lit), distance_along, 0.0, 0.0);\n"
+ "}\n";
+
+// One axis of the blur that takes the tap pattern's grain off, stopping at a change of distance so a
+// tank's dark skirt does not bleed over the roof of the tank. What counts as a change is twenty half
+// size pixels' width on the ground, which is the same ground at every zoom and on the isometric
+// camera, whose eye stands thousands of units back with a narrow lens: there a tolerance taken as a
+// share of the distance let the skirt straight over the hull.
+static const char * const WORLD_AO_BLUR_SHADER_BODY =
+ WORLD_AO_CONSTANTS
+ "static const float WEIGHTS[5] = { 0.2, 0.18, 0.14, 0.09, 0.05 };\n"
+ "\n"
+ "float4 main(VertexOutput input) : SV_TARGET\n"
+ "{\n"
+ " int2 texel = int2(input.Position.xy);\n"
+ " int2 step = int2(BlurDirection.xy);\n"
+ " float2 centre = Source.Load(int3(texel, 0)).rg;\n"
+ " float allowed = 40.0 * centre.g / (WorldAoProjection.y * TexelSize.w);\n"
+ " float sum = centre.r * WEIGHTS[0];\n"
+ " float total = WEIGHTS[0];\n"
+ " for (int index = 1; index < 5; ++index)\n"
+ " {\n"
+ " float2 a = Source.Load(int3(clamp(texel + step * index, int2(0, 0), int2(TexelSize.zw) - 1), 0)).rg;\n"
+ " float2 b = Source.Load(int3(clamp(texel - step * index, int2(0, 0), int2(TexelSize.zw) - 1), 0)).rg;\n"
+ " float weightA = WEIGHTS[index] * saturate(1.0 - abs(a.g - centre.g) / allowed);\n"
+ " float weightB = WEIGHTS[index] * saturate(1.0 - abs(b.g - centre.g) / allowed);\n"
+ " sum += a.r * weightA + b.r * weightB;\n"
+ " total += weightA + weightB;\n"
+ " }\n"
+ " return float4(sum / total, centre.g, 0.0, 0.0);\n"
+ "}\n";
+
+// Back to full size as a factor the scene is multiplied by. The four half size pixels round this
+// one weigh by nearness as a bilinear filter would and by how close their distance is to this
+// pixel's, with a floor: a one pixel antenna that matches none of them still gets the filter's
+// answer rather than a division by nothing. A half size pixel holds the depth of full size texel
+// 2i+1, so its centre is at 2i+1.5, which is the 0.75 in the position.
+static const char * const WORLD_AO_UPSAMPLE_SHADER_BODY =
+ WORLD_AO_CONSTANTS
+ "float4 main(VertexOutput input) : SV_TARGET\n"
+ "{\n"
+ " float wanted = eye_distance(Extra.Load(int3(int2(input.Position.xy), 0)).r);\n"
+ " float allowed = 20.0 * wanted / (WorldAoProjection.y * TexelSize.w);\n"
+ " float2 at = input.Position.xy * 0.5 - 0.75;\n"
+ " int2 corner = max(int2(floor(at)), int2(0, 0));\n"
+ " float2 part = saturate(at - corner);\n"
+ " float sum = 0.0;\n"
+ " float total = 0.0;\n"
+ " for (int y = 0; y < 2; ++y)\n"
+ " {\n"
+ " for (int x = 0; x < 2; ++x)\n"
+ " {\n"
+ " float2 tap = Source.Load(int3(corner + int2(x, y), 0)).rg;\n"
+ " float bilinear = (x == 1 ? part.x : 1.0 - part.x) * (y == 1 ? part.y : 1.0 - part.y);\n"
+ " float weight = bilinear * (0.001 + saturate(1.0 - abs(tap.g - wanted) / allowed));\n"
+ " sum += tap.r * weight;\n"
+ " total += weight;\n"
+ " }\n"
+ " }\n"
+ " return float4((sum / total).xxx, 1.0);\n"
+ "}\n";
+
// The prototype ground haze, blended over the scene target by its alpha mid-scene, at the moment
// the occlusion goes on. The pixel's depth goes back to the world the way the headlights take it
// (HEADLIGHT_SAMPLING in ffshader.h); how far it lies below the haze's top decides how much of the
@@ -820,8 +972,12 @@ DX11PostProcessClass::DX11PostProcessClass()
, Hazed(false)
, HazeRefused(false)
, HazeShroudView(NULL)
+ , WorldAoRefused(false)
{
memset(HazeWorldFromClip, 0, sizeof(HazeWorldFromClip));
+ memset(WorldAoShaders, 0, sizeof(WorldAoShaders));
+ memset(WorldAoTargets, 0, sizeof(WorldAoTargets));
+ memset(WorldAoProjection, 0, sizeof(WorldAoProjection));
memset(PixelShaders, 0, sizeof(PixelShaders));
memset(&SceneTarget, 0, sizeof(SceneTarget));
memset(&SceneResolve, 0, sizeof(SceneResolve));
@@ -870,6 +1026,9 @@ void DX11PostProcessClass::Shutdown()
release_interface(reinterpret_cast<IUnknown **>(&BlendState));
release_interface(reinterpret_cast<IUnknown **>(&Sampler));
release_interface(reinterpret_cast<IUnknown **>(&HazeShader));
+ for (unsigned index = 0; index < WORLD_AO_PROGRAMS; ++index) {
+ release_interface(reinterpret_cast<IUnknown **>(&WorldAoShaders[index]));
+ }
release_interface(reinterpret_cast<IUnknown **>(&SceneOcclusionShader));
release_interface(reinterpret_cast<IUnknown **>(&WarpShader));
release_interface(reinterpret_cast<IUnknown **>(&BloomCompositeShader));
@@ -885,6 +1044,7 @@ void DX11PostProcessClass::Shutdown()
ShadersReady = false;
Resolved = false;
HazeRefused = false;
+ WorldAoRefused = false;
}
void DX11PostProcessClass::Set_Chain(const DX11PostEffect effects[DX11_POST_CHAIN_LIMIT],
@@ -1110,6 +1270,8 @@ void DX11PostProcessClass::Release_Targets()
Release_Target(SceneTarget);
Release_Target(SceneResolve);
Release_Target(SceneCopy);
+ Release_Target(WorldAoTargets[0]);
+ Release_Target(WorldAoTargets[1]);
const unsigned chain_target_count = sizeof(ChainTargets) / sizeof(ChainTargets[0]);
for (unsigned index = 0; index < chain_target_count; ++index) {
Release_Target(ChainTargets[index]);
@@ -1215,6 +1377,111 @@ void DX11PostProcessClass::Compile_Haze_Program()
}
}
+bool DX11PostProcessClass::Wants_World_Ao_Programs() const
+{
+ return WorldAoShaders[WORLD_AO_PROGRAMS - 1] == NULL && !WorldAoRefused && ShadersReady;
+}
+
+const char * DX11PostProcessClass::World_Ao_Program_Source(unsigned index) const
+{
+ static const std::string sources[WORLD_AO_PROGRAMS] = {
+ std::string(PIXEL_SHADER_PROLOGUE) + WORLD_AO_SHADER_BODY,
+ std::string(PIXEL_SHADER_PROLOGUE) + WORLD_AO_BLUR_SHADER_BODY,
+ std::string(PIXEL_SHADER_PROLOGUE) + WORLD_AO_UPSAMPLE_SHADER_BODY
+ };
+ return sources[index].c_str();
+}
+
+void DX11PostProcessClass::Load_World_Ao_Program(unsigned index, const void * bytecode, SIZE_T size)
+{
+ if (bytecode == NULL || FAILED(Device->Get_Device()->CreatePixelShader(bytecode, size, NULL,
+ &WorldAoShaders[index]))) {
+ WorldAoShaders[index] = NULL;
+ WorldAoRefused = true;
+ }
+}
+
+void DX11PostProcessClass::Compile_World_Ao_Programs()
+{
+ const char * const bodies[WORLD_AO_PROGRAMS] = { WORLD_AO_SHADER_BODY, WORLD_AO_BLUR_SHADER_BODY,
+ WORLD_AO_UPSAMPLE_SHADER_BODY };
+ for (unsigned index = 0; index < WORLD_AO_PROGRAMS; ++index) {
+ if (!compile_pixel_shader(compiler_function(), Device->Get_Device(), bodies[index], &WorldAoShaders[index])) {
+ WorldAoShaders[index] = NULL;
+ WorldAoRefused = true;
+ }
+ }
+}
+
+bool DX11PostProcessClass::World_Occlude_Scene(ID3D11ShaderResourceView * depth,
+ const float world_from_clip[16], float projection_x, float projection_y)
+{
+ if (Occluded || Resolved || !ShadersReady || SceneTarget.View == NULL
+ || Device->Get_Scene_View() != SceneTarget.View || WorldAoRefused
+ || WorldAoShaders[WORLD_AO_PROGRAMS - 1] == NULL) {
+ return false;
+ }
+ const unsigned half_width = (Width + 1) / 2;
+ const unsigned half_height = (Height + 1) / 2;
+ if (WorldAoTargets[0].Texture == NULL
+ && (!Create_Target(WorldAoTargets[0], half_width, half_height, DXGI_FORMAT_R32G32_FLOAT)
+ || !Create_Target(WorldAoTargets[1], half_width, half_height, DXGI_FORMAT_R32G32_FLOAT))) {
+ Release_Target(WorldAoTargets[0]);
+ Release_Target(WorldAoTargets[1]);
+ return false;
+ }
+ memcpy(HazeWorldFromClip, world_from_clip, sizeof(HazeWorldFromClip));
+ WorldAoProjection[0] = projection_x;
+ WorldAoProjection[1] = projection_y;
+ // Read and left for the haze, which comes later in the same frame and takes it for good.
+ HazeShroudView = HazeShroudSource;
+
+ PassSetup pass;
+ memset(&pass, 0, sizeof(pass));
+ pass.Shader = WorldAoShaders[0];
+ pass.Extra = depth;
+ pass.World = true;
+ pass.Destination = WorldAoTargets[0].View;
+ pass.DestinationWidth = half_width;
+ pass.DestinationHeight = half_height;
+ pass.SourceWidth = Width;
+ pass.SourceHeight = Height;
+ Draw_Pass(pass);
+
+ memset(&pass, 0, sizeof(pass));
+ pass.Shader = WorldAoShaders[1];
+ pass.World = true;
+ pass.Source = WorldAoTargets[0].Resource;
+ pass.Destination = WorldAoTargets[1].View;
+ pass.DestinationWidth = half_width;
+ pass.DestinationHeight = half_height;
+ pass.SourceWidth = half_width;
+ pass.SourceHeight = half_height;
+ pass.BlurX = 1.0f;
+ Draw_Pass(pass);
+
+ pass.Source = WorldAoTargets[1].Resource;
+ pass.Destination = WorldAoTargets[0].View;
+ pass.BlurX = 0.0f;
+ pass.BlurY = 1.0f;
+ Draw_Pass(pass);
+
+ memset(&pass, 0, sizeof(pass));
+ pass.Shader = WorldAoShaders[2];
+ pass.Source = WorldAoTargets[0].Resource;
+ pass.Extra = depth;
+ pass.World = true;
+ pass.Multiply = true;
+ pass.Destination = SceneTarget.View;
+ pass.DestinationWidth = Width;
+ pass.DestinationHeight = Height;
+ pass.SourceWidth = half_width;
+ pass.SourceHeight = half_height;
+ Draw_Pass(pass);
+ Occluded = true;
+ return true;
+}
+
bool DX11PostProcessClass::Haze_Scene(ID3D11ShaderResourceView * depth,
const float world_from_clip[16])
{
@@ -1347,6 +1614,7 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
// the program reads only the sun's bearing, so its z says whether a shroud texture is bound
block.HazeSun[2] = (HazeShroudView != NULL) ? 1.0f : 0.0f;
memcpy(block.HazeShroudRect, HazeShroudRect, sizeof(block.HazeShroudRect));
+ memcpy(block.WorldAoProjection, WorldAoProjection, sizeof(block.WorldAoProjection));
memcpy(mapped.pData, &block, sizeof(block));
context->Unmap(ConstantBuffer, 0);
@@ -1377,7 +1645,7 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
ID3D11ShaderResourceView * resources[2] = { pass.Source, pass.Extra };
context->PSSetShaderResources(0, 2, resources);
context->PSSetConstantBuffers(0, 1, &ConstantBuffer);
- const bool haze = (pass.Shader == HazeShader);
+ const bool haze = pass.World || pass.Shader == HazeShader;
if (haze) {
// The same buffer at b1 as well, where the haze program reads its own fields of it, and
// the shroud at t2.
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 78f818c43..a224208da 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -231,6 +231,21 @@ public:
// The same program compiled here, past any cache, for a caller without the backend (the tests).
void Compile_Haze_Program();
+ // The Ambient Occlusion option multiplied into the scene target as it stands: half size, in world
+ // units out of the depth given, blurred, and brought back up by distance. The scene calls it before
+ // the water and every translucent draw, so none of those takes a corner's shade. It takes the
+ // place of the chain's "ao" that frame, whether or not the chain has one. Projection_x and _y
+ // are the scene projection's scale on each axis. False when it drew nothing; the caller rebinds
+ // as for Occlude_Scene. The programs come through the backend's cache as the haze's do: three
+ // sources, and the tests compile them here.
+ bool World_Occlude_Scene(ID3D11ShaderResourceView * depth, const float world_from_clip[16],
+ float projection_x, float projection_y);
+ bool Wants_World_Ao_Programs() const;
+ const char * World_Ao_Program_Source(unsigned index) const;
+ void Load_World_Ao_Program(unsigned index, const void * bytecode, SIZE_T size);
+ void Compile_World_Ao_Programs();
+ static const unsigned WORLD_AO_PROGRAMS = 3;
+
// Call once at the very top of a frame, before any scene of it (a mirror's included) begins.
// Arms Occlude_Scene again.
void Open_Frame();
@@ -274,6 +289,8 @@ private:
bool Multiply;
// The pass's colour goes over what the destination holds by its alpha.
bool Blend;
+ // The pass reads the world's fields of the constants at b1 and the shroud at t2, as the haze does.
+ bool World;
};
bool Create_Shaders();
@@ -322,6 +339,8 @@ private:
Target SceneResolve;
// The scene as Occlude_Scene found it, in its format, made at that pass's first use.
Target SceneCopy;
+ // Half size, occlusion and distance: the two the blur goes between, made at that pass's first use.
+ Target WorldAoTargets[2];
Target ChainTargets[2];
Target BloomTargets[2];
@@ -348,6 +367,11 @@ private:
bool HazeRefused;
// The terrain's shroud texture under the haze, borrowed from its D3D9 texture each pass.
ID3D11ShaderResourceView * HazeShroudView;
+ // The Ambient Occlusion option's programs, the projection scale it was handed, and a refusal: not
+ // tried again.
+ ID3D11PixelShader * WorldAoShaders[WORLD_AO_PROGRAMS];
+ float WorldAoProjection[4];
+ bool WorldAoRefused;
char Diagnostic[192];
};
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index 247006c47..11278e828 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -776,6 +776,34 @@ void Direct3D11_Occlude_Scene()
}
}
+void Direct3D11_Ambient_Occlusion()
+{
+ if (!Active || !DrawEffectsAllowed || !Backend.Draws_Into_Scene()) {
+ return;
+ }
+ if (Post.Wants_World_Ao_Programs()) {
+ for (unsigned index = 0; index < DX11PostProcessClass::WORLD_AO_PROGRAMS; ++index) {
+ std::vector<unsigned char> code;
+ if (Backend.Compile_Pixel_Program(Post.World_Ao_Program_Source(index), "dx11worldao", code) && !code.empty()) {
+ Post.Load_World_Ao_Program(index, &code[0], code.size());
+ } else {
+ Post.Load_World_Ao_Program(index, NULL, 0);
+ }
+ }
+ }
+ float world_from_clip[16];
+ if (!Backend.Scene_World_From_Clip(world_from_clip)) {
+ return;
+ }
+ Backend.Resolve_Scene_Depth();
+ float projection_x = 0.0f;
+ float projection_y = 0.0f;
+ Backend.Scene_Projection_Scale(projection_x, projection_y);
+ if (Post.World_Occlude_Scene(Device.Get_Depth_Texture(), world_from_clip, projection_x, projection_y)) {
+ Backend.Resume_Scene();
+ }
+}
+
void Direct3D11_Allow_Draw_Effects(bool allowed)
{
DrawEffectsAllowed = allowed;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
index 43ae64b56..9770e078e 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
@@ -267,6 +267,11 @@ unsigned Direct3D11_Requested_Draw_Effect(float parameters[4]);
// Nothing happens without "ao" in the chain or while a filter or a mirror holds the target.
void Direct3D11_Occlude_Scene();
+// The Ambient Occlusion option (DX11PostProcessClass::World_Occlude_Scene), called once the opaque world
+// is down and before the water. The chain's own occlusion stands down for the frame. -d3d9, Classic
+// graphics, -headless and the SDL3 port draw nothing here.
+void Direct3D11_Ambient_Occlusion();
+
// Whether the draws that follow take the Glow option's additive gain (DX11BackendClass::
// Set_Glow_Draw). ShaderClass::Apply sends it from the shader's GLOW_ENABLE bit.
void Direct3D11_Set_Glow_Draw(bool glow);
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
index c3ce2c8f5..595d7937f 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
@@ -96,6 +96,7 @@ unsigned Direct3D11_Requested_Draw_Effect(float parameters[4])
return 0;
}
void Direct3D11_Occlude_Scene() {}
+void Direct3D11_Ambient_Occlusion() {}
void Direct3D11_Set_Glow_Draw(bool) {}
void Direct3D11_Set_Scene_Stand_In(struct IDirect3DBaseTexture9 *, struct IDirect3DSurface9 *) {}
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index 75d0ec8fd..8e4254348 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -740,3 +740,79 @@ TEST(dx11post_the_ground_haze_lies_over_a_scene_under_its_top)
delete [] result;
}
}
+
+// The Ambient Occlusion option drawn for real over a white scene. The world is the clip space times
+// forty across and a thousand deep, so the frame is 80 units across at 0.8 of a pixel a unit, the left
+// half stands 10 units nearer the eye than the right, and the near plane, which a tap past the frame's
+// edge reads, is out of reach. The floor at that step's foot goes dark; the floor past the reach and
+// the top of the step stay exactly white, and the chain's own "ao" stands down.
+TEST(dx11post_world_occlusion_darkens_the_foot_of_a_step_and_nothing_else)
+{
+ DeviceFixture fixture;
+ if (!fixture.Create()) {
+ printf("skip: no Direct3D 11 device on this machine\n");
+ return;
+ }
+
+ const float FLOOR_DEPTH = 0.5f;
+ const float TOP_DEPTH = 0.49f;
+ const float UNITS_DEEP = 1000.0f;
+ const float UNITS_A_CLIP = 40.0f;
+ const float PROJECTION_SCALE = 1.0f / UNITS_A_CLIP;
+ const unsigned char DARKENED_BY_AT_LEAST = 10;
+ DX11DeviceClass & device = fixture.Get_Device();
+ DX11PostProcessClass & post = fixture.Get_Post();
+
+ float depth[SURFACE_SIZE * SURFACE_SIZE];
+ for (unsigned y = 0; y < SURFACE_SIZE; ++y) {
+ for (unsigned x = 0; x < SURFACE_SIZE; ++x) {
+ depth[y * SURFACE_SIZE + x] = (x < SURFACE_SIZE / 2) ? TOP_DEPTH : FLOOR_DEPTH;
+ }
+ }
+ D3D11_TEXTURE2D_DESC description;
+ ZeroMemory(&description, sizeof(description));
+ description.Width = SURFACE_SIZE;
+ description.Height = SURFACE_SIZE;
+ description.MipLevels = 1;
+ description.ArraySize = 1;
+ description.Format = DXGI_FORMAT_R32_FLOAT;
+ description.SampleDesc.Count = 1;
+ description.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+ D3D11_SUBRESOURCE_DATA initial;
+ ZeroMemory(&initial, sizeof(initial));
+ initial.pSysMem = depth;
+ initial.SysMemPitch = SURFACE_SIZE * sizeof(float);
+ ID3D11Texture2D * texture = NULL;
+ ID3D11ShaderResourceView * view = NULL;
+ CHECK(SUCCEEDED(device.Get_Device()->CreateTexture2D(&description, &initial, &texture)));
+ CHECK(SUCCEEDED(device.Get_Device()->CreateShaderResourceView(texture, NULL, &view)));
+
+ unsigned char picture[SURFACE_SIZE * SURFACE_SIZE * BYTES_A_PIXEL];
+ fill_flat(picture, LIGHT_LEVEL);
+ const DX11PostEffect ao_only[] = { DX11_POST_AO };
+ post.Set_Chain(ao_only, 1);
+ post.Compile_World_Ao_Programs();
+ post.Open_Frame();
+ post.Begin_Frame();
+ device.Set_Scene_View(post.Scene_View());
+ const float world_from_clip[16] = {
+ UNITS_A_CLIP, 0.0f, 0.0f, 0.0f, 0.0f, UNITS_A_CLIP, 0.0f, 0.0f, 0.0f, 0.0f, UNITS_DEEP, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
+ const bool drawn = write_scene(device, post, picture)
+ && post.World_Occlude_Scene(view, world_from_clip, PROJECTION_SCALE, PROJECTION_SCALE);
+ CHECK(drawn);
+ CHECK(!post.Occlude_Scene(device.Get_Depth_Texture()));
+ CHECK(post.Run_Chain());
+ device.Set_Scene_View(NULL);
+
+ unsigned pitch = 0;
+ unsigned char * result = drawn ? read_back_buffer(device, pitch) : NULL;
+ CHECK(result != NULL);
+ if (result != NULL) {
+ CHECK(pixel_level(result, pitch, SURFACE_SIZE / 2 + 2, SURFACE_SIZE / 2) <= LIGHT_LEVEL - DARKENED_BY_AT_LEAST);
+ CHECK_EQ((unsigned)LIGHT_LEVEL, (unsigned)pixel_level(result, pitch, SURFACE_SIZE - 3, SURFACE_SIZE / 2));
+ CHECK_EQ((unsigned)LIGHT_LEVEL, (unsigned)pixel_level(result, pitch, 3, SURFACE_SIZE / 2));
+ delete [] result;
+ }
+ view->Release();
+ texture->Release();
+}
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index b4d939a77..8965e436a 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -241,6 +241,7 @@ NEW_CONTROLS = [
(CHECK, "CheckGroundMarks", "GUI:GroundMarks"),
(CHECK, "CheckFirelight", "GUI:Firelight"),
(CHECK, "CheckHemiAmbient", "GUI:HemiAmbient"),
+ (CHECK, "CheckAmbientOcclusion", "GUI:AmbientOcclusion"),
(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),
(SLIDER, "SliderGraphicsQuality", None),
]
@@ -382,6 +383,7 @@ GROUP_LAYOUT = [
("check", "CheckWaterFoam"),
("check", "CheckGroundMarks"),
("check", "CheckHemiAmbient"),
+ ("check", "CheckAmbientOcclusion"),
("check", "CheckExtraAnimations"),
("check", "CheckTreeSway"),
("check", "CheckBehindBuilding")]),