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): refused looks keep heat vision, occlusion before fire

Olcay Seygana69523ac7fb2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5f1869f32..e972f5bad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1583,13 +1583,13 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Up to a thousand craters stay on the ground in a long match, where the game kept five hundred and quietly dropped the oldest.
- A nuke flattens a town from the middle out. EA's missile did all its damage on one frame a second after it landed, so every building under the cloud blew up together. The blast now rolls out from the point of impact with the orange heat ring and reaches the edge six tenths of a second later, levelling each building and toppling each tree as it gets there, and burning the ground in the same ring. What each thing takes is unchanged. A replay recorded before this, with a nuke in it, will not play back the same.
- An explosion lights everything around it, smoothly. On the default renderer the light of a blast reaches every tank, soldier, building and patch of ground it can see, fading out with distance, where the ground used to brighten in blocky squares and a model took only four lights at once, so in a big fight half the tanks next to a burning wreck stayed dark. The 32 blasts nearest the camera light at the same time, and a wall with its back to the fire stays in shadow. The light brightens what it falls on by three quarters at most: a nuke's took the ground to white within a few frames until it was held there.
-- A bright cloud no longer shows what is behind it as a line drawing. Inside a nuke's white cloud, or a falling War Factory's fireball, every tree and wreck under it used to come out as a thin grey outline, and the picture's sharpening ringed each dark piece in white. Both stop where the frame is bright.
+- A bright cloud no longer shows what is behind it as a line drawing. Inside a nuke's white cloud, or a falling War Factory's fireball, every tree and wreck under it used to come out as a thin grey outline, and the picture's sharpening ringed each dark piece in white. Both stop where the frame is bright. A yellow or orange fireball still drew them, because the shading that darkens corners was laid over the finished picture and read the fire as dark: an Aurora's bomb on a War Factory showed its chimneys, its lattice and the trees beside it as dark outlines through the flames. Corners are now shaded before any fire or smoke is drawn, so a blast of any colour covers what is behind it.
- Smoke and fire no longer end on a straight line where they meet the ground or a building. A puff that sinks into a hillside or drifts against a wall thins out over its last few metres, softly enough that a nuke's haze and a Scud's grey smoke no longer come out as stacked, stair-stepped terraces, and a toxin cloud lying low over the ground keeps its body instead of breaking into hard-edged green islands. A China mine field blinks where you can see it again: its lights hang just off the ground, and the fade had eaten all but a thirtieth of their bright middle. No effect fades over more than its own size now, so a small spark close to the ground keeps its light. This is the default renderer; Classic and the old renderer keep the hard edge they had in 2003.
- Gunfire shows at the zoom you play at. A rifle's tracer was a third of a unit wide, about one pixel from the default camera, and a bullet hit nothing you could see. Tracers from rifles, Gattlings, Humvees, Technicals and Quad Cannons are now twice as wide and half again as long, the muzzle flash is half as big again, and every hit kicks up sparks and a puff of dirt where it lands. A tank shell burns a short hot streak behind it all the way to the target, where it used to be a grey sliver you could not pick out between the flash and the blast. A Crusader's, Battlemaster's, Scorpion's, Paladin's or Overlord's shot used to be a soft white glow drifting out in front of the gun, wider than the tank; it is now a short orange blast at the barrel tip, with a bigger flame and smoke puff behind it. A shell landing throws dirt and sparks around its blast. The colours are the ones the game always used, and no weapon does anything different.
- Blasts throw fragments that smoke. The bigger explosions fling hot sparks into the air, each drawing a thin dark line of smoke that climbs, fans around the blast and curves down. A Stinger, a rocket pod, a tank shell or a rocket used to throw them too, and a fight filled with them; they now show on a bomb, a heavy shell, a Scud or a building, five that climb several times a tank's length, and on a nuke, a MOAB, a Daisy Cutter or a large building, eight that arc over its own fireball and hang for a couple of seconds. A vehicle that blows up throws burning pieces that drag near-black smoke and bounce where they land, and the turret, wheels and plates it throws off trail smoke and flame too, then smoulder a moment on the ground. The fragments and their smoke are the first effects the particle limit and a lower detail setting drop, so a bigger fight keeps its explosions and loses some lines. What a weapon does is unchanged. Rather have the explosions as they always were? Explosion Debris Trails in the launcher's Options turns all of it off, for you alone: the other players in your match keep whatever they picked, and nobody's game falls out of step over it.
- A China mine field tells you what kind it is. EA's field had no model at all, only a soft white glint swelling and fading on each of its eight spots, so your own minefield looked like a patch of fireflies. Each mine is now marked by a small arming light that snaps on for a quarter of a second every second and a half, red on standard and cluster mines and blue on EMP mines, with a white-hot point and a dark rim that keep it readable on grass, sand or snow. No mine body is drawn on the ground, only the light. The enemy still sees nothing until he detects the field. A mine going off under a tank now throws a column of dark earth twice the tank's height, scatters clods round it and leaves a low black smoke and a scorch, with a short jolt of the screen; it used to puff a pale spray of specks that looked like dust kicked up. An EMP mine throws no earth, so you can tell which kind went off: it lights a blue ring across the ground, a crackle of blue sparks and a short blue flash at the spot; EA's flash grew until it washed the whole screen white for a fifth of a second. What a mine does is unchanged.
- A base out of power looks out of power. A building that switches off when your power runs short, or one a hacker shut down, drains to a cold grey and sags darker, and its windows and lamps go out. Every few seconds it blinks dark for an instant or its lights catch again for a moment, and blue sparks jump on its walls where something shorts. A tank or building hit by an EMP crawls with thin blue arcs for as long as it stays dead, where it used to just turn dark grey.
-- Your own stealthed units look like glass, not like ice. In 3.0 a camouflaged Rebel, a Pathfinder or Colonel Burton came out under a blue skin with bands running up it, which players rightly called ugly. The blue is gone: the ground behind him shows through his body in its own colours and bends, a slow lens that ripples along him and pulls harder at his outline, with a muted share of his own paint left in it. The bend is what you find him by: each face of him tips the ground behind it its own way, so his shape shows even on plain sand, and the bend never drops below a few pixels, and a cool haze that thickens at his outline makes a cloaked squad or a camouflaged base read at a glance at the zoom you play at, still as glass and without turning white. Up close a building's flat wall bends across its face. It moves slowly and never fizzes. He breathes solid at the top of the 2003 pulse and back to glass at the bottom. Going invisible, the paint eases into that lens, then the pulse takes over. Coming out, the bend eases off until the paint is whole. An enemy a detector finds fades into heat the same way. His shadow fades with him, to between a quarter and a half of its strength as he breathes, where it used to lie on the ground at full strength and give him away before his body did; on Classic and the old renderer the shadow stays whole. When an enemy detector has found him, his whole body beats amber along with his edge, so a spotted building reads as spotted and does not just turn tan. On every renderer, a stealthed unit of yours no longer comes out solid whenever no building is on the screen: the game drew it a second time without its see-through. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it shows as heat, its own shading run from dark red through orange to a warm yellow that stops short of white, so you can still tell a tank from a soldier and bright GLA paint keeps its detail, with a burning outline and a slow glow climbing it that flares on every sweep of the detector. The fine scan lines of 3.0 are gone, since zoomed out they broke into stripes. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.
+- Your own stealthed units look like glass, not like ice. In 3.0 a camouflaged Rebel, a Pathfinder or Colonel Burton came out under a blue skin with bands running up it, which players rightly called ugly. The blue is gone: the ground behind him shows through his body in its own colours and bends, a slow lens that ripples along him and pulls harder at his outline, with a muted share of his own paint left in it. The bend is what you find him by: each face of him tips the ground behind it its own way, so his shape shows even on plain sand, and the bend never drops below a few pixels, and a cool haze that thickens at his outline makes a cloaked squad or a camouflaged base read at a glance at the zoom you play at, still as glass and without turning white. Up close a building's flat wall bends across its face. It moves slowly and never fizzes. He breathes solid at the top of the 2003 pulse and back to glass at the bottom. Going invisible, the paint eases into that lens, then the pulse takes over. Coming out, the bend eases off until the paint is whole. An enemy a detector finds fades into heat the same way. His shadow fades with him, to between a quarter and a half of its strength as he breathes, where it used to lie on the ground at full strength and give him away before his body did; on Classic and the old renderer the shadow stays whole. When an enemy detector has found him, his whole body beats amber along with his edge, so a spotted building reads as spotted and does not just turn tan. On every renderer, a stealthed unit of yours no longer comes out solid whenever no building is on the screen: the game drew it a second time without its see-through. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it shows as heat, its own shading run from dark red through orange to a warm yellow that stops short of white, so you can still tell a tank from a soldier and bright GLA paint keeps its detail, with a burning outline and a slow glow climbing it that flares on every sweep of the detector. The fine scan lines of 3.0 are gone, since zoomed out they broke into stripes. Under the black and white view a mission script turns on, or the motion blur, a found enemy and a spotted unit of yours used to come out in plain paint, as if nobody had found them, and a base out of power showed no sign of it; they keep the 2003 heat and tint for those moments now. The see-through parts of a model take the same look as the rest of it, where they used to stay plain. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.
- The first outage, EMP, cloak or detection of a match no longer catches the picture. Each of those looks is a small drawing program of its own on every model it dresses, and until now the game built each one the first time it came on screen, 25 to 60ms of a single frame, so a whole base browning out at once could stack several into one. They come with the game now: a match, both look scenes and the main menu that compiled 61 programs while playing compile none.
- A hidden base no longer burns in plain view. The fire and smoke on a stealthed building or unit, damage flames and chimney smoke alike, kept drawing for the enemy while the building itself was invisible, so a burning Stealth General base under Camo Netting stood out as a column of black smoke on an empty patch of ground. The enemy now sees none of it until a detector finds the building, and then all of it. On your own side the flames and smoke go faint with the building and breathe with it, the fire a little stronger than the smoke, so they no longer sit at full strength beside the glass. This holds on every renderer, and the smoke's shadow and the light its fire throws on nearby smoke go with it. A hit on a hidden unit gives it away no more either: a laser landing on a parked Listening Outpost you had not found threw sparks, a lens flare and a flash of yellow light on the ground round what looked like an empty spot. Now nothing shows until you find it.
- Effects fade out instead of blinking off. The rings a nuke sends across the ground, and any spark, flash or puff whose own colours never reached nothing, used to vanish at full strength on their last frame. Each one now dims away over its last quarter of a second, or over a quarter of its life when it lives shorter than that. One that was already fading looks the way it always did.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index 457a00744..94b7cb054 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -109,11 +109,12 @@ static Bool wearsCloak( const Drawable *draw )
// mines force opacity 0 and must not become a lens on the ground
if( draw->isKindOf( KINDOF_MINE ) )
return FALSE;
- return TRUE;
+ // a frame that cannot draw the cloak (a screen filter holds the target) draws him by opacity
+ return Direct3D11_Takes_Draw_Effect( DRAW_EFFECT_CLOAK );
}
// revealed fades in the translucent pass so the heat can come up from nothing
if( look == STEALTHLOOK_VISIBLE_DETECTED && fade < 0.99f )
- return TRUE;
+ return Direct3D11_Takes_Draw_Effect( DRAW_EFFECT_REVEALED );
return FALSE;
}
@@ -704,6 +705,11 @@ static unsigned chooseDrawEffect( const Drawable *draw, Bool translucentPass, fl
effect = DRAW_EFFECT_OUTAGE;
}
+ // A frame the backend would draw the look in nowhere (a screen filter or a mirror holds the
+ // target, or the device made no copy for the cloak) keeps the heat vision and the tint instead.
+ if ( effect != DRAW_EFFECT_NONE && !Direct3D11_Takes_Draw_Effect( effect ) )
+ return DRAW_EFFECT_NONE;
+
if ( effect != DRAW_EFFECT_NONE )
{
// an hour of seconds keeps the sines' arguments small enough for single precision
@@ -1044,7 +1050,13 @@ void RTS3DScene::Flush(RenderInfoClass & rinfo)
//don't draw transparent in this mode because they interfere with destination alpha
if (m_customPassMode == SCENE_PASS_DEFAULT && Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
+ {
+ // The Direct3D 11 chain's ambient occlusion goes on here, over the world with every
+ // corner in its depth and under the fire and smoke, which write none: put on the
+ // finished frame it shaded a fireball by the chimneys and trees behind it.
+ Direct3D11_Occlude_Scene();
DoParticles(rinfo); //queue up particles for rendering.
+ }
SortingRendererClass::Flush(); //draw sorted translucent polys like particles.
#ifdef DEBUG_LOGGING
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
index 1a3710939..229c380c0 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
@@ -1081,6 +1081,40 @@ void DX11BackendClass::Set_Draw_Effect(unsigned effect, const float parameters[4
}
}
+unsigned DX11BackendClass::Requested_Draw_Effect(float parameters[4]) const
+{
+ if (DrawEffect == DRAW_EFFECT_NONE) {
+ memset(parameters, 0, sizeof(DrawEffectNumbers));
+ } else {
+ memcpy(parameters, DrawEffectNumbers, sizeof(DrawEffectNumbers));
+ }
+ return DrawEffect;
+}
+
+bool DX11BackendClass::Draws_Into_Scene() const
+{
+ return CurrentTarget == NULL && !ShadowMapBound;
+}
+
+/** The black and white view, the motion blur and the cross fade draw the whole scene into a target
+ of their own, and Draw_Effect refuses every look there; asked first, the scene keeps the heat
+ vision and the disabled tint for those frames instead of drawing the object plain. */
+bool DX11BackendClass::Takes_Draw_Effect(unsigned effect)
+{
+ if (!Draws_Into_Scene()) {
+ return false;
+ }
+ return effect != DRAW_EFFECT_CLOAK || Make_Scene_Colour();
+}
+
+void DX11BackendClass::Resume_Scene()
+{
+ const unsigned width = ViewportWidth;
+ const unsigned height = ViewportHeight;
+ Set_Render_Target(NULL);
+ Set_Viewport(0, 0, width, height);
+}
+
/** Which look the current draw takes. Only the scene's own world draws, and in the sun's map only
the cloak's thinned shadow: not a mirror or a filter target, not a screen space quad and not a transcribed program. A draw
adding light (ONE as either factor) takes the outage alone, which puts a building's glow cards
@@ -1127,17 +1161,16 @@ void DX11BackendClass::Release_Scene_Colour()
SceneColourStale = true;
}
-/** The scene's colour for the cloak, copied once a frame at the first cloaked draw: made at the
- scene target's own size and format and made again when a resize changes either. A multisampled
- target cannot be copied into a texture that is read by pixel, so that refuses the cloak. */
-bool DX11BackendClass::Take_Scene_Colour()
+/** The texture the cloak's copy of the scene goes into, made at the scene target's own size and
+ format and made again when a resize changes either. A multisampled target cannot be copied
+ into a texture that is read by pixel, so that refuses the cloak. Asked by the scene for each
+ cloaked object before it decides on the look (Takes_Draw_Effect), so a refusal is known
+ before the first such object goes without its heat vision. */
+bool DX11BackendClass::Make_Scene_Colour()
{
if (SceneColourRefused) {
return false;
}
- if (!SceneColourStale) {
- return true;
- }
ID3D11Resource * source = NULL;
Device->Get_Scene_View()->GetResource(&source);
D3D11_TEXTURE2D_DESC description;
@@ -1174,6 +1207,21 @@ bool DX11BackendClass::Take_Scene_Colour()
return false;
}
}
+ source->Release();
+ return true;
+}
+
+/** The scene's colour for the cloak, copied once a frame at the first cloaked draw. */
+bool DX11BackendClass::Take_Scene_Colour()
+{
+ if (!Make_Scene_Colour()) {
+ return false;
+ }
+ if (!SceneColourStale) {
+ return true;
+ }
+ ID3D11Resource * source = NULL;
+ Device->Get_Scene_View()->GetResource(&source);
Device->Get_Context()->CopyResource(SceneColourCopy, source);
SceneColourStale = false;
++FrameDepthCopies; // counted with the depth copies, so DX11 FRAME COST sees it
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
index 8a090f0fb..dd0d0bbc0 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
@@ -240,6 +240,23 @@ public:
// A draw it does not suit takes none (Draw_Effect).
void Set_Draw_Effect(unsigned effect, const float parameters[4]);
+ // The look Set_Draw_Effect last asked for and its numbers (zeros with none), for the sorting
+ // pool: a sorted mesh is drawn after its object's draws have put the look back to none.
+ unsigned Requested_Draw_Effect(float parameters[4]) const;
+
+ // Whether a look asked for now would be drawn at all, for the scene to ask before it leaves an
+ // object's heat vision pass or disabled tint out for it: only into the scene's own target, not
+ // a screen filter's texture, a mirror or the sun's map, and the cloak only where the device
+ // makes the copy of the scene it bends. A single draw can still refuse one (Draw_Effect).
+ bool Takes_Draw_Effect(unsigned effect);
+
+ // Whether the draws are going into the scene's own target.
+ bool Draws_Into_Scene() const;
+
+ // The scene's target, its depth and the draws' viewport bound again after a pass that bound
+ // its own on the context mid-scene (the post chain's occlusion).
+ void Resume_Scene();
+
// What an additive draw (ONE, ONE) into the scene is worth, for the Glow option: the blend
// takes the draw's colour times this through the blend factor, so fire, muzzle flashes and
// laser cores pass white in the half float scene and the bloom's bright pass finds them, where
@@ -543,6 +560,7 @@ private:
ID3D11ShaderResourceView * SceneColourCopyView;
bool SceneColourStale;
bool SceneColourRefused;
+ bool Make_Scene_Colour();
bool Take_Scene_Colour();
void Release_Scene_Colour();
float AdditiveGain;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index fbe11b0bf..2437d4762 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -348,46 +348,69 @@ static const char * const SHARPEN_SHADER_BODY =
//
// It cannot see behind a surface, so a neighbour nearer by more than the radius is ignored: that is
// a different object in front, not a corner.
-static const char * const AO_SHADER_BODY =
- "static const int AO_TAPS = 12;\n"
- "static const float AO_STRENGTH = 0.45;\n"
- "static const float AO_PI2 = 6.2831853;\n"
+#define AO_OCCLUSION_FUNCTIONS \
+ "static const int AO_TAPS = 12;\n" \
+ "static const float AO_STRENGTH = 0.45;\n" \
+ "static const float AO_PI2 = 6.2831853;\n" \
+ "\n" \
+ "float linear_depth(float2 at)\n" \
+ "{\n" \
+ " float raw = Extra.Sample(Sampler, at).r;\n" \
+ " float near_plane = Tuning.x;\n" \
+ " float far_plane = Tuning.y;\n" \
+ " return near_plane * far_plane / max(far_plane - raw * (far_plane - near_plane), 0.0001);\n" \
+ "}\n" \
+ "\n" \
+ "float occlusion_at(VertexOutput input)\n" \
+ "{\n" \
+ " float centre = linear_depth(input.Texture);\n" \
+ " float radius = Tuning.z;\n" \
+ " if (centre >= Tuning.y * 0.99) return 0.0;\n" \
+ " float turn = frac(sin(dot(input.Position.xy, float2(12.9898, 78.233))) * 43758.5453) * AO_PI2;\n" \
+ " float spread = TexelSize.x * Tuning.w / max(centre, 1.0);\n" \
+ " float occlusion = 0.0;\n" \
+ " for (int tap = 0; tap < AO_TAPS; ++tap)\n" \
+ " {\n" \
+ " float angle = turn + AO_PI2 * (float)tap / (float)AO_TAPS;\n" \
+ " float reach = 0.35 + 0.65 * frac((float)tap * 0.618);\n" \
+ " float2 at = input.Texture + float2(cos(angle), sin(angle)) * spread * reach;\n" \
+ " float neighbour = linear_depth(at);\n" \
+ " float nearer = centre - neighbour;\n" \
+ " occlusion += (nearer > 0.05 && nearer < radius) ? (1.0 - nearer / radius) : 0.0;\n" \
+ " }\n" \
+ " return saturate(occlusion / (float)AO_TAPS);\n" \
+ "}\n" \
"\n"
- "float linear_depth(float2 at)\n"
+
+// The pass over the finished frame, for a frame whose scene never reached Occlude_Scene (a screen
+// filter held the target). Fire, glow and a nuke's cloud are in the frame by now and write no
+// depth, so the depth under them is the ground and the wrecks behind them; darkened by it a white
+// cloud showed every tree and wreck under it as a grey line drawing. Keyed on the dimmest channel:
+// a white cloud has all three high, sunlit sand and concrete keep a low blue and keep their corners.
+// An orange fireball keeps a low blue too, which is why the occlusion normally runs before the
+// particles are drawn at all.
+static const char * const AO_SHADER_BODY =
+ AO_OCCLUSION_FUNCTIONS
+ "float4 main(VertexOutput input) : SV_TARGET\n"
"{\n"
- " float raw = Extra.Sample(Sampler, at).r;\n"
- " float near_plane = Tuning.x;\n"
- " float far_plane = Tuning.y;\n"
- " return near_plane * far_plane / max(far_plane - raw * (far_plane - near_plane), 0.0001);\n"
- "}\n"
- "\n"
+ " float3 scene = Source.Sample(Sampler, input.Texture).rgb;\n"
+ " float bright = min(scene.r, min(scene.g, scene.b));\n"
+ " float occlusion = occlusion_at(input) * (1.0 - smoothstep(0.7, 0.95, bright));\n"
+ " return float4(scene * (1.0 - occlusion * AO_STRENGTH), 1.0);\n"
+ "}\n";
+
+// The same occlusion as a factor the scene target is multiplied by, mid-scene, after the opaque
+// world and before the particles (Occlude_Scene), so no particle takes a corner's shade. The glow
+// cards, muzzle flashes and fading units drawn before it write no depth either, so the key on the
+// dimmest channel stays, read from a copy of the scene.
+static const char * const AO_SCENE_SHADER_BODY =
+ AO_OCCLUSION_FUNCTIONS
"float4 main(VertexOutput input) : SV_TARGET\n"
"{\n"
" float3 scene = Source.Sample(Sampler, input.Texture).rgb;\n"
- " float centre = linear_depth(input.Texture);\n"
- " float radius = Tuning.z;\n"
- " if (centre >= Tuning.y * 0.99) return float4(scene, 1.0);\n"
- " float turn = frac(sin(dot(input.Position.xy, float2(12.9898, 78.233))) * 43758.5453) * AO_PI2;\n"
- " float spread = TexelSize.x * Tuning.w / max(centre, 1.0);\n"
- " float occlusion = 0.0;\n"
- " for (int tap = 0; tap < AO_TAPS; ++tap)\n"
- " {\n"
- " float angle = turn + AO_PI2 * (float)tap / (float)AO_TAPS;\n"
- " float reach = 0.35 + 0.65 * frac((float)tap * 0.618);\n"
- " float2 at = input.Texture + float2(cos(angle), sin(angle)) * spread * reach;\n"
- " float neighbour = linear_depth(at);\n"
- " float nearer = centre - neighbour;\n"
- " occlusion += (nearer > 0.05 && nearer < radius) ? (1.0 - nearer / radius) : 0.0;\n"
- " }\n"
- " occlusion /= (float)AO_TAPS;\n"
- " // Light does not take a corner's shade. Fire, glow and a nuke's cloud write no depth, so\n"
- " // the depth here is the ground and the wrecks behind them, and darkened by it a white cloud\n"
- " // showed every tree and wreck under it as a grey line drawing. Keyed on the dimmest\n"
- " // channel: a white cloud has all three high, sunlit sand and concrete keep a low blue and\n"
- " // keep their corners.\n"
" float bright = min(scene.r, min(scene.g, scene.b));\n"
- " occlusion *= 1.0 - smoothstep(0.7, 0.95, bright);\n"
- " return float4(scene * (1.0 - saturate(occlusion) * AO_STRENGTH), 1.0);\n"
+ " float occlusion = occlusion_at(input) * (1.0 - smoothstep(0.7, 0.95, bright));\n"
+ " return float4((1.0 - occlusion * AO_STRENGTH).xxx, 1.0);\n"
"}\n";
// The bright pass, downsampling as it goes: four taps of the full size frame averaged into one
@@ -611,8 +634,10 @@ DX11PostProcessClass::DX11PostProcessClass()
, BloomBlurShader(NULL)
, BloomCompositeShader(NULL)
, WarpShader(NULL)
+ , SceneOcclusionShader(NULL)
, Sampler(NULL)
, BlendState(NULL)
+ , MultiplyBlendState(NULL)
, DepthState(NULL)
, RasterizerState(NULL)
, ConstantBuffer(NULL)
@@ -624,9 +649,11 @@ DX11PostProcessClass::DX11PostProcessClass()
, TargetsAreFloat(false)
, ShadersReady(false)
, Resolved(false)
+ , Occluded(false)
{
memset(PixelShaders, 0, sizeof(PixelShaders));
memset(&SceneTarget, 0, sizeof(SceneTarget));
+ memset(&SceneCopy, 0, sizeof(SceneCopy));
memset(ChainTargets, 0, sizeof(ChainTargets));
memset(BloomTargets, 0, sizeof(BloomTargets));
memset(Chain, 0, sizeof(Chain));
@@ -664,8 +691,10 @@ void DX11PostProcessClass::Shutdown()
release_interface(reinterpret_cast<IUnknown **>(&ConstantBuffer));
release_interface(reinterpret_cast<IUnknown **>(&RasterizerState));
release_interface(reinterpret_cast<IUnknown **>(&DepthState));
+ release_interface(reinterpret_cast<IUnknown **>(&MultiplyBlendState));
release_interface(reinterpret_cast<IUnknown **>(&BlendState));
release_interface(reinterpret_cast<IUnknown **>(&Sampler));
+ release_interface(reinterpret_cast<IUnknown **>(&SceneOcclusionShader));
release_interface(reinterpret_cast<IUnknown **>(&WarpShader));
release_interface(reinterpret_cast<IUnknown **>(&BloomCompositeShader));
release_interface(reinterpret_cast<IUnknown **>(&BloomBlurShader));
@@ -749,7 +778,8 @@ bool DX11PostProcessClass::Create_Shaders()
&& compile_pixel_shader(compiler, device, BLOOM_BLUR_SHADER_BODY, &BloomBlurShader)
&& compile_pixel_shader(compiler, device, BLOOM_COMPOSITE_SHADER_BODY,
&BloomCompositeShader)
- && compile_pixel_shader(compiler, device, WARP_SHADER_BODY, &WarpShader);
+ && compile_pixel_shader(compiler, device, WARP_SHADER_BODY, &WarpShader)
+ && compile_pixel_shader(compiler, device, AO_SCENE_SHADER_BODY, &SceneOcclusionShader);
}
bool DX11PostProcessClass::Create_States()
@@ -778,6 +808,18 @@ bool DX11PostProcessClass::Create_States()
return false;
}
+ // The scene's colour times the pass's, its alpha kept.
+ blend.RenderTarget[0].BlendEnable = TRUE;
+ blend.RenderTarget[0].SrcBlend = D3D11_BLEND_ZERO;
+ blend.RenderTarget[0].DestBlend = D3D11_BLEND_SRC_COLOR;
+ blend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
+ blend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
+ blend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
+ blend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
+ if (FAILED(device->CreateBlendState(&blend, &MultiplyBlendState))) {
+ return false;
+ }
+
D3D11_DEPTH_STENCIL_DESC depth;
ZeroMemory(&depth, sizeof(depth));
if (FAILED(device->CreateDepthStencilState(&depth, &DepthState))) {
@@ -874,6 +916,7 @@ void DX11PostProcessClass::Release_Target(Target & target)
void DX11PostProcessClass::Release_Targets()
{
Release_Target(SceneTarget);
+ Release_Target(SceneCopy);
const unsigned chain_target_count = sizeof(ChainTargets) / sizeof(ChainTargets[0]);
for (unsigned index = 0; index < chain_target_count; ++index) {
Release_Target(ChainTargets[index]);
@@ -929,6 +972,50 @@ void DX11PostProcessClass::Begin_Frame()
Resolved = false;
}
+void DX11PostProcessClass::Open_Frame()
+{
+ Occluded = false;
+}
+
+bool DX11PostProcessClass::Occlude_Scene(ID3D11ShaderResourceView * depth)
+{
+ if (Occluded || Resolved || !ShadersReady || SceneTarget.View == NULL
+ || Device->Get_Scene_View() != SceneTarget.View) {
+ return false;
+ }
+ bool wanted = false;
+ for (unsigned index = 0; index < ChainLength; ++index) {
+ wanted = wanted || Chain[index] == DX11_POST_AO;
+ }
+ if (!wanted) {
+ return false;
+ }
+ // The pass keys on the scene's colour and cannot read the target it multiplies, so it reads a
+ // copy, made the first time and kept with the other targets.
+ if (SceneCopy.Texture == NULL
+ && !Create_Target(SceneCopy, Width, Height, TargetsAreFloat ? FLOAT_FORMAT : EIGHT_BIT_FORMAT)) {
+ Release_Target(SceneCopy);
+ return false;
+ }
+ Device->Get_Context()->CopyResource(SceneCopy.Texture, SceneTarget.Texture);
+
+ PassSetup pass;
+ memset(&pass, 0, sizeof(pass));
+ pass.Shader = SceneOcclusionShader;
+ pass.Source = SceneCopy.Resource;
+ pass.Extra = depth;
+ pass.Occlusion = true;
+ pass.Multiply = true;
+ pass.Destination = SceneTarget.View;
+ pass.DestinationWidth = Width;
+ pass.DestinationHeight = Height;
+ pass.SourceWidth = Width;
+ pass.SourceHeight = Height;
+ Draw_Pass(pass);
+ Occluded = true;
+ return true;
+}
+
void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
{
ID3D11DeviceContext * context = Device->Get_Context();
@@ -992,7 +1079,8 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
context->RSSetViewports(1, &viewport);
const float blend_factor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
- context->OMSetBlendState(BlendState, blend_factor, 0xffffffff);
+ context->OMSetBlendState(pass.Multiply ? MultiplyBlendState : BlendState, blend_factor,
+ 0xffffffff);
context->OMSetDepthStencilState(DepthState, 0);
context->RSSetState(RasterizerState);
@@ -1153,7 +1241,22 @@ bool DX11PostProcessClass::Finish(const DX11PostEffect * effects, unsigned count
bool DX11PostProcessClass::Run_Chain()
{
- return Finish(Chain, ChainLength);
+ if (!Occluded) {
+ return Finish(Chain, ChainLength);
+ }
+ // The scene took its occlusion before the particles; a chain of nothing else still has to
+ // bring the scene to the screen.
+ DX11PostEffect effects[DX11_POST_CHAIN_LIMIT];
+ unsigned count = 0;
+ for (unsigned index = 0; index < ChainLength; ++index) {
+ if (Chain[index] != DX11_POST_AO) {
+ effects[count++] = Chain[index];
+ }
+ }
+ if (count == 0) {
+ effects[count++] = DX11_POST_COPY;
+ }
+ return Finish(effects, count);
}
bool DX11PostProcessClass::Copy_Through()
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 19899abf7..031cb8b89 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -191,6 +191,16 @@ public:
// Call at the top of a frame. Arms the two above again.
void Begin_Frame();
+ // The chain's ambient occlusion multiplied into the scene target as it stands, out of the depth
+ // given, when "ao" is in the chain and the scene is going into this chain's target. Once a
+ // frame: the chain leaves its own occlusion pass out after it. The caller binds its target,
+ // depth and viewport again afterwards. False when it drew nothing.
+ bool Occlude_Scene(ID3D11ShaderResourceView * depth);
+
+ // 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();
+
// One line for the shutdown report: the chain, the size of the buffers, and the reason there is
// no chain if there is not one.
const char * Diagnostic_Line() const { return Diagnostic; }
@@ -226,6 +236,8 @@ private:
// The scene came down without a match finishing it (the loading screen, interface and all
// drawn into the scene target): the tone curve, but never the lighting style's grade.
bool Ungraded;
+ // The pass's colour multiplies what the destination holds instead of replacing it.
+ bool Multiply;
};
bool Create_Shaders();
@@ -248,8 +260,10 @@ private:
ID3D11PixelShader * BloomBlurShader;
ID3D11PixelShader * BloomCompositeShader;
ID3D11PixelShader * WarpShader;
+ ID3D11PixelShader * SceneOcclusionShader;
ID3D11SamplerState * Sampler;
ID3D11BlendState * BlendState;
+ ID3D11BlendState * MultiplyBlendState;
ID3D11DepthStencilState * DepthState;
ID3D11RasterizerState * RasterizerState;
ID3D11Buffer * ConstantBuffer;
@@ -258,6 +272,8 @@ private:
// turn, and they are always eight bit: the frame is back from half float by the time any of the
// one pass effects sees it.
Target SceneTarget;
+ // The scene as Occlude_Scene found it, in its format, made at that pass's first use.
+ Target SceneCopy;
Target ChainTargets[2];
Target BloomTargets[2];
@@ -274,6 +290,8 @@ private:
bool TargetsAreFloat;
bool ShadersReady;
bool Resolved;
+ // Occlude_Scene ran this frame, so Finish leaves the occlusion pass out.
+ bool Occluded;
char Diagnostic[192];
};
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index 45cbf8277..cb0d929b6 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -636,6 +636,27 @@ bool Direct3D11_Draw_Effects()
return Active && DrawEffectsAllowed;
}
+bool Direct3D11_Takes_Draw_Effect(unsigned effect)
+{
+ return Active && DrawEffectsAllowed && Backend.Takes_Draw_Effect(effect);
+}
+
+unsigned Direct3D11_Requested_Draw_Effect(float parameters[4])
+{
+ if (Active && DrawEffectsAllowed) {
+ return Backend.Requested_Draw_Effect(parameters);
+ }
+ parameters[0] = parameters[1] = parameters[2] = parameters[3] = 0.0f;
+ return 0;
+}
+
+void Direct3D11_Occlude_Scene()
+{
+ if (Active && Backend.Draws_Into_Scene() && Post.Occlude_Scene(Device.Get_Depth_Texture())) {
+ Backend.Resume_Scene();
+ }
+}
+
void Direct3D11_Allow_Draw_Effects(bool allowed)
{
DrawEffectsAllowed = allowed;
@@ -807,6 +828,7 @@ void Direct3D11_Begin_Scene()
// first of them is the top of the frame.
if (!FrameOpen) {
begin_frame();
+ Post.Open_Frame();
}
// Before the backend binds anything: the scene goes wherever this says it goes, and a frame
// that asked for a chain and could not have one falls back to the swap chain here rather
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
index cf005a5aa..813bacee0 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
@@ -177,10 +177,24 @@ void Direct3D11_Set_Smoke_Glow(bool glow);
void Direct3D11_Set_Draw_Effect(unsigned effect, const float parameters[4]);
// Whether the looks are drawn at all: a Direct3D 11 frame is presenting and the Classic graphics
-// setting is off. The scene asks before it leaves the heat vision pass out for one of them.
+// setting is off.
bool Direct3D11_Draw_Effects();
void Direct3D11_Allow_Draw_Effects(bool allowed);
+// Whether one look asked for now would be drawn (DX11BackendClass::Takes_Draw_Effect). The scene
+// asks before it leaves the heat vision pass or the disabled tint out for it.
+bool Direct3D11_Takes_Draw_Effect(unsigned effect);
+
+// The look the mesh renderer has set and its numbers, zero and zeros with none. The sorting pool
+// keeps it with a sorted mesh's triangles and sets it again when it draws them.
+unsigned Direct3D11_Requested_Draw_Effect(float parameters[4]);
+
+// The post chain's ambient occlusion, applied to the scene where it stands, once a frame: called
+// after the opaque world and before the particles, so fire and smoke, which write no depth, are
+// not shaded by the corners of what is behind them. The chain then skips its own occlusion pass.
+// Nothing happens without "ao" in the chain or while a filter or a mirror holds the target.
+void Direct3D11_Occlude_Scene();
+
// 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 d8d0f967f..ee2261d72 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
@@ -78,6 +78,13 @@ void Direct3D11_Set_Smoke_Glow(bool) {}
void Direct3D11_Set_Draw_Effect(unsigned, const float [4]) {}
bool Direct3D11_Draw_Effects() { return false; }
void Direct3D11_Allow_Draw_Effects(bool) {}
+bool Direct3D11_Takes_Draw_Effect(unsigned) { return false; }
+unsigned Direct3D11_Requested_Draw_Effect(float parameters[4])
+{
+ parameters[0] = parameters[1] = parameters[2] = parameters[3] = 0.0f;
+ return 0;
+}
+void Direct3D11_Occlude_Scene() {}
void Direct3D11_Set_Glow_Draw(bool) {}
void Direct3D11_Set_Scene_Stand_In(struct IDirect3DBaseTexture9 *, struct IDirect3DSurface9 *) {}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp
index 697c1bfe0..52411b50f 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp
@@ -1917,7 +1917,8 @@ void DX8TextureCategoryClass::Render(void)
if (!DX8RendererDebugger::Is_Enabled() || !mesh->Is_Disabled_By_Debugger()) {
// The object's look on the Direct3D 11 frame (RTS3DScene::renderOneObject picks it), for this
- // mesh's draws only. A sorted mesh draws later, from the sorting pool, and goes without.
+ // mesh's draws only. A sorted mesh draws later, from the sorting pool, which keeps the look
+ // with its triangles (SortingRendererClass::Insert_Triangles).
const unsigned draw_effect = mesh->Get_Draw_Effect();
if (draw_effect != 0) {
Direct3D11_Set_Draw_Effect(draw_effect, mesh->Get_Draw_Effect_Parameters());
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
index ce0429dca..f603d219b 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
@@ -149,8 +149,26 @@ public:
unsigned short vertex_count; // Number of vertices used in vb
bool quads; // four vertices a quad, in order from min_vertex_index; the ib is not read
bool glow; // the normals hold a fire's glow (Insert_Quads)
+ // The object's Direct3D 11 look (RTS3DScene::renderOneObject) as the mesh renderer had it set
+ // when a sorted mesh queued its triangles; its draws come later, after the look is put back.
+ unsigned draw_effect;
+ float draw_effect_parameters[4];
};
+// Whether two nodes are drawn in the same look; the numbers differ per object.
+static bool Same_Draw_Effect(const SortingNodeStruct* a,const SortingNodeStruct* b)
+{
+ return a->draw_effect==b->draw_effect
+ && (a->draw_effect==0 || memcmp(a->draw_effect_parameters,b->draw_effect_parameters,sizeof(a->draw_effect_parameters))==0);
+}
+
+static void No_Draw_Effect(SortingNodeStruct* state)
+{
+ state->draw_effect=0;
+ state->draw_effect_parameters[0]=state->draw_effect_parameters[1]=0.0f;
+ state->draw_effect_parameters[2]=state->draw_effect_parameters[3]=0.0f;
+}
+
static DLListClass<SortingNodeStruct> sorted_list;
// Nodes that arrive with no bounding sphere have nothing to sort by; they wait here and go into
// the sorted list in one piece at flush time, instead of each walking it looking for a place.
@@ -234,6 +252,7 @@ void SortingRendererClass::Insert_Triangles(
state->vertex_count=vertex_count;
state->quads=false;
state->glow=false;
+ state->draw_effect=Direct3D11_Requested_Draw_Effect(state->draw_effect_parameters);
SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);
WWASSERT(vertex_buffer);
@@ -345,6 +364,7 @@ void SortingRendererClass::Insert_Quads(
state->vertex_count=vertex_count;
state->quads=true;
state->glow=glow;
+ No_Draw_Effect(state);
state->transformed_center=Vector3(0.0f,0.0f,0.0f);
unsorted_list.Add_Tail(state);
}
@@ -716,11 +736,12 @@ static void Flush_Sorting_Batch(const TempIndexStruct* entries,unsigned entry_co
SortingNodeStruct* next=overlapping_nodes[entry_node];
// A run of billboards fades into the depth behind it and a run of meshes does not, so the
// two never share a draw even in one state.
- if (state->glow!=next->glow || state->quads!=next->quads ||
+ if (state->glow!=next->glow || state->quads!=next->quads || !Same_Draw_Effect(state,next) ||
!Same_Draw_State(state->sorting_state,next->sorting_state)) {
Apply_Render_State(state->sorting_state);
Direct3D11_Set_Smoke_Glow(state->glow);
Direct3D11_Set_Soft_Particles(state->quads);
+ Direct3D11_Set_Draw_Effect(state->draw_effect,state->draw_effect_parameters);
DX8Wrapper::Draw_Triangles(run_first_index,run_triangles,run_first_vertex,vertex_cursor-run_first_vertex);
run_first_index=index_cursor;
run_first_vertex=vertex_cursor;
@@ -736,9 +757,12 @@ static void Flush_Sorting_Batch(const TempIndexStruct* entries,unsigned entry_co
Apply_Render_State(overlapping_nodes[node_id]->sorting_state);
Direct3D11_Set_Smoke_Glow(overlapping_nodes[node_id]->glow);
Direct3D11_Set_Soft_Particles(overlapping_nodes[node_id]->quads);
+ Direct3D11_Set_Draw_Effect(overlapping_nodes[node_id]->draw_effect,overlapping_nodes[node_id]->draw_effect_parameters);
DX8Wrapper::Draw_Triangles(run_first_index,run_triangles,run_first_vertex,vertex_cursor-run_first_vertex);
Direct3D11_Set_Smoke_Glow(false);
Direct3D11_Set_Soft_Particles(false);
+ static const float no_effect[4]={0.0f,0.0f,0.0f,0.0f};
+ Direct3D11_Set_Draw_Effect(0,no_effect);
tDrawEnd = Clock_Ticks();
flush_profile_draw_ms += flushProfileElapsedMS(tCopyEnd, tDrawEnd);
@@ -1058,6 +1082,7 @@ void SortingRendererClass::Insert_VolumeParticle(
state->vertex_count=vertex_count * layerCount;//THIS IS VOLUME_PARTICLE SPECIFIC
state->quads=false;
state->glow=false;
+ No_Draw_Effect(state);
SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);
WWASSERT(vertex_buffer);
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index 4561109a7..8398602e5 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -635,3 +635,55 @@ TEST(dx11post_resolves_once_a_frame)
delete [] first;
delete [] second;
}
+
+TEST(dx11post_the_scene_takes_its_occlusion_once_a_frame_and_the_chain_then_skips_it)
+{
+ DeviceFixture fixture;
+ if (!fixture.Create()) {
+ printf("skip: no Direct3D 11 device on this machine\n");
+ return;
+ }
+ DX11DeviceClass & device = fixture.Get_Device();
+ DX11PostProcessClass & post = fixture.Get_Post();
+
+ // Nothing to do without ao in the chain.
+ const DX11PostEffect copy_only[] = { DX11_POST_COPY };
+ post.Set_Chain(copy_only, 1);
+ post.Open_Frame();
+ post.Begin_Frame();
+ device.Set_Scene_View(post.Scene_View());
+ CHECK(!post.Occlude_Scene(device.Get_Depth_Texture()));
+
+ // With it, once a frame, and the chain of ao alone still brings the scene to the screen. The
+ // depth is all far plane, so nothing is occluded and the multiply has to give every pixel back.
+ unsigned char * picture = new unsigned char[SURFACE_SIZE * SURFACE_SIZE * BYTES_A_PIXEL];
+ fill_diagonal(picture);
+ const DX11PostEffect ao_only[] = { DX11_POST_AO };
+ post.Set_Chain(ao_only, 1);
+ post.Open_Frame();
+ post.Begin_Frame();
+ device.Set_Scene_View(post.Scene_View());
+ device.Get_Context()->ClearDepthStencilView(device.Get_Depth_Stencil_View(), D3D11_CLEAR_DEPTH,
+ 1.0f, 0);
+ CHECK(write_scene(device, post, picture));
+ CHECK(post.Occlude_Scene(device.Get_Depth_Texture()));
+ CHECK(!post.Occlude_Scene(device.Get_Depth_Texture()));
+ CHECK(post.Run_Chain());
+ unsigned pitch = 0;
+ unsigned char * result = read_back_buffer(device, pitch);
+ CHECK(result != NULL);
+ if (result != NULL) {
+ CHECK_EQ(0u, differing_pixels(picture, result, pitch));
+ delete [] result;
+ }
+
+ // A Begin_Frame alone (a mirror's scene, then the frame's own) does not arm it again; the top of
+ // the next frame does.
+ post.Begin_Frame();
+ CHECK(!post.Occlude_Scene(device.Get_Depth_Texture()));
+ post.Open_Frame();
+ CHECK(post.Occlude_Scene(device.Get_Depth_Texture()));
+
+ device.Set_Scene_View(NULL);
+ delete [] picture;
+}