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): atmosphere option, far ground fades into a sky

Olcay Seyganf360c04b55ff
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a0c06003..81d369b6c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## A sky over the map
+
+- Atmosphere, under Options, Graphics, is a new setting, off by default until it has been played. Tilt the camera flat or fly it low in a replay and EA's game ran out of world: black above the skyline, black past the map's edge, a far plane that cut the ground off in a line. With this on there is a sky, EA's own clouds, sunset or stars by the map's hour, the ground far from the camera fades toward its colour, and the black ring past the map goes into the same haze. Your fog of war stays as dark as it was, the ground near the camera stays clear, and nothing moves but your camera. Your opponent's setting is his own, because no part of the game reads this. A battle of three armies and three superweapons takes the graphics card's frame from about 8.0 to 8.2 ms. Direct3D 11 only, and off under Classic Graphics.
+
## Shells land in water
- Water Splashes, under Options, Effects, is a new setting, off by default until it has been played. EA's shells burst on a river as they burst on sand: a fireball and nothing on the water. With this on, a shell or a bomb that comes down in water throws up spray, leaves a patch of foam and sends two rings across the surface, dimmed by the map's light at night. On the wet sand at the water's edge you get the spray alone, since a ring lying on a beach looks like glass. Your opponent's setting is his own, because no part of the game reads this. Fifteen guns shelling one channel without a pause, more than a match ever puts in water, take the graphics card's frame from about 2.45 to 2.64 ms and the slowest frames from about 13 to 15 ms. Direct3D 11 and Classic water only, and off under Classic Graphics.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index bf6932e82..e141f97d6 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1556,6 +1556,14 @@ TOOLTIP:WaterSplashes
"A shell, a bomb or a falling body that comes down in water throws up a splash and sends rings across the surface. Only your picture changes: nothing in the game reads it, and other players see their own setting. Direct3D 11 and Classic water only, and off under Classic Graphics. Applies when you press Accept."
END
+GUI:Atmosphere
+"Atmosphere"
+END
+
+TOOLTIP:Atmosphere
+"The ground far from the camera fades toward the sky's colour, and where the map ends or the camera lies flat you see a sky by the map's time of day instead of black. The ground near the camera stays clear and fog of war keeps its dark. Only your picture changes: nothing in the game reads it, and other players see their own setting. Direct3D 11 only, and off under Classic Graphics."
+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 b4fde8ef5..61ed90360 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15949,6 +15949,14 @@ TOOLTIP:WaterSplashes
"Suya düşen mermi, bomba ya da ceset su sıçratır ve yüzeyde halkalar yayar. Değişen sadece sizin görüntünüzdür: oyunda hiçbir şey bunu okumaz, diğer oyuncular kendi ayarını görür. Yalnızca Direct3D 11 ve Klasik su ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
END
+GUI:Atmosphere
+"Atmosfer"
+END
+
+TOOLTIP:Atmosphere
+"Kameradan uzak zemin gökyüzünün rengine doğru solar; haritanın bittiği yerde ya da kamera yatık durduğunda siyah yerine haritanın saatine uygun bir gökyüzü görünür. Kameraya yakın zemin temiz kalır, savaş sisi karanlığını korur. Değişen sadece sizin görüntünüzdür: oyunda hiçbir şey bunu okumaz, diğer oyuncular kendi ayarını görür. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdı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 9b717c78d..73e6f3b0b 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
@@ -4578,6 +4578,53 @@ WINDOW
IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
END
CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 288 434, BOTTOMRIGHT: 512 458, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckAtmosphere";
+ 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:Atmosphere";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:Atmosphere";
+ 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 = STATICTEXT;
SCREENRECT = UPPERLEFT: 530 150, BOTTOMRIGHT: 754 174, CREATIONRESOLUTION: 800 600;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index b4298d6ec..387b1fb7a 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -712,6 +712,7 @@ public:
Bool m_ambientOcclusion; ///< "AmbientOcclusion": corners and the ground under what stands on it darken, half size in world units (Direct3D 11, client only)
Bool m_weatherEffects; ///< "Weather": rain, blowing sand or snow by the map's ground, and a wind on trees and smoke (Direct3D 11, client only)
Bool m_waterSplashes; ///< "WaterSplashes": a splash and rings where a blast or a falling body meets water (Direct3D 11, client only)
+ Bool m_atmosphere; ///< "Atmosphere": the far ground fades toward the horizon and an empty frame takes a sky (Direct3D 11, client only)
Bool m_internalHdr; ///< "InternalHdr": what passes white in the half float scene keeps its colour on the way to eight bits; no HDR monitor output (Direct3D 11, client only)
Int m_maxParticleCount; ///< maximum number of particles that can exist
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 55cc157ad..abc24e58f 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1141,6 +1141,7 @@ GlobalData::GlobalData()
m_ambientOcclusion = FALSE;
m_weatherEffects = FALSE;
m_waterSplashes = FALSE;
+ m_atmosphere = FALSE;
m_internalHdr = 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 c0f50b17c..50a41e957 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -148,6 +148,7 @@ OPTION_BOOL_ACCESSORS( m_hemiAmbient )
OPTION_BOOL_ACCESSORS( m_ambientOcclusion )
OPTION_BOOL_ACCESSORS( m_weatherEffects )
OPTION_BOOL_ACCESSORS( m_waterSplashes )
+OPTION_BOOL_ACCESSORS( m_atmosphere )
OPTION_BOOL_ACCESSORS( m_internalHdr )
OPTION_INT_ACCESSORS( m_shadowQuality )
OPTION_INT_ACCESSORS( m_graphicsQuality )
@@ -660,6 +661,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_waterSplashes, set_m_waterSplashes },
+ // The far ground fades toward the horizon and what the frame left empty takes a sky. Read every frame,
+ // and no sim reads it. Off under Classic graphics and -d3d9, and no row in the quality table: an opt-in
+ // until it has been seen. On Options > Graphics, under Warm Light: Effects is full.
+ { "Atmosphere", OPT_WND( "CheckAtmosphere" ), "GUI:Atmosphere",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_atmosphere, set_m_atmosphere },
+
// What passes white keeps its colour on the way to the eight bit screen; no HDR monitor output. The
// post chain is told every frame. Classic graphics has no half float scene and -d3d9 no chain, and
// no row in the quality table: an opt-in until it has been seen. On Options > Effects.
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 9fae6503a..212ee0fd6 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", "AmbientOcclusion", "InternalHdr", "Weather", "WaterSplashes" };
+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient", "AmbientOcclusion", "InternalHdr", "Weather", "WaterSplashes", "Atmosphere" };
for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )
findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
index 1097d89e4..4c888057b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
@@ -139,6 +139,7 @@ public:
Real getWaterHeight(Real x, Real y); ///<return water height at given point - for use by WB.
void replaceSkyboxTexture(const AsciiString& oldTexName, const AsciiString& newTextName);
+ TextureClass *getSkyTexture(void) const { return m_settings[m_tod].skyTexture; } ///< the time of day's sky, as WaterSet names it
Bool hasModernVesselFoam(UnsignedInt objectID) const; ///< replacement was submitted for this hull in the current render frame
Bool isModernWaterMirrorForOwner(UnsignedInt objectID) const; ///< owner's surface foam must not reflect back into the same water plane
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index 57e0984cc..a8dbd009b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -1464,7 +1464,13 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )
if (TheW3DVolumetricShadowManager != NULL && m_customPassMode == SCENE_PASS_DEFAULT &&
!ShaderClass::Is_Backface_Culling_Inverted() &&
Get_Extra_Pass_Polygon_Mode() == EXTRA_PASS_DISABLE)
+ {
TheW3DVolumetricShadowManager->renderShadowMap(rinfo.Camera);
+ // Before the frame for the same reason: it has to lie under all of it. The pass above has just
+ // handed the backend the camera it needs.
+ if (TheGlobalData->m_atmosphere)
+ Direct3D11_Atmosphere_Sky();
+ }
Int localPlayerIndex = ThePlayerList ? TheObserverCamera.getShroudPlayerIndex() : 0;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index 50cdf1001..68c582f3f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -66,6 +66,7 @@
#include "W3DDevice/GameClient/HeightMap.h"
#include "W3DDevice/GameClient/W3DCustomScene.h"
#include "W3DDevice/GameClient/W3DSmudge.h"
+#include "W3DDevice/GameClient/W3DWater.h"
#include "GameClient/View.h"
#include "GameClient/Snow.h"
#include "GameClient/CommandXlat.h"
@@ -410,6 +411,65 @@ static void pushWeatherHaze(void)
const float up[3] = { 0.0f, 0.0f, 1.0f };
DX11Post_Set_Haze(colour, 1.0e5f, 1.0f, strength, PROTO_HAZE_REACH, -1.0e6f, up, 0.0f);
}
+
+/* The Atmosphere option (DX11Post_Set_Atmosphere). The horizon's colour goes by the time of day, scaled by
+ the map's own light as the weather's haze is, so a map with a dim or tinted sun gets the sky that goes
+ with it; under the Weather option it is the weather's colour. A map whose script drew EA's skybox keeps
+ that, and the isometric camera has no far ground to fade. */
+static const Real ATMOSPHERE_START = 500.0f; // the least eye distance the fade starts at
+static const Real ATMOSPHERE_SCALE = 2200.0f; // how far past it the fade takes to reach about two thirds
+static const Real ATMOSPHERE_STRENGTH = 0.85f; // the most of the horizon's colour the far ground takes
+static const Real ATMOSPHERE_SKY_FLOOR = 0.7f; // a night's sky keeps this much, or the stars go
+static const float ATMOSPHERE_HORIZON[TIME_OF_DAY_COUNT][3] = {
+ { 0.72f, 0.80f, 0.90f }, // invalid, as afternoon
+ { 0.80f, 0.80f, 0.84f }, // morning
+ { 0.72f, 0.80f, 0.90f }, // afternoon
+ { 0.80f, 0.58f, 0.44f }, // evening
+ { 0.07f, 0.10f, 0.18f } }; // night
+
+static void pushAtmosphere(Bool weatherHaze)
+{
+ static Bool s_on = FALSE;
+ const Bool on = TheGlobalData->m_atmosphere && !TheGlobalData->m_classicGraphics && Direct3D11_Present_Is_Enabled()
+ && !TheGlobalData->m_drawSkyBox && !TheGlobalData->m_isometricCamera
+ && TheTerrainRenderObject != NULL && TheTerrainRenderObject->getMap() != NULL
+ && TheWaterRenderObj != NULL && TheWaterRenderObj->getSkyTexture() != NULL;
+ if (on)
+ {
+ const GlobalData::TerrainLighting &sun = TheGlobalData->m_terrainLighting[TheGlobalData->m_timeOfDay][0];
+ const float light[3] = { min(sun.ambient.red + sun.diffuse.red, 1.0f), min(sun.ambient.green + sun.diffuse.green, 1.0f),
+ min(sun.ambient.blue + sun.diffuse.blue, 1.0f) };
+ float horizon[3];
+ float tint[3];
+ for (Int i = 0; i < 3; ++i)
+ {
+ horizon[i] = ATMOSPHERE_HORIZON[TheGlobalData->m_timeOfDay][i] * light[i];
+ tint[i] = max(light[i], ATMOSPHERE_SKY_FLOOR);
+ }
+ if (weatherHaze)
+ {
+ Real strength;
+ TheSnowManager->getWeatherHaze(horizon, &strength);
+ memcpy(tint, horizon, sizeof(tint));
+ }
+ TextureClass *sky = TheWaterRenderObj->getSkyTexture();
+ if (!sky->Is_Initialized())
+ sky->Init();
+ // The ground under the focus, at the map's lowest: a height at the focus would pulse the fade as
+ // the camera scrolled over a ridge, and reading the logic's is a read inside the overlap window.
+ WorldHeightMap *map = TheTerrainRenderObject->getMap();
+ Direct3D11_Set_Atmosphere(horizon, tint, ATMOSPHERE_START, ATMOSPHERE_SCALE, ATMOSPHERE_STRENGTH,
+ TheTerrainRenderObject->getMinHeight(),
+ (map->getXExtent() - 1 - map->getBorderSizeInline() * 2) * MAP_XY_FACTOR,
+ (map->getYExtent() - 1 - map->getBorderSizeInline() * 2) * MAP_XY_FACTOR, sky->Peek_D3D_Base_Texture());
+ }
+ else if (s_on)
+ {
+ const float none[3] = { 0.0f, 0.0f, 0.0f };
+ DX11Post_Set_Atmosphere(none, none, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, NULL);
+ }
+ s_on = on;
+}
#endif
void W3DShaderManager::pushProtoHaze(void)
@@ -431,7 +491,8 @@ void W3DShaderManager::pushProtoHaze(void)
DX11Post_Set_Haze(none, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, none, 0.0f);
}
s_hazed = weatherHaze || TheGlobalData->m_mapLight;
- if ((TheGlobalData->m_mapLight || TheGlobalData->m_ambientOcclusion || weatherHaze) && Direct3D11_Is_Active())
+ pushAtmosphere(weatherHaze);
+ if ((TheGlobalData->m_mapLight || TheGlobalData->m_ambientOcclusion || TheGlobalData->m_atmosphere || weatherHaze) && Direct3D11_Is_Active())
pushShroudFrame();
#endif
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index 1527dbc6d..449a502de 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -163,6 +163,26 @@ void DX11Post_Set_Haze_Shroud(ID3D11ShaderResourceView * view, const float rect[
memcpy(HazeShroudRect, rect, sizeof(HazeShroudRect));
}
+static float AtmosphereHorizon[3] = { 0.0f, 0.0f, 0.0f };
+static float AtmosphereTint[3] = { 0.0f, 0.0f, 0.0f };
+static float AtmosphereFade[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
+static float AtmosphereMapSize[2] = { 0.0f, 0.0f };
+static ID3D11ShaderResourceView * AtmosphereSky = NULL;
+
+void DX11Post_Set_Atmosphere(const float horizon[3], const float tint[3], float start, float scale,
+ float strength, float ground, float map_width, float map_height, ID3D11ShaderResourceView * sky)
+{
+ AtmosphereMapSize[0] = map_width;
+ AtmosphereMapSize[1] = map_height;
+ memcpy(AtmosphereHorizon, horizon, sizeof(AtmosphereHorizon));
+ memcpy(AtmosphereTint, tint, sizeof(AtmosphereTint));
+ AtmosphereFade[0] = start;
+ AtmosphereFade[1] = scale;
+ AtmosphereFade[2] = strength;
+ AtmosphereFade[3] = ground;
+ AtmosphereSky = sky;
+}
+
static DX11PostWarp Warps[DX11_POST_WARP_LIMIT];
static unsigned WarpCount = 0;
@@ -764,6 +784,110 @@ static const char * const HAZE_SHADER_BODY =
" return float4(colour, saturate(amount));\n"
"}\n";
+// The Atmosphere option's two programs. Their constants lie in the haze's slots, the pass writes them
+// over for these draws (PassSetup::Atmosphere): c13 is the fade's start, scale, strength and ground
+// height, c14 the horizon, c21 the map's size, and BlurDirection the sky's tint.
+#define ATMOSPHERE_CONSTANTS \
+ "cbuffer AtmosphereConstants : register(b1)\n" \
+ "{\n" \
+ " float4 Fade : packoffset(c13);\n" \
+ " float4 Horizon : packoffset(c14);\n" \
+ " row_major float4x4 WorldFromClip : packoffset(c15);\n" \
+ " float4 HazeSun : packoffset(c19);\n" \
+ " float4 HazeShroudRect : packoffset(c20);\n" \
+ " float4 MapSize : packoffset(c21);\n" \
+ "};\n" \
+ "static const float BELOW_DIM = 0.55;\n" \
+ "static const float BELOW_REACH = 0.25;\n" \
+ "\n" \
+ "float3 haze_along(float up)\n" \
+ "{\n" \
+ " return Horizon.rgb * lerp(BELOW_DIM, 1.0, saturate(1.0 + up / BELOW_REACH));\n" \
+ "}\n" \
+ "\n" \
+ "float3 world_at(float2 ndc, float raw)\n" \
+ "{\n" \
+ " float4 world = mul(float4(ndc, raw, 1.0), WorldFromClip);\n" \
+ " return world.xyz / world.w;\n" \
+ "}\n" \
+ "\n"
+
+// The sky, over the whole frame before anything is drawn on it, so whatever the frame leaves empty holds
+// it and there is no depth to read: water and glass past the ground blend over it, and a multisampled
+// edge resolves between it and what stands in front. Painted later out of the depth, it took the water
+// past the terrain's window and left black samples on every skyline under MSAA. The eye's ray reads
+// EA's own time of day texture from WaterSet, on a plane overhead, opening out of the horizon's colour.
+// Below the horizon, past the map's edge or past the far plane, the ray takes that colour dimming the
+// further down it looks, not the black a frame clears to and not one flat sheet of it; the ground's fade
+// takes the same colour by the same ray, so the two meet with no line.
+static const char * const SKY_SHADER_BODY =
+ ATMOSPHERE_CONSTANTS
+ "Texture2D Sky : register(t3);\n"
+ "SamplerState SkySampler : register(s1);\n"
+ "static const float SKY_REPEAT = 0.35;\n"
+ "static const float SKY_OPEN = 0.30;\n"
+ "\n"
+ "float4 main(VertexOutput input) : SV_TARGET\n"
+ "{\n"
+ " float2 ndc = float2(input.Texture.x * 2.0 - 1.0, 1.0 - input.Texture.y * 2.0);\n"
+ " float3 ray = world_at(ndc, 1.0) - world_at(ndc, 0.0);\n"
+ " float reach = max(length(ray), 0.0001);\n"
+ " float up = ray.z / reach;\n"
+ " float open = smoothstep(0.0, SKY_OPEN, up);\n"
+ " float2 plane = ray.xy / (max(up, 0.05) * reach) * SKY_REPEAT;\n"
+ " float3 sky = Sky.SampleLevel(SkySampler, plane, 3.0 * (1.0 - open)).rgb * BlurDirection.rgb;\n"
+ " return float4(lerp(haze_along(up), sky, open), 1.0);\n"
+ "}\n";
+
+// The fade, blended over the scene target by its alpha after the haze. It goes by eye distance past a
+// start, and nothing reads the clock, so only the camera shifts it. The start is the eye's distance to
+// its focus and a little over, and never less than the constant: at the game's own tilt the middle of
+// the frame and below it stay clean at any zoom, and only the ground beyond fades. The focus has a
+// ceiling, or a camera near level would push the start past all the far ground, and jump as it crossed
+// level. Over the last of the far plane's depth it closes to the horizon whatever the shroud says, or
+// the far plane's cut shows as a line. Short of that the colour takes the shroud's light (t2, what the
+// terrain multiplied by), so fogged ground comes out the same fade as ground in sight times that light
+// and black ground stays black. Cutting the amount by the light as the haze does kept the fog dark
+// 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
+// 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
+// had a black line across the whole frame. Depth is Load: filtered across a skyline it is a distance nothing
+// stands at. Under MSAA it is one sample's for the whole pixel; the fade is gentle enough there that the
+// edge does not show it.
+static const char * const ATMOSPHERE_SHADER_BODY =
+ ATMOSPHERE_CONSTANTS
+ "Texture2D Shroud : register(t2);\n"
+ "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"
+ "\n"
+ "float4 main(VertexOutput input) : SV_TARGET\n"
+ "{\n"
+ " float raw = Extra.Load(int3(input.Position.xy, 0)).r;\n"
+ " float2 ndc = float2(input.Texture.x * 2.0 - 1.0, 1.0 - input.Texture.y * 2.0);\n"
+ " float3 eye = world_at(ndc, 0.0);\n"
+ " float3 ray = world_at(ndc, raw) - eye;\n"
+ " float reach = length(ray);\n"
+ " if (raw >= 1.0) return float4(haze_along(ray.z / max(reach, 0.0001)), ray.z < 0.0 ? 1.0 : 0.0);\n"
+ " float3 centreEye = world_at(float2(0.0, 0.0), 0.0);\n"
+ " float3 axis = world_at(float2(0.0, 0.0), 1.0) - centreEye;\n"
+ " float axisLength = length(axis);\n"
+ " float focus = (axis.z < 0.0) ? min((Fade.w - centreEye.z) / axis.z * axisLength, FOCUS_MOST) : FOCUS_MOST;\n"
+ " float past = max(reach - max(focus * FOCUS_MARGIN, Fade.x), 0.0);\n"
+ " float amount = Fade.z * (1.0 - exp(-past / Fade.y));\n"
+ " float2 here = (eye + ray).xy;\n"
+ " 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"
+ " return float4(haze_along(ray.z / max(reach, 0.0001)) * lerp(lit, 1.0, closing), max(amount, closing));\n"
+ "}\n";
+
// The bright pass, downsampling as it goes: four taps of the full size frame averaged into one
// quarter size texel, then the threshold taken off its brightest channel. What survives is the
// amount by which something was brighter than white, which is a quantity an eight bit scene target
@@ -999,6 +1123,7 @@ DX11PostProcessClass::DX11PostProcessClass()
, WarpShader(NULL)
, SceneOcclusionShader(NULL)
, HazeShader(NULL)
+ , WrapSampler(NULL)
, Sampler(NULL)
, BlendState(NULL)
, MultiplyBlendState(NULL)
@@ -1019,10 +1144,12 @@ DX11PostProcessClass::DX11PostProcessClass()
, Hazed(false)
, HazeRefused(false)
, HazeShroudView(NULL)
+ , AtmosphereRefused(false)
, WorldAoRefused(false)
{
memset(HazeWorldFromClip, 0, sizeof(HazeWorldFromClip));
memset(WorldAoShaders, 0, sizeof(WorldAoShaders));
+ memset(AtmosphereShaders, 0, sizeof(AtmosphereShaders));
memset(WorldAoTargets, 0, sizeof(WorldAoTargets));
memset(WorldAoProjection, 0, sizeof(WorldAoProjection));
memset(PixelShaders, 0, sizeof(PixelShaders));
@@ -1065,6 +1192,11 @@ void DX11PostProcessClass::Shutdown()
Release_Targets();
HazeShroudView = NULL;
HazeShroudSource = NULL;
+ AtmosphereSky = NULL;
+ for (unsigned index = 0; index < ATMOSPHERE_PROGRAMS; ++index) {
+ release_interface(reinterpret_cast<IUnknown **>(&AtmosphereShaders[index]));
+ }
+ release_interface(reinterpret_cast<IUnknown **>(&WrapSampler));
release_interface(reinterpret_cast<IUnknown **>(&ConstantBuffer));
release_interface(reinterpret_cast<IUnknown **>(&RasterizerState));
release_interface(reinterpret_cast<IUnknown **>(&DepthState));
@@ -1093,6 +1225,7 @@ void DX11PostProcessClass::Shutdown()
ShadersReady = false;
Resolved = false;
HazeRefused = false;
+ AtmosphereRefused = false;
WorldAoRefused = false;
}
@@ -1192,6 +1325,11 @@ bool DX11PostProcessClass::Create_States()
if (FAILED(device->CreateSamplerState(&sampler, &Sampler))) {
return false;
}
+ sampler.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
+ sampler.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
+ if (FAILED(device->CreateSamplerState(&sampler, &WrapSampler))) {
+ return false;
+ }
D3D11_BLEND_DESC blend;
ZeroMemory(&blend, sizeof(blend));
@@ -1401,6 +1539,83 @@ void DX11PostProcessClass::Open_Frame()
Hazed = false;
}
+bool DX11PostProcessClass::Wants_Atmosphere_Programs() const
+{
+ return AtmosphereFade[2] > 0.0f && AtmosphereShaders[ATMOSPHERE_PROGRAMS - 1] == NULL && !AtmosphereRefused
+ && ShadersReady;
+}
+
+const char * DX11PostProcessClass::Atmosphere_Program_Source(unsigned index) const
+{
+ static const std::string sources[ATMOSPHERE_PROGRAMS] = {
+ std::string(PIXEL_SHADER_PROLOGUE) + SKY_SHADER_BODY,
+ std::string(PIXEL_SHADER_PROLOGUE) + ATMOSPHERE_SHADER_BODY
+ };
+ return sources[index].c_str();
+}
+
+void DX11PostProcessClass::Load_Atmosphere_Program(unsigned index, const void * bytecode, SIZE_T size)
+{
+ if (bytecode == NULL || FAILED(Device->Get_Device()->CreatePixelShader(bytecode, size, NULL,
+ &AtmosphereShaders[index]))) {
+ AtmosphereShaders[index] = NULL;
+ AtmosphereRefused = true;
+ }
+}
+
+void DX11PostProcessClass::Compile_Atmosphere_Programs()
+{
+ const char * const bodies[ATMOSPHERE_PROGRAMS] = { SKY_SHADER_BODY, ATMOSPHERE_SHADER_BODY };
+ for (unsigned index = 0; index < ATMOSPHERE_PROGRAMS; ++index) {
+ if (AtmosphereShaders[index] == NULL && !compile_pixel_shader(compiler_function(), Device->Get_Device(),
+ bodies[index], &AtmosphereShaders[index])) {
+ AtmosphereShaders[index] = NULL;
+ AtmosphereRefused = true;
+ }
+ }
+}
+
+bool DX11PostProcessClass::Draw_Atmosphere(unsigned index, ID3D11ShaderResourceView * depth,
+ const float world_from_clip[16])
+{
+ if (AtmosphereFade[2] <= 0.0f || AtmosphereShaders[index] == NULL || Resolved || !ShadersReady
+ || SceneTarget.View == NULL || Device->Get_Scene_View() != SceneTarget.View) {
+ return false;
+ }
+ memcpy(HazeWorldFromClip, world_from_clip, sizeof(HazeWorldFromClip));
+ // The game pushes the shroud every frame this is on. The haze, when it ran, has taken it for the
+ // frame's view already.
+ if (!Hazed) {
+ HazeShroudView = HazeShroudSource;
+ }
+
+ PassSetup pass;
+ memset(&pass, 0, sizeof(pass));
+ pass.Shader = AtmosphereShaders[index];
+ pass.Extra = depth;
+ pass.Blend = depth != NULL;
+ pass.World = true;
+ pass.Atmosphere = true;
+ pass.Destination = SceneTarget.View;
+ pass.DestinationWidth = Width;
+ pass.DestinationHeight = Height;
+ pass.SourceWidth = Width;
+ pass.SourceHeight = Height;
+ Draw_Pass(pass);
+ return true;
+}
+
+bool DX11PostProcessClass::Sky_Scene(const float world_from_clip[16])
+{
+ return Draw_Atmosphere(0, NULL, world_from_clip);
+}
+
+bool DX11PostProcessClass::Atmosphere_Scene(ID3D11ShaderResourceView * depth,
+ const float world_from_clip[16])
+{
+ return Draw_Atmosphere(1, depth, world_from_clip);
+}
+
bool DX11PostProcessClass::Wants_Haze_Program() const
{
return HazeStrength > 0.0f && HazeShader == NULL && !HazeRefused && ShadersReady;
@@ -1667,6 +1882,12 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
block.HazeSun[2] = (HazeShroudView != NULL) ? 1.0f : 0.0f;
memcpy(block.HazeShroudRect, HazeShroudRect, sizeof(block.HazeShroudRect));
memcpy(block.WorldAoProjection, WorldAoProjection, sizeof(block.WorldAoProjection));
+ if (pass.Atmosphere) {
+ memcpy(block.Haze, AtmosphereFade, sizeof(block.Haze));
+ memcpy(block.HazeColour, AtmosphereHorizon, sizeof(AtmosphereHorizon));
+ memcpy(block.BlurDirection, AtmosphereTint, sizeof(AtmosphereTint));
+ memcpy(block.WorldAoProjection, AtmosphereMapSize, sizeof(AtmosphereMapSize));
+ }
memcpy(mapped.pData, &block, sizeof(block));
context->Unmap(ConstantBuffer, 0);
@@ -1704,6 +1925,10 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
context->PSSetConstantBuffers(1, 1, &ConstantBuffer);
context->PSSetShaderResources(2, 1, &HazeShroudView);
}
+ if (pass.Atmosphere) {
+ context->PSSetShaderResources(3, 1, &AtmosphereSky);
+ context->PSSetSamplers(1, 1, &WrapSampler);
+ }
context->Draw(FULL_SCREEN_VERTEX_COUNT, 0);
@@ -1711,6 +1936,10 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
ID3D11ShaderResourceView * no_haze_resource = NULL;
context->PSSetShaderResources(2, 1, &no_haze_resource);
}
+ if (pass.Atmosphere) {
+ ID3D11ShaderResourceView * no_sky = NULL;
+ context->PSSetShaderResources(3, 1, &no_sky);
+ }
// The texture this pass read is the target the next one writes, and D3D11 unbinds a resource
// silently when it is bound both ways at once. Letting go here says which of the two bindings
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 78b83c5e5..3fba08117 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -148,6 +148,16 @@ void DX11Post_Set_Haze(const float colour[3], float top, float thickness, float
// every frame; null reads everything as in sight. The view is borrowed, not held.
void DX11Post_Set_Haze_Shroud(ID3D11ShaderResourceView * view, const float rect[4]);
+// The Atmosphere option: the far ground fades toward the horizon's colour and whatever the frame left
+// undrawn takes a sky. Laid over the opaque world with the haze, under the particles. Nothing moves
+// but the camera. Start is the least eye distance the fade begins at, the frame's own focus pushing it
+// further at a higher camera; scale how far the fade takes to reach about two thirds of strength; ground
+// the world height the camera's focus lies on; the map's width and height how far the playable map runs
+// from the world's origin. Tint multiplies the sky's texture, which is borrowed for the frame. Strength
+// zero, the default, is no pass at all. Set every frame.
+void DX11Post_Set_Atmosphere(const float horizon[3], const float tint[3], float start, float scale,
+ float strength, float ground, float map_width, float map_height, ID3D11ShaderResourceView * sky);
+
// A blast warping the picture around it: the frame drawn toward a point and then pushed out by a
// ring that travels away from it. Not an effect in the chain and not a switch: whatever chain is
// set, one more pass goes on its end for every frame that has a warp in it, and a frame with none
@@ -240,6 +250,16 @@ public:
// The same program compiled here, past any cache, for a caller without the backend (the tests).
void Compile_Haze_Program();
+ // The same again for the Atmosphere option's sky, over the whole frame before anything is drawn
+ // on it, and its fade, over the haze.
+ enum { ATMOSPHERE_PROGRAMS = 2 };
+ bool Sky_Scene(const float world_from_clip[16]);
+ bool Atmosphere_Scene(ID3D11ShaderResourceView * depth, const float world_from_clip[16]);
+ bool Wants_Atmosphere_Programs() const;
+ const char * Atmosphere_Program_Source(unsigned index) const;
+ void Load_Atmosphere_Program(unsigned index, const void * bytecode, SIZE_T size);
+ void Compile_Atmosphere_Programs();
+
// 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
@@ -300,8 +320,11 @@ private:
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;
+ // The Atmosphere option's: its own constants in the haze's slots, the sky at t3 and s1.
+ bool Atmosphere;
};
+ bool Draw_Atmosphere(unsigned index, ID3D11ShaderResourceView * depth, const float world_from_clip[16]);
bool Create_Shaders();
bool Create_States();
// A multisampled target is drawn into and resolved, never read, so it has no shader view.
@@ -334,6 +357,9 @@ private:
ID3D11PixelShader * WarpShader;
ID3D11PixelShader * SceneOcclusionShader;
ID3D11PixelShader * HazeShader;
+ ID3D11PixelShader * AtmosphereShaders[ATMOSPHERE_PROGRAMS];
+ // The sky's texture repeats, where every other read in the chain clamps.
+ ID3D11SamplerState * WrapSampler;
ID3D11SamplerState * Sampler;
ID3D11BlendState * BlendState;
ID3D11BlendState * MultiplyBlendState;
@@ -378,6 +404,8 @@ private:
bool HazeRefused;
// The terrain's shroud texture under the haze, borrowed from its D3D9 texture each pass.
ID3D11ShaderResourceView * HazeShroudView;
+ // An Atmosphere program failed to compile: not tried again.
+ bool AtmosphereRefused;
// The Ambient Occlusion option's programs, the projection scale it was handed, and a refusal: not
// tried again.
ID3D11PixelShader * WorldAoShaders[WORLD_AO_PROGRAMS];
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index 11278e828..80f30eab5 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -564,6 +564,17 @@ void Direct3D11_Set_Haze_Shroud(struct IDirect3DBaseTexture9 * texture, const fl
: DX11Texture_Mirror(Device.Get_Device(), Device.Get_Context(), texture), rect);
}
+void Direct3D11_Set_Atmosphere(const float horizon[3], const float tint[3], float start, float scale,
+ float strength, float ground, float map_width, float map_height, struct IDirect3DBaseTexture9 * sky)
+{
+ if (!Active) {
+ return;
+ }
+ DX11Post_Set_Atmosphere(horizon, tint, start, scale, strength, ground, map_width, map_height, sky == NULL
+ ? NULL
+ : DX11Texture_Mirror(Device.Get_Device(), Device.Get_Context(), sky));
+}
+
void Direct3D11_Set_Headlights(const float * lights, unsigned count, const float gain[3])
{
if (Active) {
@@ -767,15 +778,36 @@ void Direct3D11_Occlude_Scene()
}
}
float world_from_clip[16];
- if (Backend.Scene_World_From_Clip(world_from_clip)
- && Post.Haze_Scene(Device.Get_Depth_Texture(), world_from_clip)) {
- drew = true;
+ if (Backend.Scene_World_From_Clip(world_from_clip)) {
+ drew = Post.Haze_Scene(Device.Get_Depth_Texture(), world_from_clip) || drew;
+ drew = Post.Atmosphere_Scene(Device.Get_Depth_Texture(), world_from_clip) || drew;
}
if (drew) {
Backend.Resume_Scene();
}
}
+void Direct3D11_Atmosphere_Sky()
+{
+ if (!Active || !DrawEffectsAllowed || !Backend.Draws_Into_Scene()) {
+ return;
+ }
+ if (Post.Wants_Atmosphere_Programs()) {
+ for (unsigned index = 0; index < DX11PostProcessClass::ATMOSPHERE_PROGRAMS; ++index) {
+ std::vector<unsigned char> code;
+ if (Backend.Compile_Pixel_Program(Post.Atmosphere_Program_Source(index), "dx11atmosphere", code) && !code.empty()) {
+ Post.Load_Atmosphere_Program(index, &code[0], code.size());
+ } else {
+ Post.Load_Atmosphere_Program(index, NULL, 0);
+ }
+ }
+ }
+ float world_from_clip[16];
+ if (Backend.Scene_World_From_Clip(world_from_clip) && Post.Sky_Scene(world_from_clip)) {
+ Backend.Resume_Scene();
+ }
+}
+
void Direct3D11_Ambient_Occlusion()
{
if (!Active || !DrawEffectsAllowed || !Backend.Draws_Into_Scene()) {
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
index 9770e078e..499d02b9c 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
@@ -119,6 +119,13 @@ void Direct3D11_Mirror_Texture(unsigned stage, struct IDirect3DBaseTexture9 * te
// terrain's world to texture mapping (DX11Post_Set_Haze_Shroud). Null reads everything as in sight.
void Direct3D11_Set_Haze_Shroud(struct IDirect3DBaseTexture9 * texture, const float rect[4]);
+// The Atmosphere option's fade and sky for this frame (DX11Post_Set_Atmosphere), with the sky's D3D9
+// texture. Strength zero is no pass.
+void Direct3D11_Set_Atmosphere(const float horizon[3], const float tint[3], float start, float scale,
+ float strength, float ground, float map_width, float map_height, struct IDirect3DBaseTexture9 * sky);
+// That sky, over the whole frame, before anything is drawn on it. The fade goes on with the haze.
+void Direct3D11_Atmosphere_Sky();
+
// The vehicle headlights for the frame, nearest the camera first, eight floats each: world
// position, reach, world direction, cosine of the cone's edge; and what a pixel gains per channel
// per unit of their light. A Direct3D 9 run ignores them.
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
index 595d7937f..58dd9f3f8 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
@@ -61,6 +61,8 @@ DX11BufferTwinClass * Direct3D11_Twin_Vertex_Buffer(unsigned, bool) { return NUL
DX11BufferTwinClass * Direct3D11_Twin_Index_Buffer(unsigned, bool) { return NULL; }
void Direct3D11_Mirror_Texture(unsigned, struct IDirect3DBaseTexture9 *) {}
void Direct3D11_Set_Haze_Shroud(struct IDirect3DBaseTexture9 *, const float [4]) {}
+void Direct3D11_Set_Atmosphere(const float [3], const float [3], float, float, float, float, float, float, struct IDirect3DBaseTexture9 *) {}
+void Direct3D11_Atmosphere_Sky() {}
void Direct3D11_Set_Headlights(const float *, unsigned, const float [3]) {}
void Direct3D11_Set_Blast_Lights(const float *, unsigned) {}
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index e5ec5563d..4b430913e 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -799,6 +799,70 @@ TEST(dx11post_the_ground_haze_lies_over_a_scene_under_its_top)
}
}
+// The Atmosphere option drawn for real, as the haze's test is. With depth at a half the ground lies half
+// 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.
+TEST(dx11post_the_atmosphere_fades_the_far_ground_and_the_sky_fills_the_frame)
+{
+ DeviceFixture fixture;
+ if (!fixture.Create()) {
+ printf("skip: no Direct3D 11 device on this machine\n");
+ return;
+ }
+
+ const unsigned char LIFTED_BY_AT_LEAST = 16;
+ DX11DeviceClass & device = fixture.Get_Device();
+ DX11PostProcessClass & post = fixture.Get_Post();
+ const float white[3] = { 1.0f, 1.0f, 1.0f };
+ 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.
+ 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 };
+ 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];
+ fill_flat(picture, DARK_LEVEL);
+ const DX11PostEffect copy_only[] = { DX11_POST_COPY };
+ 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) {
+ 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,
+ DEPTHS[run], 0);
+ const bool drawn = write_scene(device, post, picture)
+ && (run == 2 ? post.Sky_Scene(identity)
+ : post.Atmosphere_Scene(device.Get_Depth_Texture(), run == 1 ? identity : looking_down))
+ && post.Run_Chain();
+ device.Set_Scene_View(NULL);
+ CHECK(drawn);
+ unsigned pitch = 0;
+ unsigned char * result = drawn ? read_back_buffer(device, pitch) : NULL;
+ CHECK(result != NULL);
+ if (result != NULL) {
+ levels[run] = pixel_level(result, pitch, SURFACE_SIZE / 2, SURFACE_SIZE / 2);
+ delete [] result;
+ }
+ }
+ 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[1] == DARK_LEVEL);
+ CHECK(levels[2] == 0);
+ CHECK(levels[3] >= DARK_LEVEL + LIFTED_BY_AT_LEAST);
+
+ // Strength zero is no pass at all.
+ post.Open_Frame();
+ CHECK(!post.Atmosphere_Scene(device.Get_Depth_Texture(), identity));
+}
+
// 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
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index 68ebae8d9..f6f0b9eb0 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -245,6 +245,7 @@ NEW_CONTROLS = [
(CHECK, "CheckInternalHdr", "GUI:InternalHdr"),
(CHECK, "CheckWeather", "GUI:Weather"),
(CHECK, "CheckWaterSplashes", "GUI:WaterSplashes"),
+ (CHECK, "CheckAtmosphere", "GUI:Atmosphere"),
(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),
(SLIDER, "SliderGraphicsQuality", None),
]
@@ -366,7 +367,8 @@ GROUP_LAYOUT = [
setting("LabelAnisotropy", "SliderAnisotropy", "ValueAnisotropy"),
# the Lighting column is full with the water and cloud styles
("check", "CheckMapLight"),
- ("check", "CheckTeamGlow")]),
+ ("check", "CheckTeamGlow"),
+ ("check", "CheckAtmosphere")]),
("GUI:OptionsGroupLighting", [
setting("LabelLightingStyle", "ComboBoxLightingStyle"),
setting("LabelBloom", "ComboBoxBloom"),