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.

refactor(w3ddevice): the map haze stays still, nothing parts it

Olcay Seygana9354d19ad5f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6aab0f78..5b86cc60c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -208,7 +208,6 @@ found and fixed, EA's own, not port damage.**
- The Raptor, King Raptor, MiG, Aurora and Stealth Fighter turn the way a plane turns. The faster a jet flies, the slower it comes round, so at cruise it sweeps a wide arc and only a slow jet turns tight. It no longer slides sideways through a turn. A Raptor's half circle at cruise takes about 3.2 seconds, where it took about 1.7.
- A jet banks into every turn and rolls through level when it swings from one turn into the opposite one, so you can read where it is going from its wings.
- Jets no longer rock their wings. A 2 degree nudge on a chase or a path corner flicked the wings 15 degrees over and back inside a third of a second, and a fighter did that every few seconds, so it looked like it was shaking the whole way. Measured over a four-player Hard match, flicks of 8 degrees or more that barely turned the nose came 1.8 times a minute per jet; now 0.2. A full turn still reaches the full bank. A jet that flies into view mid-turn also shows its bank straight away, where it used to snap level and roll back in, up to 42 degrees out.
-- With Map Light on, the haze a low jet parts on the ground no longer flickers. The wake's length and spread follow the plane's speed, and that speed was read off a clock that runs smoothly against a plane that moves a whole frame at a time, so a Raptor holding 170 read anywhere from 126 to 239 and the whole wake pulsed thirty times a second. Step to step the reading now moves under 5% in nineteen cases of twenty, where it moved up to 46%, and the wake's point stays under the plane.
- Attack runs take longer, and against a target that moves that is a real nerf. A jet cannot snap round onto a tank that drives out from under it, so it flies a wider loop to come back for another pass. In a test a Raptor's pass on a moving Overlord took about 14 seconds where it took about 4. That is the price of a plane that turns like one.
- Takeoff has a runway in it. The jet rolls at full throttle, rotates its nose up, lifts its wheels off the tarmac and climbs out at a steady angle, where it used to hop off the end of the runway.
- Landing has a circuit in it. The jet turns down in a descending curve onto a straight final, glides in, flares and touches down on the centreline, then rolls out and slows. It used to corkscrew down and stop dead.
@@ -864,7 +863,7 @@ found and fixed, EA's own, not port damage.**
theirs, which they have to: a shadow crawling across fogged ground is the position of a unit you
are not meant to see. Ground you have never set foot on is still dark and still empty.
- Woodland stops vanishing when you look at too much of it at once. Every tree on screen was written into one buffer that held about 730 of them, and the ones that did not fit were simply not drawn, so scrolling into a dense corner made whole stands of trees blink out and come back when you left. There are four of those buffers now.
-- Three optional looks for the Direct3D 11 picture, each a box in Options, off until you tick it. Water Foam, on the Effects page after Soft Shorelines, puts foam flecks and a pale band along the shore, softens where water meets land and lets the sun's shadow fall on the water; it dresses the Classic water and stands down while the Modern water style is picked. Warm Light and Haze, at the foot of the Image group on the Graphics page, swings the sun low and warm and lays a light haze over the map; a jet leaves a soft V parting the haze behind it and a helicopter clears a turbulent patch under its rotors. Team Color Glow, next to it, lets the bright house-colour parts of a unit, the flag and the stripe, glow in their own hue without bleaching to white. Picture only: replays and network games play the same with any of them on, and the haze cost 0.4 ms a frame in our measurement.
+- Three optional looks for the Direct3D 11 picture, each a box in Options, off until you tick it. Water Foam, on the Effects page after Soft Shorelines, puts foam flecks and a pale band along the shore, softens where water meets land and lets the sun's shadow fall on the water; it dresses the Classic water and stands down while the Modern water style is picked. Warm Light and Haze, at the foot of the Image group on the Graphics page, swings the sun low and warm and lays a light haze over the low ground, a fixed pattern that holds still whatever flies or drives through it. Team Color Glow, next to it, lets the bright house-colour parts of a unit, the flag and the stripe, glow in their own hue without bleaching to white. Picture only: replays and network games play the same with any of them on.
## Every replay, not just the last one
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index 217918f50..19ba42562 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -87,9 +87,7 @@ Data/Cinema/filterbw.txt
Data/Cinema/firelook.txt
Data/Cinema/geproto_alpine.txt
Data/Cinema/geproto_glow.txt
-Data/Cinema/geproto_hazemove.txt
Data/Cinema/geproto_oasis.txt
-Data/Cinema/geproto_wake.txt
Data/Cinema/gpu1m_battle.txt
Data/Cinema/gunfx.txt
Data/Cinema/headlights.txt
@@ -300,9 +298,7 @@ Data/Scenarios/geproto_alpine.txt
Data/Scenarios/geproto_fogedge.txt
Data/Scenarios/geproto_glow.txt
Data/Scenarios/geproto_hazefog.txt
-Data/Scenarios/geproto_hazemove.txt
Data/Scenarios/geproto_oasis.txt
-Data/Scenarios/geproto_wake.txt
Data/Scenarios/givemoney.txt
Data/Scenarios/glowbase.txt
Data/Scenarios/glowfight.txt
diff --git a/GeneralsMD/Code/Data/Cinema/geproto_hazemove.txt b/GeneralsMD/Code/Data/Cinema/geproto_hazemove.txt
deleted file mode 100644
index a73992e34..000000000
--- a/GeneralsMD/Code/Data/Cinema/geproto_hazemove.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-# Haze motion over Scenarios/geproto_hazemove.txt on Golden Oasis. Fixed frames except one slide,
-# so whatever moves on screen is the haze or the units. Run with a -video range.
-
-0 hud off
-3 cut 3040 900 1.3 -45 0 # wide, the patches drifting with nothing in frame
-14 cut 3040 900 0.6 -45 0 # close: the Comanche comes in and hovers over the bank
-28 move 3000 950 3 # it leaves at 28; the camera slides while the disc fades
-28 zoom 1.0 3
-32 cut 3000 950 1.0 -45 0 # play distance: the Crusaders cross the bank
-50 cut 3040 900 1.0 -45 0 # play distance for the Raptor's pass and the cargo plane's after it
-68 end
diff --git a/GeneralsMD/Code/Data/Cinema/geproto_wake.txt b/GeneralsMD/Code/Data/Cinema/geproto_wake.txt
deleted file mode 100644
index d0fce1fc1..000000000
--- a/GeneralsMD/Code/Data/Cinema/geproto_wake.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# Fixed frames over Scenarios/geproto_wake.txt so the wake's ground position can be judged.
-0 hud off
-3 cut 2966 742 1.2 -45 0 # the Comanche between the dry bank and the outcrop
-30 cut 2940 840 1.5 -45 0 # wider and still: the Raptor's turns over the bank
-52 end
diff --git a/GeneralsMD/Code/Data/French/Generals.str b/GeneralsMD/Code/Data/French/Generals.str
index 101fd9a62..b9bd25c66 100644
--- a/GeneralsMD/Code/Data/French/Generals.str
+++ b/GeneralsMD/Code/Data/French/Generals.str
@@ -16870,7 +16870,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"Un soleil bas d'après-midi qui éclaire la carte plus chaudement et allonge les ombres, et une légère brume posée sur les terrains bas que les avions fendent en la traversant. Direct3D 11 seulement. S'applique à partir de la carte suivante."
+"Un soleil bas d'après-midi qui éclaire la carte plus chaudement et allonge les ombres, et une légère brume immobile posée sur les terrains bas. Direct3D 11 seulement. S'applique à partir de la carte suivante."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/Data/German/Generals.str b/GeneralsMD/Code/Data/German/Generals.str
index 7903bf89a..a40a71b00 100644
--- a/GeneralsMD/Code/Data/German/Generals.str
+++ b/GeneralsMD/Code/Data/German/Generals.str
@@ -14994,7 +14994,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"Eine tief stehende Nachmittagssonne taucht die Karte in wärmeres Licht und wirft längere Schatten, und über tiefem Gelände liegt ein leichter Dunst, den Flugzeuge beim Durchfliegen teilen. Nur mit Direct3D 11. Gilt ab der nächsten Karte."
+"Eine tief stehende Nachmittagssonne taucht die Karte in wärmeres Licht und wirft längere Schatten, und über tiefem Gelände liegt reglos ein leichter Dunst. Nur mit Direct3D 11. Gilt ab der nächsten Karte."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 39d50d789..31bcf8372 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1473,7 +1473,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"A low afternoon sun that lights the map warmer and casts longer shadows, and a light haze lying over low ground that aircraft part as they fly through it. Direct3D 11 only. Applies from the next map."
+"A low afternoon sun that lights the map warmer and casts longer shadows, and a light haze lying still over low ground. Direct3D 11 only. Applies from the next map."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/Data/Russian/Generals.str b/GeneralsMD/Code/Data/Russian/Generals.str
index ddd74bab9..adbfb2e02 100644
--- a/GeneralsMD/Code/Data/Russian/Generals.str
+++ b/GeneralsMD/Code/Data/Russian/Generals.str
@@ -16842,7 +16842,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"Низкое послеполуденное солнце освещает карту теплее и отбрасывает более длинные тени, а лёгкая дымка стелется над низинами, и самолёты рассекают её в полёте. Только Direct3D 11. Применяется со следующей карты."
+"Низкое послеполуденное солнце освещает карту теплее и отбрасывает более длинные тени, а лёгкая дымка неподвижно лежит над низинами. Только Direct3D 11. Применяется со следующей карты."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/Data/Scenarios/geproto_hazemove.txt b/GeneralsMD/Code/Data/Scenarios/geproto_hazemove.txt
deleted file mode 100644
index 8c85cd74a..000000000
--- a/GeneralsMD/Code/Data/Scenarios/geproto_hazemove.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-# The Warm Light haze reacting to movers, on the low bank of the oasis on Golden Oasis
-# (Cinema/geproto_hazemove.txt): a Comanche flies in low and hovers, four Crusaders drive across,
-# then a Raptor passes over at cruise height. Nothing is in the frame for the first 10 s, so the
-# wide view shows the patches drifting on their own. Frames here count 30 a second.
-#
-# generals.exe -win -borderless -quickstart -noshellmap -multiInstance -fps 120 -noFPSLimit
-# -particlecap 2500 -map "Maps\Golden Oasis\Golden Oasis.map" -autoskirmish 2 -takeover
-# -observer -side 0 FactionAmerica -side 1 FactionChina -seed 1 -scenario geproto_hazemove
-# -cinema geproto_hazemove -video 180 3480 hazemove -maxframes 3540
-# with MapLight = yes in the Options.ini of a ZH_USER_DATA_DIR folder for the haze
-
-# the helicopter: in low from the south-west at 10 s, hovers over the bank, leaves at 28 s
-300 spawn 0 AmericaVehicleComanche 1 2500 650
-305 move 0 AmericaVehicleComanche 3040 900
-840 move 0 AmericaVehicleComanche 3500 1250
-
-# the tanks: across the bank through the middle of the frame from 30 s
-900 spawn 0 AmericaTankCrusader 4 2600 1150 40
-905 move 0 AmericaTankCrusader 3400 750
-
-# the aircraft: a Raptor pass from 49 s, then a slower cargo plane from 57 s, over the same ground
-1470 spawn 0 AmericaJetRaptor 1 2300 400
-1471 move 0 AmericaJetRaptor 3800 1400
-1710 spawn 0 AmericaJetCargoPlane 1 2500 550
-1711 move 0 AmericaJetCargoPlane 3800 1400
diff --git a/GeneralsMD/Code/Data/Scenarios/geproto_wake.txt b/GeneralsMD/Code/Data/Scenarios/geproto_wake.txt
deleted file mode 100644
index dc63df683..000000000
--- a/GeneralsMD/Code/Data/Scenarios/geproto_wake.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-# Aircraft wake held in the world: a Comanche going back and forth between the dry near bank and
-# the rock outcrop (climbing onto it, dropping off it), then a Raptor sent onto the bank and turned
-# twice in frame. Golden Oasis, fixed cameras (Cinema/geproto_wake.txt). 30 a second.
-
-# heli: in from the south-west, then dry bank -> outcrop -> dry bank -> outcrop
-300 spawn 0 AmericaVehicleComanche 1 2500 650
-301 move 0 AmericaVehicleComanche 2766 980
-420 move 0 AmericaVehicleComanche 3165 505
-600 move 0 AmericaVehicleComanche 2700 900
-780 move 0 AmericaVehicleComanche 3165 505
-
-# jet: in from screen left onto the bank, a turn toward screen right, a hard turn back, and out
-900 spawn 0 AmericaJetRaptor 1 2214 1786
-901 move 0 AmericaJetRaptor 2915 817
-1080 move 0 AmericaJetRaptor 3190 402
-1200 move 0 AmericaJetRaptor 2600 1100
-1320 move 0 AmericaJetRaptor 3700 300
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index d96193742..71ae31dd2 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15866,7 +15866,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"Haritayı daha sıcak aydınlatıp daha uzun gölgeler düşüren alçak bir ikindi güneşi ve alçak zeminin üstünde duran, içinden geçen uçakların araladığı hafif bir pus. Yalnızca Direct3D 11. Bir sonraki haritada uygulanır."
+"Haritayı daha sıcak aydınlatıp daha uzun gölgeler düşüren alçak bir ikindi güneşi ve alçak zeminin üstünde kımıldamadan duran hafif bir pus. Yalnızca Direct3D 11. Bir sonraki haritada uygulanır."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/Data/Ukrainian/Generals.str b/GeneralsMD/Code/Data/Ukrainian/Generals.str
index 1028dfb27..8f42583ec 100644
--- a/GeneralsMD/Code/Data/Ukrainian/Generals.str
+++ b/GeneralsMD/Code/Data/Ukrainian/Generals.str
@@ -16842,7 +16842,7 @@ GUI:MapLight
END
TOOLTIP:MapLight
-"Низьке надвечірнє сонце, що освітлює мапу тепліше й відкидає довші тіні, та легка імла над низинами, яку літаки розсувають, пролітаючи крізь неї. Лише Direct3D 11. Діє з наступної мапи."
+"Низьке надвечірнє сонце, що освітлює мапу тепліше й відкидає довші тіні, та легка імла, що нерухомо лежить над низинами. Лише Direct3D 11. Діє з наступної мапи."
END
GUI:TeamGlow
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 21c531b42..8ac70232e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -702,7 +702,7 @@ public:
Bool m_lanLobbyOnStart; ///< -lanlobby: open the LAN lobby instead of stopping at the main menu
Bool m_skirmishLobbyOnStart; ///< -skirmishlobby: open the skirmish staging room instead of stopping at the main menu
Bool m_optionsMenuOnStart; ///< -optionsmenu: open the options screen over the main menu at startup
- Bool m_mapLight; ///< "MapLight": warm low sun, ground haze and aircraft wakes (Direct3D 11, client only)
+ Bool m_mapLight; ///< "MapLight": warm low sun and a still ground haze (Direct3D 11, client only)
Bool m_teamGlow; ///< "TeamGlow": bright house colour glows (Direct3D 11, client only)
Bool m_waterFoam; ///< "WaterFoam": foam, shore band and the sun's shadow on water (Direct3D 11, client only)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 32bca53a8..b21b0c764 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -587,7 +587,7 @@ const OptionDef TheOptionCatalog[] =
// Three Direct3D 11 looks, all off by default; the menu greys them under -d3d9. Warm light is a
// low late afternoon sun put into each map's lights as the map loads (WorldHeightMap), so it waits
- // for the next map, and a light haze over low ground that aircraft part, pushed every frame
+ // for the next map, and a light still haze over low ground, pushed every frame
// (W3DShaderManager). Team glow marks a house colour mesh as it is recoloured for its side,
// which happens as a map's models are made. On Options > Graphics.
{ "MapLight", OPT_WND( "CheckMapLight" ), "GUI:MapLight",
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
index fed163042..a42884c06 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h
@@ -114,7 +114,7 @@ public:
static Bool filterPreRender(FilterTypes filter, Bool &skipRender, CustomScenePassModes &scenePassMode); ///< Set up at start of render. Only applies to screen filter shaders.
static Bool filterPostRender(FilterTypes filter, enum FilterModes mode, Coord2D &scrollDelta, Bool &doExtraRender); ///< Called after render. Only applies to screen filter shaders.
static Bool filterSetup(FilterTypes filter, enum FilterModes mode);
- /// The Warm Light haze for this frame (levels, shroud, field step, wakes), once a frame from
+ /// The Warm Light haze for this frame (levels, sun, shroud), once a frame from
/// W3DDisplay::draw before the views render, whatever screen filter is running.
static void pushProtoHaze(void);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 26c012709..e4275aed7 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -2781,7 +2781,7 @@ AGAIN:
W3DModelDraw::lightHeadlights(primaryW3DView->get3DCamera()->Get_Position());
// Once a frame and before any view draws, so a script's blur or black and white filter
- // does not freeze the haze the way pushing it from the default filter did.
+ // does not cost the haze its levels and shroud the way pushing it from the default filter did.
W3DShaderManager::pushProtoHaze();
if (TheWaterRenderObj)
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
index 1d60fbe28..59e3bf15f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp
@@ -84,14 +84,7 @@
#include "dx8caps.h"
#include "Common/GameLOD.h"
#include "benchmark.h"
-#include "Common/GameEngine.h"
-#include "GameClient/Drawable.h"
-#include "GameClient/GameClient.h"
-#include "W3DDevice/GameClient/W3DSmoothMotion.h"
-#include <algorithm>
-#include <map>
#include <math.h>
-#include <vector>
#include <string.h> // memset, strcpy, strlen
#ifdef _INTERNAL
@@ -316,621 +309,6 @@ static Real protoHazeMiddle(WorldHeightMap *map)
return 0.0f;
}
-/* The haze moves. Its patches drift on a fixed wind (the shader's noise, PROTO_HAZE_WIND and
- PROTO_HAZE_PATCH), and what goes through it leaves a mark: a field of PROTO_FIELD squared cells
- over PROTO_FIELD_SPAN world units round the camera's look point (six units a cell, fine enough
- for a tank's track to read), stepped PROTO_FIELD_RATE times a second, that fades over
- PROTO_FIELD_LIFE seconds, spreads a little each step and is carried by the same wind. The field
- follows the camera a whole cell at a time, so what is on screen keeps its marks and what scrolls
- out is dropped. Vehicles on the ground rub a strip along their track. Aircraft over the haze
- and within PROTO_STIR_AIR_BAND above its top (a jet at cruise height over a valley too, a licence
- taken for the look) leave wakes instead, below: the haze opens behind them as a wave. Only what the
- local player can see stamps: a unit under the shroud, hidden or stealthed out of sight leaves
- nothing, or the haze would give it away. Read from the drawables only (where they are drawn,
- what kind of thing they are), never from the logic, and it costs the logic nothing. Everything
- runs on the game's clock (the picture clock under -video), so a pause stops the wind and the
- marks with the units. */
-static const Int PROTO_FIELD = (Int)DX11_POST_HAZE_FIELD_SIZE;
-static const Real PROTO_FIELD_SPAN = 1536.0f; // world units the field covers each way
-static const Real PROTO_HAZE_WIND[2] = { 11.0f, 4.0f }; // world units a second
-static const Real PROTO_HAZE_PATCH = 1.0f / 320.0f; // one over a patch's size
-static const Real PROTO_HAZE_STIR = 0.85f; // share of the haze a full mark takes away
-static const Real PROTO_HAZE_SUN_WARMTH = 1.0f; // how much warmer it looks toward the sun
-static const Real PROTO_FIELD_RATE = 30.0f; // field steps a second
-static const Real PROTO_FIELD_LIFE = 1.6f; // seconds for a mark to fall to a third (a disc left behind is gone in about three)
-static const Real PROTO_FIELD_SPREAD = 0.10f; // share of a cell's neighbours it takes each step
-static const Real PROTO_STIR_VEHICLE_RADIUS = 16.0f;
-static const Real PROTO_STIR_VEHICLE_RATE = 6.0f; // field a second, at full speed
-static const Real PROTO_STIR_VEHICLE_SPEED = 30.0f; // full speed, world units a second
-static const Real PROTO_STIR_VEHICLE_HEIGHT = 20.0f; // higher off the ground than this stirs nothing
-static const Real PROTO_STIR_AIR_BAND = 400.0f; // an aircraft this far over the haze's top stirs nothing
-
-static Real s_hazeField[2][PROTO_FIELD * PROTO_FIELD];
-static Int s_hazeFieldCurrent = 0;
-static unsigned char s_hazeFieldBytes[PROTO_FIELD * PROTO_FIELD];
-static WorldHeightMap *s_hazeFieldMap = NULL;
-static Int s_hazeFieldCellX = 0; // the field's origin, in whole cells of the world
-static Int s_hazeFieldCellY = 0;
-/* Aircraft wakes. Each aircraft over the haze keeps a trail of where it was, a point every
- PROTO_TRAIL_EVERY seconds for the last PROTO_WAKE_LIFE, and every frame the shader gets the path
- from the aircraft (moved on from the last step by its speed) back along that trail as segments.
- Behind it the haze parts in a narrow V, PROTO_WAKE_ANGLE_SLOW degrees each side of the path for
- a slow flyer down to PROTO_WAKE_ANGLE_FAST at PROTO_WAKE_FAST world units a second, a vortex
- PROTO_WAKE_VORTEX across rolling along each arm, as long as the path it flew in PROTO_WAKE_LIFE.
- One whose trail took it less than PROTO_WAKE_HOVER_SPEED a second over the last
- PROTO_WAKE_HOVER_SPAN or more hovers: its rotor wash pushes two rings of turbulence out from it,
- PROTO_RIPPLE_REACH far every PROTO_RIPPLE_PERIOD seconds, half a period apart.
- The wake comes out straight under the aircraft, the haze being on the ground. Its height over the
- haze's top sets it: skimming the haze the wake is narrow, sharp and strong; climbing, the V and the
- rings open wider (PROTO_WAKE_HIGH_WIDEN more at the band's top, in a straight line), the shader
- softens it and the strength falls on a smoothstep to nothing at PROTO_STIR_AIR_BAND. */
-static const Int PROTO_TRAIL_POINTS = 14;
-static const Real PROTO_TRAIL_EVERY = 0.2f;
-static const Real PROTO_WAKE_LIFE = 2.8f;
-static const Real PROTO_WAKE_ANGLE_SLOW = 18.0f;
-static const Real PROTO_WAKE_ANGLE_FAST = 10.0f;
-static const Real PROTO_WAKE_FAST = 250.0f;
-static const Real PROTO_WAKE_VORTEX = 7.0f;
-static const Real PROTO_WAKE_OPEN_SOFT = 12.0f;
-static const Real PROTO_WAKE_HOVER_SPEED = 15.0f;
-static const Real PROTO_WAKE_HOVER_SPAN = 0.6f;
-static const Real PROTO_WAKE_LANDED_HEIGHT = 10.0f; // lower over the ground than this is landed, no wake
-static const Real PROTO_WAKE_HIGH_WIDEN = 2.0f; // how much wider than a skimming wake one at the band's top is
-static const Real PROTO_RIPPLE_REACH = 70.0f;
-static const Real PROTO_RIPPLE_PERIOD = 1.4f;
-
-/** A trail point: where the aircraft was (the wake lies straight under it), the clock it was there
- at, and the wake's strength and width for its height then. Fixed once laid, so a turn, a climb or
- the camera moving after it moves only the newest end. */
-enum { PROTO_POINT_X, PROTO_POINT_Y, PROTO_POINT_AT, PROTO_POINT_STRENGTH, PROTO_POINT_WIDTH, PROTO_POINT_FIELDS };
-
-/** Where a stirring drawable was at the last step, its speed then, and for an aircraft the wake it
- is laying now (strength, 0 for none, and width) and its trail, newest first. Kept from step to
- step in place, so a step allocates only for a drawable it has not seen before; step says which
- step last saw it. An aircraft that stops laying (out of the haze's band, landed, fogged, hidden,
- gone) keeps its entry while the trail it laid lives, and the trail fades out where it lies. */
-struct ProtoHazeSeen
-{
- Coord3D pos;
- Real velX;
- Real velY;
- Real seenAt;
- UnsignedInt frame; // the logic frame pos is from
- Real wake;
- Real wakeWidth;
- Real trail[PROTO_TRAIL_POINTS][PROTO_POINT_FIELDS];
- Int trailCount;
- Int step;
-};
-
-/** The wake an aircraft this far over the haze's top lays: full strength and its narrowest at the
- top or under it, nothing at PROTO_STIR_AIR_BAND. */
-static Real protoWakeStrength(Real over)
-{
- const Real high = min(max(over / PROTO_STIR_AIR_BAND, 0.0f), 1.0f);
- return 1.0f - high * high * (3.0f - 2.0f * high);
-}
-
-static Real protoWakeWidth(Real over)
-{
- return 1.0f + PROTO_WAKE_HIGH_WIDEN * min(max(over / PROTO_STIR_AIR_BAND, 0.0f), 1.0f);
-}
-
-static std::map<DrawableID, ProtoHazeSeen> s_hazeLastSeen;
-static Int s_hazeStepNumber = 0;
-static Real s_hazeLastClock = -1.0f;
-static Real s_hazeClockLead = 0.0f; // how far the clock is past the logic frame the drawables stand on, in seconds
-static Real s_hazeSeconds = 0.0f;
-static Real s_hazeStepDue = 0.0f;
-
-/** The points of a trail still inside the wake's life, moved to start at kept; the new count. The
- two may be one trail, kept no further on than the point read. */
-static Int keepProtoTrail(const Real (*from)[PROTO_POINT_FIELDS], Int count, Real (*to)[PROTO_POINT_FIELDS], Int kept)
-{
- for (Int index = 0; index < count && kept < PROTO_TRAIL_POINTS; ++index)
- {
- const Real age = s_hazeSeconds - from[index][PROTO_POINT_AT];
- if (age < 0.0f || age > PROTO_WAKE_LIFE)
- break;
- memmove(to[kept], from[index], sizeof(to[kept]));
- ++kept;
- }
- return kept;
-}
-
-/** A new newest point for an aircraft at x, y laying a wake of this strength and width. */
-static void pushProtoTrail(ProtoHazeSeen &entry, Real x, Real y, Real strength, Real width)
-{
- Real older[PROTO_TRAIL_POINTS][PROTO_POINT_FIELDS];
- memcpy(older, entry.trail, sizeof(older));
- entry.trailCount = keepProtoTrail(older, entry.trailCount, entry.trail, 1);
- entry.trail[0][PROTO_POINT_X] = x;
- entry.trail[0][PROTO_POINT_Y] = y;
- entry.trail[0][PROTO_POINT_AT] = s_hazeSeconds;
- entry.trail[0][PROTO_POINT_STRENGTH] = strength;
- entry.trail[0][PROTO_POINT_WIDTH] = width;
-}
-
-/** The game's time in seconds as the picture shows it: the logic frame and how far into the next
- one the blend is, or the picture's own time while -video records. */
-static Real protoHazeClock(void)
-{
- if (GameEngine_isVideoFrame())
- return (Real)GameEngine_pictureMilliseconds() * 0.001f;
- return ((Real)TheGameClient->getFrame() + GameEngine_logicTickFraction()) / (Real)LOGICFRAMES_PER_SECOND;
-}
-
-/** A rectangle of field cells, both ends inside; empty when x1 < x0. */
-struct ProtoFieldRect
-{
- Int x0, y0, x1, y1;
- Bool isEmpty(void) const { return x1 < x0 || y1 < y0; }
- void clear(void) { x0 = y0 = PROTO_FIELD; x1 = y1 = -1; }
- void add(Int ax0, Int ay0, Int ax1, Int ay1)
- {
- x0 = min(x0, ax0); y0 = min(y0, ay0); x1 = max(x1, ax1); y1 = max(y1, ay1);
- }
-};
-
-/** Adds amount to the field in a soft disc of the given world radius about a world point, and
- grows marked to cover it. */
-static void stampProtoHaze(Real *field, ProtoFieldRect &marked, Real cellsPerUnitX, Real cellsPerUnitY,
- Real originX, Real originY, Real x, Real y, Real radius, Real amount)
-{
- const Real cx = (x - originX) * cellsPerUnitX;
- const Real cy = (y - originY) * cellsPerUnitY;
- const Real rx = radius * cellsPerUnitX;
- const Real ry = radius * cellsPerUnitY;
- // off the field's outer ring of cells, which stepProtoHaze's loop reads as clear neighbours only
- const Int x0 = max((Int)(cx - rx), 1);
- const Int x1 = min((Int)(cx + rx) + 1, PROTO_FIELD - 2);
- const Int y0 = max((Int)(cy - ry), 1);
- const Int y1 = min((Int)(cy + ry) + 1, PROTO_FIELD - 2);
- for (Int j = y0; j <= y1; ++j)
- {
- for (Int i = x0; i <= x1; ++i)
- {
- const Real dx = ((Real)i + 0.5f - cx) / rx;
- const Real dy = ((Real)j + 0.5f - cy) / ry;
- const Real fall = 1.0f - (dx * dx + dy * dy);
- if (fall <= 0.0f)
- continue;
- Real &cell = field[i + j * PROTO_FIELD];
- cell = min(cell + amount * fall, 1.0f);
- }
- }
- if (x0 <= x1 && y0 <= y1)
- marked.add(x0, y0, x1, y1);
-}
-
-// The cells holding a mark, and the cells whose byte may not be zero. A step works over the first
-// and one cell round it only (the spread and the drift reach no further), so a quiet field costs
-// nothing and a battle costs its own corner of it. The buffer a step writes into is clear all over
-// before it starts: each step clears the cells it read once it is done with them.
-static ProtoFieldRect s_hazeActive = { PROTO_FIELD, PROTO_FIELD, -1, -1 };
-static ProtoFieldRect s_hazeWritten = { PROTO_FIELD, PROTO_FIELD, -1, -1 };
-
-/** Moves the marks by whole cells as the field follows the camera: the cell (x, y) takes what was at
- (x + moveX, y + moveY), and what had no cell to come from starts clear. */
-static void shiftProtoHaze(Int moveX, Int moveY)
-{
- if (s_hazeActive.isEmpty())
- return;
- Real *field = s_hazeField[s_hazeFieldCurrent];
- Real *spare = s_hazeField[1 - s_hazeFieldCurrent];
- const ProtoFieldRect old = s_hazeActive;
- s_hazeActive.x0 = max(old.x0 - moveX, 1);
- s_hazeActive.x1 = min(old.x1 - moveX, PROTO_FIELD - 2);
- s_hazeActive.y0 = max(old.y0 - moveY, 1);
- s_hazeActive.y1 = min(old.y1 - moveY, PROTO_FIELD - 2);
- if (!s_hazeActive.isEmpty())
- {
- for (Int y = s_hazeActive.y0; y <= s_hazeActive.y1; ++y)
- memcpy(spare + s_hazeActive.x0 + y * PROTO_FIELD, field + (s_hazeActive.x0 + moveX) + (y + moveY) * PROTO_FIELD,
- (s_hazeActive.x1 - s_hazeActive.x0 + 1) * sizeof(Real));
- }
- else
- {
- s_hazeActive.clear();
- }
- for (Int y = old.y0; y <= old.y1; ++y)
- memset(field + old.x0 + y * PROTO_FIELD, 0, (old.x1 - old.x0 + 1) * sizeof(Real));
- s_hazeFieldCurrent = 1 - s_hazeFieldCurrent;
-}
-
-/** One field step: follow the camera, fade, drift on the wind and spread, then what moved since the
- last step. */
-static void stepProtoHaze(Real top, Real dt)
-{
- WorldHeightMap *map = TheTerrainRenderObject->getMap();
- if (map != s_hazeFieldMap)
- {
- s_hazeFieldMap = map;
- memset(s_hazeField, 0, sizeof(s_hazeField));
- memset(s_hazeFieldBytes, 0, sizeof(s_hazeFieldBytes));
- s_hazeActive.clear();
- s_hazeWritten.clear();
- s_hazeLastSeen.clear();
- DX11Post_Set_Haze_Field(s_hazeFieldBytes);
- }
- const Real cellSize = PROTO_FIELD_SPAN / (Real)PROTO_FIELD;
- const Real cellsPerUnitX = 1.0f / cellSize;
- const Real cellsPerUnitY = cellsPerUnitX;
- Coord3D look;
- TheTacticalView->getPosition(&look);
- const Int cellX = (Int)floor(look.x / cellSize) - PROTO_FIELD / 2;
- const Int cellY = (Int)floor(look.y / cellSize) - PROTO_FIELD / 2;
- const Int moveCellsX = cellX - s_hazeFieldCellX;
- const Int moveCellsY = cellY - s_hazeFieldCellY;
- s_hazeFieldCellX = cellX;
- s_hazeFieldCellY = cellY;
- if (moveCellsX != 0 || moveCellsY != 0)
- shiftProtoHaze(moveCellsX, moveCellsY);
- const Real originX = (Real)cellX * cellSize;
- const Real originY = (Real)cellY * cellSize;
-
- const Real *from = s_hazeField[s_hazeFieldCurrent];
- Real *to = s_hazeField[1 - s_hazeFieldCurrent];
- const Real keep = (Real)exp(-dt / PROTO_FIELD_LIFE);
- // the wind moves a mark well under a cell a step, so a bilinear read that far upwind is the drift
- const Real shiftX = PROTO_HAZE_WIND[0] * dt * cellsPerUnitX;
- const Real shiftY = PROTO_HAZE_WIND[1] * dt * cellsPerUnitY;
- const Int stepX = (shiftX >= 0.0f) ? -1 : 1;
- const Int stepY = (shiftY >= 0.0f) ? -1 : 1;
- const Real fx = (Real)fabs(shiftX);
- const Real fy = (Real)fabs(shiftY);
- const Real w00 = keep * (1.0f - PROTO_FIELD_SPREAD) * (1.0f - fx) * (1.0f - fy);
- const Real w10 = keep * (1.0f - PROTO_FIELD_SPREAD) * fx * (1.0f - fy);
- const Real w01 = keep * (1.0f - PROTO_FIELD_SPREAD) * (1.0f - fx) * fy;
- const Real w11 = keep * (1.0f - PROTO_FIELD_SPREAD) * fx * fy;
- const Real wAround = keep * PROTO_FIELD_SPREAD * 0.25f;
-
- // the marks, one cell wider; everything outside is clear in both buffers
- ProtoFieldRect work;
- work.clear();
- if (!s_hazeActive.isEmpty())
- work.add(max(s_hazeActive.x0 - 1, 1), max(s_hazeActive.y0 - 1, 1),
- min(s_hazeActive.x1 + 1, PROTO_FIELD - 2), min(s_hazeActive.y1 + 1, PROTO_FIELD - 2));
- ProtoFieldRect live;
- live.clear();
- // No mark ever lies on the field's outer ring of cells (the stamps and the shift keep off it), so
- // every cell worked on has its four neighbours inside and the loop needs no clamping.
- for (Int j = work.y0; j <= work.y1; ++j)
- {
- const Real *row = from + j * PROTO_FIELD;
- const Real *rowUp = row - PROTO_FIELD;
- const Real *rowDown = row + PROTO_FIELD;
- const Real *rowWind = row + stepY * PROTO_FIELD;
- Real *out = to + j * PROTO_FIELD;
- Int rowLow = PROTO_FIELD;
- Int rowHigh = -1;
- for (Int i = work.x0; i <= work.x1; ++i)
- {
- Real value = w00 * row[i] + w10 * row[i + stepX] + w01 * rowWind[i] + w11 * rowWind[i + stepX]
- + wAround * (row[i - 1] + row[i + 1] + rowUp[i] + rowDown[i]);
- // a mark faded under a byte's half step is gone, so the field goes quiet again
- if (value < 0.002f)
- {
- value = 0.0f;
- }
- else
- {
- if (i < rowLow)
- rowLow = i;
- rowHigh = i;
- }
- out[i] = value;
- }
- if (rowHigh >= 0)
- live.add(rowLow, j, rowHigh, j);
- }
- // the buffer read is the next step's to write into, so it goes back to clear
- if (!s_hazeActive.isEmpty())
- {
- for (Int j = s_hazeActive.y0; j <= s_hazeActive.y1; ++j)
- memset((Real *)from + s_hazeActive.x0 + j * PROTO_FIELD, 0, (s_hazeActive.x1 - s_hazeActive.x0 + 1) * sizeof(Real));
- }
- s_hazeFieldCurrent = 1 - s_hazeFieldCurrent;
-
- ++s_hazeStepNumber;
- for (Drawable *draw = TheGameClient->firstDrawable(); draw != NULL; draw = draw->getNextDrawable())
- {
- const Bool air = draw->isKindOf(KINDOF_AIRCRAFT);
- if (!air && !draw->isKindOf(KINDOF_VEHICLE))
- continue;
- if (draw->getFullyObscuredByShroud() || draw->isDrawableEffectivelyHidden()
- || draw->getStealthLook() == STEALTHLOOK_INVISIBLE)
- continue;
- const Coord3D pos = *draw->getPosition();
- std::map<DrawableID, ProtoHazeSeen>::iterator found = s_hazeLastSeen.find(draw->getID());
- const Bool fresh = found == s_hazeLastSeen.end();
- ProtoHazeSeen &now = fresh ? s_hazeLastSeen[draw->getID()] : found->second;
- // what the last step saw, before this one writes over it
- const ProtoHazeSeen before = now;
- now.pos = pos;
- now.velX = 0.0f;
- now.velY = 0.0f;
- // pos is where the drawable stood at the start of its logic frame, not at the clock's fraction
- // of the way into the next one
- now.seenAt = s_hazeSeconds - s_hazeClockLead;
- now.frame = TheGameClient->getFrame();
- now.wake = 0.0f;
- now.trailCount = fresh ? 0 : keepProtoTrail(before.trail, before.trailCount, now.trail, 0);
- now.step = s_hazeStepNumber;
- // one the last step did not see (new, or back from the fog) starts its motion over; a trail
- // it laid before going keeps fading where it lies
- if (fresh || before.step != s_hazeStepNumber - 1)
- continue;
- const Real moveX = pos.x - before.pos.x;
- const Real moveY = pos.y - before.pos.y;
- const Real moved = (Real)sqrt(moveX * moveX + moveY * moveY);
- const Real speed = moved / dt;
-
- if (air)
- {
- /* The speed is the move over the logic frames it took. Over the step's time it came out 126 to
- 239 a second for a Raptor holding 170: the position moves a whole frame at a time and the
- step falls anywhere inside one, and the wake's length and opening follow the speed, so the
- whole wake pulsed thirty times a second. */
- const UnsignedInt frames = now.frame - before.frame;
- now.velX = (frames > 0) ? moveX * LOGICFRAMES_PER_SECOND / (Real)frames : before.velX;
- now.velY = (frames > 0) ? moveY * LOGICFRAMES_PER_SECOND / (Real)frames : before.velY;
- const Real ground = TheTerrainRenderObject->getHeightMapHeight(pos.x, pos.y, NULL);
- const Real over = pos.z - top;
- // one parked on a runway or a pad is no wake; a base's planes took every slot
- if (ground <= top && over < PROTO_STIR_AIR_BAND && pos.z - ground >= PROTO_WAKE_LANDED_HEIGHT)
- {
- now.wake = protoWakeStrength(over);
- now.wakeWidth = protoWakeWidth(over);
- }
- // the trail: the last one's points still inside the wake's life, and this one in front
- // once the newest is old enough, while it lays a wake; one that just stopped lays a last
- // point where it stopped, so the end that was following it stays there
- if (now.wake > 0.0f)
- {
- if (now.trailCount == 0 || s_hazeSeconds - now.trail[0][PROTO_POINT_AT] >= PROTO_TRAIL_EVERY
- || s_hazeSeconds < now.trail[0][PROTO_POINT_AT])
- pushProtoTrail(now, pos.x, pos.y, now.wake, now.wakeWidth);
- }
- else if (before.wake > 0.0f)
- {
- pushProtoTrail(now, pos.x, pos.y, before.wake, before.wakeWidth);
- }
- continue;
- }
- const Real ground = TheTerrainRenderObject->getHeightMapHeight(pos.x, pos.y, NULL);
- if (ground > top)
- continue;
- if (pos.z - ground >= PROTO_STIR_VEHICLE_HEIGHT)
- continue;
- const Real radius = PROTO_STIR_VEHICLE_RADIUS;
- const Real rate = PROTO_STIR_VEHICLE_RATE * min(speed / PROTO_STIR_VEHICLE_SPEED, 1.0f);
- if (rate <= 0.0f)
- continue;
- // along the stretch moved since the last step, so a quick one leaves a strip and not beads
- const Int dabs = min(max((Int)(moved / (radius * 0.5f)) + 1, 1), 8);
- for (Int dab = 0; dab < dabs; ++dab)
- {
- const Real along = ((Real)dab + 1.0f) / (Real)dabs;
- stampProtoHaze(to, live, cellsPerUnitX, cellsPerUnitY, originX, originY,
- before.pos.x + moveX * along, before.pos.y + moveY * along, radius, rate * dt / (Real)dabs);
- }
- }
- // what this step did not see (fogged, hidden, gone) lays nothing, and is forgotten once the wake
- // it laid has faded
- for (std::map<DrawableID, ProtoHazeSeen>::iterator it = s_hazeLastSeen.begin(); it != s_hazeLastSeen.end(); )
- {
- ProtoHazeSeen &gone = it->second;
- if (gone.step != s_hazeStepNumber)
- {
- // the last place it was laying from, as for one that stopped in sight
- if (gone.wake > 0.0f)
- pushProtoTrail(gone, gone.pos.x, gone.pos.y, gone.wake, gone.wakeWidth);
- gone.wake = 0.0f;
- gone.velX = 0.0f;
- gone.velY = 0.0f;
- gone.trailCount = keepProtoTrail(gone.trail, gone.trailCount, gone.trail, 0);
- if (gone.trailCount == 0)
- {
- s_hazeLastSeen.erase(it++);
- continue;
- }
- }
- ++it;
- }
-
- // the bytes that were not zero and the ones that may not be now; nothing to send when both are
- // empty, which is a field with nothing going on
- ProtoFieldRect bytes = s_hazeWritten;
- if (!live.isEmpty())
- bytes.add(live.x0, live.y0, live.x1, live.y1);
- if (!bytes.isEmpty())
- {
- for (Int j = bytes.y0; j <= bytes.y1; ++j)
- {
- const Real *in = to + j * PROTO_FIELD;
- unsigned char *out = s_hazeFieldBytes + j * PROTO_FIELD;
- for (Int i = bytes.x0; i <= bytes.x1; ++i)
- out[i] = (unsigned char)(in[i] * 255.0f + 0.5f);
- }
- DX11Post_Set_Haze_Field(s_hazeFieldBytes);
- }
- s_hazeActive = live;
- s_hazeWritten = live;
-}
-
-/** The haze's motion for this frame, and a field step when one is due. */
-static void stirProtoHaze(Real top)
-{
- const Real now = protoHazeClock();
- Real elapsed = now - s_hazeLastClock;
- s_hazeLastClock = now;
- // a blended picture's clock counts from the logic's frame, one past the client's between ticks,
- // and the aircraft is drawn up to a frame behind its position
- const UnsignedInt standsOn = TheGameClient->getFrame() + (TheSmoothMotionActive ? 1 : 0);
- s_hazeClockLead = now - (Real)standsOn / (Real)LOGICFRAMES_PER_SECOND;
- // the first frame, a new match (the clock starts again) or a long hitch moves nothing; a pause
- // is no time at all
- if (elapsed < 0.0f || elapsed > 0.25f)
- elapsed = 0.0f;
- s_hazeSeconds += elapsed;
- // the drift wraps well before the noise's hash runs out of float precision
- // the times kept against it go back with it, or every wake's points read as laid in the future
- // and the wakes all vanished at the wrap
- if (s_hazeSeconds > 4000.0f)
- {
- s_hazeSeconds -= 4000.0f;
- for (std::map<DrawableID, ProtoHazeSeen>::iterator it = s_hazeLastSeen.begin(); it != s_hazeLastSeen.end(); ++it)
- {
- it->second.seenAt -= 4000.0f;
- for (Int index = 0; index < it->second.trailCount; ++index)
- it->second.trail[index][PROTO_POINT_AT] -= 4000.0f;
- }
- }
- s_hazeStepDue += elapsed;
- if (s_hazeStepDue >= 1.0f / PROTO_FIELD_RATE)
- {
- stepProtoHaze(top, s_hazeStepDue);
- s_hazeStepDue = 0.0f;
- }
-
- const Real cellSize = PROTO_FIELD_SPAN / (Real)PROTO_FIELD;
- const float rect[4] = { (Real)s_hazeFieldCellX * cellSize, (Real)s_hazeFieldCellY * cellSize,
- 1.0f / PROTO_FIELD_SPAN, 1.0f / PROTO_FIELD_SPAN };
-
- const GlobalData::TerrainLighting &sun = TheGlobalData->m_terrainObjectsLighting[TheGlobalData->m_timeOfDay][0];
- const Real length = (Real)sqrt(sun.lightPos.x * sun.lightPos.x + sun.lightPos.y * sun.lightPos.y
- + sun.lightPos.z * sun.lightPos.z);
- const float towardSun[3] = { -sun.lightPos.x / length, -sun.lightPos.y / length, -sun.lightPos.z / length };
- const Real daylight = (0.299f * sun.diffuse.red + 0.587f * sun.diffuse.green + 0.114f * sun.diffuse.blue - 0.25f) / 0.5f;
- const Real warmth = PROTO_HAZE_SUN_WARMTH * max(min(daylight, 1.0f), 0.0f);
-
- DX11Post_Set_Haze_Motion(rect, PROTO_HAZE_WIND[0] * s_hazeSeconds, PROTO_HAZE_WIND[1] * s_hazeSeconds,
- PROTO_HAZE_PATCH, PROTO_HAZE_STIR, towardSun, warmth);
-
- // each aircraft's wake: from where it is now (the last step's place moved on by its speed) back
- // along its trail, or two rings round it while it hovers; nearest the camera first, so the
- // segments run out on the aircraft furthest away
- float wakes[DX11_POST_HAZE_WAKE_LIMIT][8];
- unsigned wakeCount = 0;
- Coord3D look;
- TheTacticalView->getPosition(&look);
- // kept between frames, so a frame allocates nothing once it has held the most flyers
- static std::vector<std::pair<Real, const ProtoHazeSeen *> > flyers;
- flyers.clear();
- for (std::map<DrawableID, ProtoHazeSeen>::const_iterator it = s_hazeLastSeen.begin(); it != s_hazeLastSeen.end(); ++it)
- {
- if (it->second.trailCount == 0)
- continue;
- const Real offX = it->second.pos.x - look.x;
- const Real offY = it->second.pos.y - look.y;
- flyers.push_back(std::make_pair(offX * offX + offY * offY, &it->second));
- }
- std::sort(flyers.begin(), flyers.end());
- for (size_t order = 0; order < flyers.size() && wakeCount < DX11_POST_HAZE_WAKE_LIMIT; ++order)
- {
- const ProtoHazeSeen &flyer = *flyers[order].second;
- // Laying a wake now, the newest end is the aircraft itself; stopped (out of the band, landed,
- // fogged, gone), the wake keeps its last point as its newest end and fades out from there by
- // the time since that point was laid, wherever the aircraft went.
- const Bool laying = flyer.wake > 0.0f;
- const Real *newest = flyer.trail[0];
- const Real newestAge = max(s_hazeSeconds - newest[PROTO_POINT_AT], 0.0f);
- const Real strength = laying ? flyer.wake : newest[PROTO_POINT_STRENGTH];
- const Real width = laying ? flyer.wakeWidth : newest[PROTO_POINT_WIDTH];
- // up to a frame behind the step's under -video, whose pictures fall between two logic frames
- const Real since = min(max(s_hazeSeconds - flyer.seenAt, -1.0f / (Real)LOGICFRAMES_PER_SECOND), 0.1f);
- // straight under the aircraft (the last step's place moved on by its speed), the haze being
- // on the ground; every trail point keeps the place it was laid at, so the wake stays where it
- // was left and the aircraft moves on
- const Real tipX = laying ? flyer.pos.x + flyer.velX * since : newest[PROTO_POINT_X];
- const Real tipY = laying ? flyer.pos.y + flyer.velY * since : newest[PROTO_POINT_Y];
- const Real speed = (Real)sqrt(flyer.velX * flyer.velX + flyer.velY * flyer.velY);
- // Hovering goes by how far it got over the whole trail, not by the last step: a hovering
- // helicopter sways and slides, and stepped it reads faster than the hover speed while going
- // nowhere, which drew a wedge folded up under itself and no rings.
- Real travel = speed;
- if (flyer.trailCount > 0)
- {
- const Real *oldest = flyer.trail[flyer.trailCount - 1];
- const Real age = s_hazeSeconds - oldest[PROTO_POINT_AT];
- const Real awayX = flyer.pos.x - oldest[PROTO_POINT_X];
- const Real awayY = flyer.pos.y - oldest[PROTO_POINT_Y];
- if (age >= PROTO_WAKE_HOVER_SPAN)
- travel = (Real)sqrt(awayX * awayX + awayY * awayY) / age;
- }
- if (travel < PROTO_WAKE_HOVER_SPEED)
- {
- // left behind, the rings die down over the wake's life where it hovered last
- const Real left = laying ? 1.0f : max(1.0f - newestAge / PROTO_WAKE_LIFE, 0.0f);
- for (Int ripple = 0; ripple < 2 && wakeCount < DX11_POST_HAZE_WAKE_LIMIT && left > 0.0f; ++ripple)
- {
- Real phase = s_hazeSeconds / PROTO_RIPPLE_PERIOD + 0.5f * (Real)ripple;
- phase -= (Real)floor(phase);
- float *wake = wakes[wakeCount++];
- wake[0] = wake[2] = tipX;
- wake[1] = wake[3] = tipY;
- wake[4] = phase * PROTO_RIPPLE_REACH * width;
- wake[5] = -1.0f;
- wake[6] = strength * left;
- wake[7] = phase;
- }
- continue;
- }
- // a narrow V, narrower the faster it flies
- const Real quick = min(max((speed - PROTO_WAKE_HOVER_SPEED) / (PROTO_WAKE_FAST - PROTO_WAKE_HOVER_SPEED), 0.0f), 1.0f);
- const Real tangent = (Real)tan((PROTO_WAKE_ANGLE_SLOW + (PROTO_WAKE_ANGLE_FAST - PROTO_WAKE_ANGLE_SLOW) * quick) * PI / 180.0f);
- // the trail's travel can call it flying on a step it stood still
- Real perLength = 1.0f / (max(speed, PROTO_WAKE_HOVER_SPEED) * PROTO_WAKE_LIFE);
- Real nearX = tipX;
- Real nearY = tipY;
- // Left behind, the newest end is already as old as its point: the shader's age runs on the
- // distance behind the newest end, so the time since then goes in as a distance in front.
- const Real lead = laying ? 0.0f : newestAge / (PROTO_WAKE_LIFE * perLength);
- Real behind = lead;
- const unsigned firstWake = wakeCount;
- for (Int index = laying ? 0 : 1; index < flyer.trailCount && wakeCount < DX11_POST_HAZE_WAKE_LIMIT; ++index)
- {
- const Real farX = flyer.trail[index][PROTO_POINT_X];
- const Real farY = flyer.trail[index][PROTO_POINT_Y];
- const Real length = (Real)sqrt((farX - nearX) * (farX - nearX) + (farY - nearY) * (farY - nearY));
- if (length < 1.0f)
- continue;
- float *wake = wakes[wakeCount++];
- wake[0] = farX;
- wake[1] = farY;
- wake[2] = nearX;
- wake[3] = nearY;
- wake[4] = behind;
- // as wide and as strong as the height it was laid at
- wake[5] = tangent * flyer.trail[index][PROTO_POINT_WIDTH];
- wake[6] = flyer.trail[index][PROTO_POINT_STRENGTH];
- wake[7] = perLength;
- behind += length;
- nearX = farX;
- nearY = farY;
- }
- // The wake has faded out by the trail's last point, however short the trail is against the
- // speed (one speeding up, one cut off by the segment limit): ending at full strength, the last
- // segment's square end drew a straight edge across the strip. Left behind, the trail's own
- // length still measures from the newest end, so the lead keeps growing with the clock.
- const Real span = behind - lead;
- if (span > 1.0f)
- {
- const Real least = 1.0f / span;
- if (perLength < least)
- {
- for (unsigned index = firstWake; index < wakeCount; ++index)
- {
- wakes[index][4] = (wakes[index][4] - lead) + lead * perLength / least;
- wakes[index][7] = least;
- }
- }
- }
- }
- DX11Post_Set_Haze_Wakes(wakes, wakeCount, PROTO_WAKE_VORTEX, PROTO_WAKE_OPEN_SOFT, s_hazeSeconds);
-}
-
// The haze's levels hold for the whole match (the ground and the water areas do not move), so they
// are worked out once a map: the median walks a quarter of the height map's cells. The shell map
// and the match's are made one after the other and may land at the same address, so the key is the
@@ -952,6 +330,8 @@ static void pushProtoHazeFrame(void)
Real rise = PROTO_HAZE_MIN_RISE;
Real water = -1.0e6f;
float colour[3] = { PROTO_HAZE_COLOUR[0], PROTO_HAZE_COLOUR[1], PROTO_HAZE_COLOUR[2] };
+ float towardSun[3] = { 0.0f, 0.0f, 1.0f };
+ Real warmth = 0.0f;
if (TheTerrainRenderObject != NULL && TheTerrainRenderObject->getMap() != NULL)
{
WorldHeightMap *map = TheTerrainRenderObject->getMap();
@@ -987,8 +367,18 @@ static void pushProtoHazeFrame(void)
colour[0] *= dim;
colour[1] *= dim;
colour[2] *= dim;
+
+ // Toward the sun the haze looks warmer, the more so the brighter the sun.
+ const GlobalData::TerrainLighting &objectSun = TheGlobalData->m_terrainObjectsLighting[TheGlobalData->m_timeOfDay][0];
+ const Real length = (Real)sqrt(objectSun.lightPos.x * objectSun.lightPos.x + objectSun.lightPos.y * objectSun.lightPos.y
+ + objectSun.lightPos.z * objectSun.lightPos.z);
+ towardSun[0] = -objectSun.lightPos.x / length;
+ towardSun[1] = -objectSun.lightPos.y / length;
+ towardSun[2] = -objectSun.lightPos.z / length;
+ const Real daylight = (0.299f * objectSun.diffuse.red + 0.587f * objectSun.diffuse.green + 0.114f * objectSun.diffuse.blue - 0.25f) / 0.5f;
+ warmth = max(min(daylight, 1.0f), 0.0f);
}
- DX11Post_Set_Haze(colour, top, rise, strength, PROTO_HAZE_REACH, water);
+ DX11Post_Set_Haze(colour, top, rise, strength, PROTO_HAZE_REACH, water, towardSun, warmth);
// The fog the terrain draws, through the terrain's own mapping (ShroudTextureShader::set): the
// texture starts a cell before the draw origin, a texel to a cell.
@@ -1004,8 +394,6 @@ static void pushProtoHazeFrame(void)
const float wholeRect[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
Direct3D11_Set_Haze_Shroud(NULL, wholeRect);
}
- if (strength > 0.0f)
- stirProtoHaze(top);
}
#endif
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
index 2392fe7c6..318d20794 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp
@@ -128,8 +128,10 @@ static float HazeStrength = 0.0f;
static float HazeReach = 1.0f;
static float HazeWater = -1.0e6f;
+static float HazeSun[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
+
void DX11Post_Set_Haze(const float colour[3], float top, float thickness, float strength, float reach,
- float water)
+ float water, const float toward_sun[3], float warmth)
{
HazeWater = water;
HazeColour[0] = colour[0];
@@ -139,55 +141,12 @@ void DX11Post_Set_Haze(const float colour[3], float top, float thickness, float
HazeThickness = thickness;
HazeStrength = strength;
HazeReach = reach;
-}
-
-static float HazeFieldRect[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-static float HazeMotion[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-static float HazeSun[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
-static unsigned char HazeFieldTexels[DX11_POST_HAZE_FIELD_SIZE * DX11_POST_HAZE_FIELD_SIZE];
-static bool HazeFieldDirty = false;
-
-void DX11Post_Set_Haze_Motion(const float field_rect[4], float drift_x, float drift_y,
- float noise_scale, float stir, const float toward_sun[3], float warmth)
-{
- memcpy(HazeFieldRect, field_rect, sizeof(HazeFieldRect));
- HazeMotion[0] = drift_x;
- HazeMotion[1] = drift_y;
- HazeMotion[2] = noise_scale;
- HazeMotion[3] = stir;
HazeSun[0] = toward_sun[0];
HazeSun[1] = toward_sun[1];
HazeSun[2] = toward_sun[2];
HazeSun[3] = warmth;
}
-void DX11Post_Set_Haze_Field(const unsigned char * texels)
-{
- memcpy(HazeFieldTexels, texels, sizeof(HazeFieldTexels));
- HazeFieldDirty = true;
-}
-
-static float HazeWakeInfo[4] = { 0.0f, 1.0f, 1.0f, 0.0f };
-static float HazeWakeEnds[DX11_POST_HAZE_WAKE_LIMIT][4];
-static float HazeWakeShape[DX11_POST_HAZE_WAKE_LIMIT][4];
-static float HazeClock[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-
-void DX11Post_Set_Haze_Wakes(const float (*segments)[8], unsigned count, float arm_width, float open_soft,
- float seconds)
-{
- HazeClock[0] = seconds;
- if (count > DX11_POST_HAZE_WAKE_LIMIT) {
- count = DX11_POST_HAZE_WAKE_LIMIT;
- }
- for (unsigned index = 0; index < count; ++index) {
- memcpy(HazeWakeEnds[index], &segments[index][0], sizeof(HazeWakeEnds[0]));
- memcpy(HazeWakeShape[index], &segments[index][4], sizeof(HazeWakeShape[0]));
- }
- HazeWakeInfo[0] = static_cast<float>(count);
- HazeWakeInfo[1] = arm_width;
- HazeWakeInfo[2] = open_soft;
-}
-
static ID3D11ShaderResourceView * HazeShroudSource = NULL;
static float HazeShroudRect[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
@@ -197,31 +156,6 @@ void DX11Post_Set_Haze_Shroud(ID3D11ShaderResourceView * view, const float rect[
memcpy(HazeShroudRect, rect, sizeof(HazeShroudRect));
}
-/** A single channel eight bit texture of size by size for the haze, made on first use; false
- when the device refused it. */
-static bool make_haze_texture(ID3D11Device * device, unsigned size, ID3D11Texture2D ** texture,
- ID3D11ShaderResourceView ** view)
-{
- if (*texture != NULL) {
- return true;
- }
- D3D11_TEXTURE2D_DESC description;
- ZeroMemory(&description, sizeof(description));
- description.Width = size;
- description.Height = size;
- description.MipLevels = 1;
- description.ArraySize = 1;
- description.Format = DXGI_FORMAT_R8_UNORM;
- description.SampleDesc.Count = 1;
- description.Usage = D3D11_USAGE_DEFAULT;
- description.BindFlags = D3D11_BIND_SHADER_RESOURCE;
- if (FAILED(device->CreateTexture2D(&description, NULL, texture))) {
- return false;
- }
- device->CreateShaderResourceView(*texture, NULL, view);
- return true;
-}
-
static DX11PostWarp Warps[DX11_POST_WARP_LIMIT];
static unsigned WarpCount = 0;
@@ -268,20 +202,10 @@ struct PostConstantBlock
float Haze[4];
float HazeColour[4];
float WorldFromClip[16];
- // Then the disturbance field's world rectangle (origin, one over size), the wind's drift so far,
- // the noise scale and the field's strength, and the way toward the sun with its warmth.
- float HazeField[4];
- float HazeMotion[4];
+ // Then the way toward the sun with its warmth.
float HazeSun[4];
// The shroud light's world rectangle (origin, one over size).
float HazeShroudRect[4];
- // The aircraft wakes: their count, arm width and opening ease, then each segment's ends and
- // its shape.
- float HazeWakeInfo[4];
- float HazeWakeEnds[DX11_POST_HAZE_WAKE_LIMIT][4];
- float HazeWakeShape[DX11_POST_HAZE_WAKE_LIMIT][4];
- // The picture's clock in seconds, in x.
- float HazeClock[4];
};
// A triangle big enough to cover the screen, made out of nothing. No vertex buffer and no input
@@ -563,42 +487,15 @@ static const char * const AO_SCENE_SHADER_BODY =
// Oasis's low plateau takes: the bank under it went milky at the full amount, and still a little
// at 0.62.
//
-// The layer is not even. Four points along the last stretch of the eye's ray inside the layer
-// read two octaves of value noise drifting with the wind, each at its own height so the patches
-// part with parallax as the camera moves. Their mean, eased so the patches have soft edges and
-// clear gaps, scales the amount between 0.65 and 1.35 of the even layer (one on average, so a
-// map's average haze is what it was; 0.3 to 1.7 went to a flat milky plate on the low bank), and
-// the dense patches come out a touch paler, which keeps them apart from the map's darker cloud
-// shadows. The disturbance field (t2, DX11Post_Set_Haze_Field) clears the haze where something
-// went through, read at the same four points along the ray: looking down that is the ground under
-// the pixel, and across a far bank the ray passes through the lane only partly, so a lane there
-// thins instead of standing up as a wall with a doorway in it. The clearing eases in over a wide
-// band and takes less with distance; its slope pushes the noise outward by up to HAZE_SWIRL world
-// units and piles a faint extra on the rim (a bright rim read as a crater's edge).
-//
-// Aircraft disturb the haze in a wedge, the Mach cone or a boat's wake seen from above: its point
-// at the aircraft, two arms spreading back along its recent path (DX11Post_Set_Haze_Wakes, a few
-// segments, so a turn bends the wedge). Nothing is drawn on top: the wedge is a mask that moves
-// the haze already there. A pixel's distance behind the aircraft along the path and its distance
-// off the path decide it. Along each arm, where the second is the first times the half-angle's
-// tangent plus a drift outward with age (HAZE_WAKE_DRIFT), sits a wingtip vortex: it pushes the
-// haze outward (HAZE_WAKE_PUSH world units) and rolls it along the arm, the two sides turning
-// opposite ways on the picture's clock (HAZE_WAKE_ROLL, HAZE_WAKE_SPIN), smearing wider as it ages
-// (HAZE_WAKE_SMEAR). Curl noise breaks the push up (HAZE_WAKE_TURB), and inside the wake a finer
-// grain of haze rides the same displacement (HAZE_WAKE_GRAIN), so what shows is haze texture
-// bending and parting. Inside the arms the lane tears open (HAZE_WAKE_TATTER_SCALE noise, eased
-// so the torn holes clear right down to the ground and the rest keeps HAZE_WAKE_TATTER_KEEP of the
-// clearing) and fills back in from the sides after HAZE_WAKE_FILL_FROM of the wake's life. The
-// haze the vortices push out piles on them (HAZE_WAKE_PILE, up to twice the haze there), and they
-// lift a little more out of the layer below (HAZE_WAKE_LIFT of the full layer, in clumps of the
-// fine grain), which is what still shows over a bank where the haze is too thin for a clearing in
-// it to read. A pixel whose foot on a segment falls past either end belongs to the next segment
-// and is skipped. A hovering helicopter's segments are rings instead: the same vortex pushed radially outward and
-// rolling round the ring, the disc inside cleared, travelling out as the ring ages. A weaker
-// segment (an aircraft higher over the haze) spreads its vortices wider, up to HAZE_WAKE_HIGH_SOFT
-// more at nothing, so a high pass reads soft and a low one sharp.
+// The layer is not even, and it holds still: nothing moves it. Four points along the last stretch
+// of the eye's ray inside the layer read two octaves of value noise fixed to the world, each at its
+// own height so the patches part with parallax as the camera moves. Their mean, eased so the
+// patches have soft edges and clear gaps, scales the amount between 0.65 and 1.35 of the even layer
+// (one on average, so a map's average haze is what it was; 0.3 to 1.7 went to a flat milky plate on
+// the low bank), and the dense patches come out a touch paler, which keeps them apart from the
+// map's darker cloud shadows.
//
-// The shroud has already darkened the ground under the haze by its light (t3, the very texture the
+// The shroud has already darkened the ground under the haze by its light (t2, the very texture the
// terrain multiplies by, through the terrain's own mapping, so the two cannot disagree; a copy read
// through W3DShroud::getShroudLevel did, by cells and by a stair-step edge), so the haze takes
// that light too, its colour once and its amount three times over: in the fog
@@ -613,41 +510,12 @@ static const char * const HAZE_SHADER_BODY =
" float4 Haze : packoffset(c13);\n"
" float4 HazeColour : packoffset(c14);\n"
" row_major float4x4 WorldFromClip : packoffset(c15);\n"
- " float4 HazeField : packoffset(c19);\n"
- " float4 HazeMotion : packoffset(c20);\n"
- " float4 HazeSun : packoffset(c21);\n"
- " float4 HazeShroudRect : packoffset(c22);\n"
- " float4 HazeWakeInfo : packoffset(c23);\n"
- " float4 HazeWakeEnds[" DX11_POST_HAZE_WAKE_LIMIT_TEXT "] : packoffset(c24);\n"
- " float4 HazeWakeShape[" DX11_POST_HAZE_WAKE_LIMIT_TEXT "] : packoffset(" DX11_POST_HAZE_WAKE_SHAPE_REGISTER_TEXT ");\n"
- " float4 HazeClock : packoffset(" DX11_POST_HAZE_CLOCK_REGISTER_TEXT ");\n"
+ " float4 HazeSun : packoffset(c19);\n"
+ " float4 HazeShroudRect : packoffset(c20);\n"
"};\n"
- "Texture2D HazeStir : register(t2);\n"
- "Texture2D HazeShroud : register(t3);\n"
- "static const float HAZE_FIELD_TEXEL = 1.0 / " DX11_POST_HAZE_FIELD_SIZE_TEXT ".0;\n"
- "static const float HAZE_SWIRL = 140.0;\n"
- "static const float HAZE_RIM_GAIN = 1.5;\n"
+ "Texture2D HazeShroud : register(t2);\n"
+ "static const float HAZE_PATCH = 1.0 / 320.0;\n"
"static const float HAZE_LOW_CAP = 0.5;\n"
- "static const float HAZE_WAKE_PILE = 1.0;\n"
- "static const float HAZE_WAKE_LIFT = 0.8;\n"
- "static const float HAZE_WAKE_TATTER_KEEP = 0.45;\n"
- "static const float HAZE_WAKE_HOLD = 0.55;\n"
- "static const float HAZE_WAKE_GONE = 0.85;\n"
- "static const float HAZE_WAKE_END_SCALE = 1.0 / 20.0;\n"
- "static const float HAZE_WAKE_END_BREAK = 0.3;\n"
- "static const float HAZE_WAKE_SIDE_SOFT = 0.6;\n"
- "static const float HAZE_WAKE_HIGH_SOFT = 1.5;\n"
- "static const float HAZE_WAKE_DRIFT = 16.0;\n"
- "static const float HAZE_WAKE_SMEAR = 2.5;\n"
- "static const float HAZE_WAKE_PUSH = 24.0;\n"
- "static const float HAZE_WAKE_ROLL = 14.0;\n"
- "static const float HAZE_WAKE_SPIN = 5.0;\n"
- "static const float HAZE_WAKE_FILL_FROM = 0.25;\n"
- "static const float HAZE_WAKE_TURB_SCALE = 1.0 / 18.0;\n"
- "static const float HAZE_WAKE_TURB = 18.0;\n"
- "static const float HAZE_WAKE_TATTER_SCALE = 1.0 / 14.0;\n"
- "static const float HAZE_WAKE_GRAIN = 1.0 / 22.0;\n"
- "static const float HAZE_WAKE_GRAIN_SHOW = 0.8;\n"
"\n"
"float haze_hash(float2 p)\n"
"{\n"
@@ -666,11 +534,6 @@ static const char * const HAZE_SHADER_BODY =
" return lerp(lerp(a, b, f.x), lerp(c, d, f.x), f.y);\n"
"}\n"
"\n"
- "float haze_stir(float2 at)\n"
- "{\n"
- " return HazeStir.SampleLevel(Sampler, at, 0.0).r;\n"
- "}\n"
- "\n"
"float4 main(VertexOutput input) : SV_TARGET\n"
"{\n"
" float raw = Extra.Sample(Sampler, input.Texture).r;\n"
@@ -690,101 +553,17 @@ static const char * const HAZE_SHADER_BODY =
" bank = bank * bank * (3.0 - 2.0 * bank);\n"
" amount *= bank;\n"
"\n"
- " float2 field = (world.xy - HazeField.xy) * HazeField.zw;\n"
- " float2 slope = float2(haze_stir(field + float2(HAZE_FIELD_TEXEL, 0.0)) - haze_stir(field - float2(HAZE_FIELD_TEXEL, 0.0)),\n"
- " haze_stir(field + float2(0.0, HAZE_FIELD_TEXEL)) - haze_stir(field - float2(0.0, HAZE_FIELD_TEXEL)));\n"
- "\n"
- " float2 warp = float2(0.0, 0.0);\n"
- " float wakeClear = 0.0;\n"
- " float wakeStir = 0.0;\n"
- " float endBreak = (haze_noise(world.xy * HAZE_WAKE_END_SCALE + 11.0) - 0.5) * HAZE_WAKE_END_BREAK;\n"
- " for (int wake = 0; wake < " DX11_POST_HAZE_WAKE_LIMIT_TEXT "; ++wake)\n"
- " {\n"
- " if (wake >= (int)HazeWakeInfo.x) break;\n"
- " float4 ends = HazeWakeEnds[wake];\n"
- " float4 shape = HazeWakeShape[wake];\n"
- " float2 outward;\n"
- " float2 across;\n"
- " float off;\n"
- " float edge;\n"
- " float age;\n"
- " float hand;\n"
- " if (shape.y < 0.0)\n"
- " {\n"
- " float2 fromCentre = world.xy - ends.zw;\n"
- " off = length(fromCentre);\n"
- " outward = fromCentre / max(off, 0.001);\n"
- " across = float2(-outward.y, outward.x);\n"
- " edge = shape.x;\n"
- " age = shape.w;\n"
- " hand = 1.0;\n"
- " }\n"
- " else\n"
- " {\n"
- " float2 back = ends.xy - ends.zw;\n"
- " float2 fromNear = world.xy - ends.zw;\n"
- " float span2 = max(dot(back, back), 0.0001);\n"
- " float along = dot(fromNear, back) / span2;\n"
- " if (along < 0.0 || along > 1.0) continue;\n"
- " float behind = shape.x + along * sqrt(span2);\n"
- " float2 sideways = fromNear - back * along;\n"
- " off = length(sideways);\n"
- " outward = sideways / max(off, 0.001);\n"
- " across = back * rsqrt(span2);\n"
- " hand = (back.x * fromNear.y - back.y * fromNear.x) >= 0.0 ? 1.0 : -1.0;\n"
- " age = behind * shape.w;\n"
- " edge = behind * shape.y + age * HAZE_WAKE_DRIFT;\n"
- " }\n"
- " float fade = (1.0 - smoothstep(HAZE_WAKE_HOLD, HAZE_WAKE_GONE, age + endBreak)) * shape.z;\n"
- " if (fade <= 0.0) continue;\n"
- " float spread = HazeWakeInfo.y * (1.0 + age * HAZE_WAKE_SMEAR) * (1.0 + HAZE_WAKE_HIGH_SOFT * (1.0 - shape.z));\n"
- " float arm = (off - edge) / spread;\n"
- " float vortex = exp(-arm * arm) * fade;\n"
- " float roll = sin(arm * 2.2 - HazeClock.x * HAZE_WAKE_SPIN * hand);\n"
- " warp += outward * vortex * HAZE_WAKE_PUSH * (1.0 - 0.5 * age) + across * vortex * roll * HAZE_WAKE_ROLL * hand;\n"
- " float lane = saturate((edge * (1.0 - smoothstep(HAZE_WAKE_FILL_FROM, 1.0, age)) - off + endBreak * spread)\n"
- " / max(HazeWakeInfo.z, spread * HAZE_WAKE_SIDE_SOFT));\n"
- " wakeClear = max(wakeClear, lane * fade);\n"
- " wakeStir = max(wakeStir, vortex);\n"
- " }\n"
- " float wakeTouch = saturate(wakeStir + wakeClear);\n"
- " if (wakeTouch > 0.001)\n"
- " {\n"
- " float2 t = world.xy * HAZE_WAKE_TURB_SCALE + HazeClock.x * 0.7;\n"
- " float2 curl = float2(haze_noise(t + float2(0.0, 0.5)) - haze_noise(t - float2(0.0, 0.5)),\n"
- " haze_noise(t - float2(0.5, 0.0)) - haze_noise(t + float2(0.5, 0.0)));\n"
- " warp += curl * HAZE_WAKE_TURB * wakeTouch;\n"
- " float tatter = haze_noise((world.xy - warp) * HAZE_WAKE_TATTER_SCALE + HazeClock.x * 0.3);\n"
- " wakeClear *= lerp(HAZE_WAKE_TATTER_KEEP, 1.0, smoothstep(0.3, 0.7, tatter));\n"
- " }\n"
- "\n"
" float3 ray = world.xyz - eye.xyz;\n"
" float entry = (eye.z > Haze.x && abs(ray.z) > 0.0001) ? saturate((Haze.x - eye.z) / ray.z) : 0.0;\n"
- " float2 shove = slope * HAZE_SWIRL * HazeMotion.z;\n"
" float patches = 0.0;\n"
- " float stir = 0.0;\n"
" for (int tap = 0; tap < 4; ++tap)\n"
" {\n"
" float3 at = eye.xyz + ray * lerp(entry, 1.0, ((float)tap + 0.5) * 0.25);\n"
- " float2 q = (at.xy - warp - HazeMotion.xy) * HazeMotion.z - shove + at.z * 0.011;\n"
+ " float2 q = at.xy * HAZE_PATCH + at.z * 0.011;\n"
" patches += haze_noise(q) * 0.7 + haze_noise(q * 2.7 + 17.0) * 0.3;\n"
- " stir += haze_stir((at.xy - HazeField.xy) * HazeField.zw);\n"
" }\n"
" float dense = smoothstep(0.28, 0.72, patches * 0.25);\n"
" amount *= lerp(0.65, 1.35, dense);\n"
- " float fine = 0.0;\n"
- " if (wakeTouch > 0.001)\n"
- " {\n"
- " float2 grain = (world.xy - warp - HazeMotion.xy * 0.5) * HAZE_WAKE_GRAIN;\n"
- " fine = haze_noise(grain) * 0.6 + haze_noise(grain * 2.3 + 31.0) * 0.4;\n"
- " amount *= lerp(1.0, 0.4 + 1.2 * fine, wakeTouch * HAZE_WAKE_GRAIN_SHOW);\n"
- " }\n"
- "\n"
- " float clear = max(HazeMotion.w * smoothstep(0.05, 0.6, stir * 0.25), wakeClear) * lerp(1.0, 0.6, reach);\n"
- " float rim = saturate(length(slope) * HAZE_RIM_GAIN) * (1.0 - clear);\n"
- " float pushed = wakeStir * (1.0 - clear);\n"
- " amount *= (1.0 - clear) * (1.0 + 0.12 * rim + HAZE_WAKE_PILE * pushed);\n"
- " amount += HAZE_WAKE_LIFT * Haze.z * HAZE_LOW_CAP * saturate(below * 4.0) * bank * pushed * smoothstep(0.3, 0.8, fine);\n"
"\n"
" float2 look = ray.xy * rsqrt(max(dot(ray.xy, ray.xy), 0.0001));\n"
" float2 sun = HazeSun.xy * rsqrt(max(dot(HazeSun.xy, HazeSun.xy), 0.0001));\n"
@@ -1040,8 +819,6 @@ DX11PostProcessClass::DX11PostProcessClass()
, Occluded(false)
, Hazed(false)
, HazeRefused(false)
- , HazeFieldTexture(NULL)
- , HazeFieldView(NULL)
, HazeShroudView(NULL)
{
memset(HazeWorldFromClip, 0, sizeof(HazeWorldFromClip));
@@ -1083,12 +860,8 @@ bool DX11PostProcessClass::Initialise(DX11DeviceClass * device)
void DX11PostProcessClass::Shutdown()
{
Release_Targets();
- release_interface(reinterpret_cast<IUnknown **>(&HazeFieldView));
- release_interface(reinterpret_cast<IUnknown **>(&HazeFieldTexture));
HazeShroudView = NULL;
HazeShroudSource = NULL;
- // A new device starts without it, so the next upload has to make it.
- HazeFieldDirty = true;
release_interface(reinterpret_cast<IUnknown **>(&ConstantBuffer));
release_interface(reinterpret_cast<IUnknown **>(&RasterizerState));
release_interface(reinterpret_cast<IUnknown **>(&DepthState));
@@ -1456,13 +1229,6 @@ bool DX11PostProcessClass::Haze_Scene(ID3D11ShaderResourceView * depth,
}
memcpy(HazeWorldFromClip, world_from_clip, sizeof(HazeWorldFromClip));
- if (HazeFieldDirty) {
- if (make_haze_texture(Device->Get_Device(), DX11_POST_HAZE_FIELD_SIZE, &HazeFieldTexture, &HazeFieldView)) {
- Device->Get_Context()->UpdateSubresource(HazeFieldTexture, 0, NULL, HazeFieldTexels,
- DX11_POST_HAZE_FIELD_SIZE, 0);
- }
- HazeFieldDirty = false;
- }
// Borrowed for this frame only: the shroud's texture (and so its mirror) can be freed by the
// next map or a shroud reset, and a frame that set none draws with none.
HazeShroudView = HazeShroudSource;
@@ -1577,16 +1343,10 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
block.HazeColour[2] = HazeColour[2];
block.HazeColour[3] = HazeWater;
memcpy(block.WorldFromClip, HazeWorldFromClip, sizeof(block.WorldFromClip));
- memcpy(block.HazeField, HazeFieldRect, sizeof(block.HazeField));
- memcpy(block.HazeMotion, HazeMotion, sizeof(block.HazeMotion));
memcpy(block.HazeSun, HazeSun, sizeof(block.HazeSun));
// the program reads only the sun's bearing, so its z says whether a shroud texture is bound
block.HazeSun[2] = (HazeShroudView != NULL) ? 1.0f : 0.0f;
memcpy(block.HazeShroudRect, HazeShroudRect, sizeof(block.HazeShroudRect));
- memcpy(block.HazeWakeInfo, HazeWakeInfo, sizeof(block.HazeWakeInfo));
- memcpy(block.HazeWakeEnds, HazeWakeEnds, sizeof(block.HazeWakeEnds));
- memcpy(block.HazeWakeShape, HazeWakeShape, sizeof(block.HazeWakeShape));
- memcpy(block.HazeClock, HazeClock, sizeof(block.HazeClock));
memcpy(mapped.pData, &block, sizeof(block));
context->Unmap(ConstantBuffer, 0);
@@ -1620,17 +1380,16 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)
const bool haze = (pass.Shader == HazeShader);
if (haze) {
// The same buffer at b1 as well, where the haze program reads its own fields of it, and
- // the disturbance field at t2 (none yet reads as an unstirred field).
+ // the shroud at t2.
context->PSSetConstantBuffers(1, 1, &ConstantBuffer);
- ID3D11ShaderResourceView * haze_resources[2] = { HazeFieldView, HazeShroudView };
- context->PSSetShaderResources(2, 2, haze_resources);
+ context->PSSetShaderResources(2, 1, &HazeShroudView);
}
context->Draw(FULL_SCREEN_VERTEX_COUNT, 0);
if (haze) {
- ID3D11ShaderResourceView * no_haze_resources[2] = { NULL, NULL };
- context->PSSetShaderResources(2, 2, no_haze_resources);
+ ID3D11ShaderResourceView * no_haze_resource = NULL;
+ context->PSSetShaderResources(2, 1, &no_haze_resource);
}
// The texture this pass read is the target the next one writes, and D3D11 unbinds a resource
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
index 9ea3425db..78f818c43 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h
@@ -127,23 +127,10 @@ void DX11Post_Set_Grade(float amount);
// height. Top is the world height the haze thins out to nothing at, thickness how far below that
// it reaches full strength, strength the most of the haze colour a pixel takes (zero, the default,
// is no pass at all) and reach the eye distance at which it stops thickening. Nothing below water,
-// the world height of the water surface the haze lies over, takes any. Set every frame.
+// the world height of the water surface the haze lies over, takes any. Toward_sun points at the
+// sun and warmth is how much warmer the haze looks toward it. Set every frame.
void DX11Post_Set_Haze(const float colour[3], float top, float thickness, float strength, float reach,
- float water);
-
-// The haze's movement. Field_rect is the world rectangle the disturbance field covers, as its
-// origin and one over its size on each axis; drift is how far the wind has carried the haze's
-// patches so far, in world units; noise_scale is one over a patch's size; stir is how much of the
-// haze a full field takes away; toward_sun points at the sun and warmth is how much warmer the
-// haze looks toward it. Set every frame with the haze.
-void DX11Post_Set_Haze_Motion(const float field_rect[4], float drift_x, float drift_y,
- float noise_scale, float stir, const float toward_sun[3], float warmth);
-
-// The disturbance field: what passed through the haze lately, size by size bytes, row by row from
-// the field's origin, 255 where it is most stirred. Uploaded at the next haze pass.
-const unsigned DX11_POST_HAZE_FIELD_SIZE = 256;
-#define DX11_POST_HAZE_FIELD_SIZE_TEXT "256"
-void DX11Post_Set_Haze_Field(const unsigned char * texels);
+ float water, const float toward_sun[3], float warmth);
// The view of the shroud texture the terrain draws its fog with (Direct3D11_Set_Haze_Shroud finds
// it), and the terrain's own world to texture mapping (rect: world origin x, y, then one over the
@@ -152,25 +139,6 @@ void DX11Post_Set_Haze_Field(const unsigned char * texels);
// 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 wakes aircraft leave in the haze, as segments of their recent paths. A segment is eight
-// numbers: its far end x, y and its near end x, y (the end toward the aircraft), then how far
-// behind the aircraft along the path its near end lies, the tangent of the wake's half-angle, the
-// wake's strength (0 to 1) and one over the path length the wake lasts. Behind the aircraft the
-// haze is pushed apart in a wedge whose edges stand off the path by distance behind times that
-// tangent: along each edge a vortex arm_width world units across stirs and rolls the haze, and
-// the inside clears, easing open over open_soft. A segment with a negative tangent is a ring
-// instead: both ends the centre, its first number the radius and its last how far through its
-// life it is (0 to 1). seconds is the picture's clock, which turns the vortices. Set every
-// frame; a count past the limit keeps the first ones.
-const unsigned DX11_POST_HAZE_WAKE_LIMIT = 64;
-#define DX11_POST_HAZE_WAKE_LIMIT_TEXT "64"
-// Where the segments' second halves start in the haze program's constants: c24 plus the limit,
-// and the clock after them.
-#define DX11_POST_HAZE_WAKE_SHAPE_REGISTER_TEXT "c88"
-#define DX11_POST_HAZE_CLOCK_REGISTER_TEXT "c152"
-void DX11Post_Set_Haze_Wakes(const float (*segments)[8], unsigned count, float arm_width, float open_soft,
- float seconds);
-
// 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
@@ -378,9 +346,6 @@ private:
float HazeWorldFromClip[16];
// The haze program, compiled on first use, failed to compile; not tried again.
bool HazeRefused;
- // The haze's disturbance field on the device, made at its first upload.
- ID3D11Texture2D * HazeFieldTexture;
- ID3D11ShaderResourceView * HazeFieldView;
// The terrain's shroud texture under the haze, borrowed from its D3D9 texture each pass.
ID3D11ShaderResourceView * HazeShroudView;
char Diagnostic[192];
diff --git a/GeneralsMD/Code/Tests/test_dx11post.cpp b/GeneralsMD/Code/Tests/test_dx11post.cpp
index ec9d1dc66..75d0ec8fd 100644
--- a/GeneralsMD/Code/Tests/test_dx11post.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11post.cpp
@@ -688,33 +688,31 @@ TEST(dx11post_the_scene_takes_its_occlusion_once_a_frame_and_the_chain_then_skip
delete [] picture;
}
-// The prototype haze, white over a black scene, with the given wakes; hands back the level at the
-// middle of the picture and at a corner. The clip to world matrix is the identity, so a pixel's
-// world x and y are its own clip x and y and the depth, cleared to a half, is its height: under the
-// haze's top of one.
-static bool haze_levels(DeviceFixture & fixture, const float (*segments)[8], unsigned count,
- unsigned char & middle_level, unsigned char & corner_level)
+// The ground haze, white over a black scene, drawn for real: the program compiles, finds its constants
+// where the pass writes them and lays the layer over the ground. The clip to world matrix is the
+// identity, so a pixel's world x and y are its own clip x and y and the depth, cleared to a half, is
+// its height: under the haze's top of one.
+TEST(dx11post_the_ground_haze_lies_over_a_scene_under_its_top)
{
- const float WAKE_SPREAD = 0.05f;
- const float OPEN_SOFT = 0.05f;
+ DeviceFixture fixture;
+ if (!fixture.Create()) {
+ printf("skip: no Direct3D 11 device on this machine\n");
+ return;
+ }
+
const float HAZE_TOP = 1.0f;
const float HAZE_THICKNESS = 1.0f;
const float HAZE_STRENGTH = 1.0f;
const float HAZE_REACH = 1000.0f;
const float NO_WATER = -1.0e6f;
- const float NOISE_SCALE = 1.0f;
- const float STIR = 0.85f;
const float SCENE_DEPTH = 0.5f;
- const float CLOCK = 1.0f;
+ const unsigned char LIFTED_BY_AT_LEAST = 16;
DX11DeviceClass & device = fixture.Get_Device();
DX11PostProcessClass & post = fixture.Get_Post();
- DX11Post_Set_Haze_Wakes(segments, count, WAKE_SPREAD, OPEN_SOFT, CLOCK);
const float white[3] = { 1.0f, 1.0f, 1.0f };
- DX11Post_Set_Haze(white, HAZE_TOP, HAZE_THICKNESS, HAZE_STRENGTH, HAZE_REACH, NO_WATER);
- const float field[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
const float overhead[3] = { 0.0f, 0.0f, 1.0f };
- DX11Post_Set_Haze_Motion(field, 0.0f, 0.0f, NOISE_SCALE, STIR, overhead, 0.0f);
+ DX11Post_Set_Haze(white, HAZE_TOP, HAZE_THICKNESS, HAZE_STRENGTH, HAZE_REACH, NO_WATER, overhead, 0.0f);
unsigned char picture[SURFACE_SIZE * SURFACE_SIZE * BYTES_A_PIXEL];
fill_flat(picture, DARK_LEVEL);
@@ -731,52 +729,14 @@ static bool haze_levels(DeviceFixture & fixture, const float (*segments)[8], uns
const bool drawn = write_scene(device, post, picture)
&& post.Haze_Scene(device.Get_Depth_Texture(), identity) && post.Run_Chain();
device.Set_Scene_View(NULL);
- DX11Post_Set_Haze(white, 0.0f, HAZE_THICKNESS, 0.0f, HAZE_REACH, NO_WATER);
- DX11Post_Set_Haze_Wakes(segments, 0, WAKE_SPREAD, OPEN_SOFT, CLOCK);
+ DX11Post_Set_Haze(white, 0.0f, HAZE_THICKNESS, 0.0f, HAZE_REACH, NO_WATER, overhead, 0.0f);
+ CHECK(drawn);
unsigned pitch = 0;
unsigned char * result = drawn ? read_back_buffer(device, pitch) : NULL;
- if (result == NULL) {
- return false;
- }
- middle_level = pixel_level(result, pitch, SURFACE_SIZE / 2, SURFACE_SIZE / 2);
- corner_level = pixel_level(result, pitch, 1, 1);
- delete [] result;
- return true;
-}
-
-// A hovering helicopter's rotor wash, drawn for real: the disc inside its ring clears, and the haze
-// well outside it is left as it was. The ring sits in a late slot behind segments far off the
-// picture, which is where the second half of each segment lives past the first 32.
-TEST(dx11post_a_hover_ring_parts_the_haze_inside_it_in_any_slot)
-{
- DeviceFixture fixture;
- if (!fixture.Create()) {
- printf("skip: no Direct3D 11 device on this machine\n");
- return;
+ CHECK(result != NULL);
+ if (result != NULL) {
+ CHECK(pixel_level(result, pitch, SURFACE_SIZE / 2, SURFACE_SIZE / 2) >= DARK_LEVEL + LIFTED_BY_AT_LEAST);
+ delete [] result;
}
-
- const unsigned RING_SLOT = 40;
- const float RING_RADIUS = 0.5f;
- const float RING_AGE = 0.3f;
- const float FAR_OFF = 100.0f;
- const unsigned char CLEARED_BY_AT_LEAST = 8;
- float segments[RING_SLOT + 1][8];
- for (unsigned slot = 0; slot < RING_SLOT; ++slot) {
- const float far_segment[8] = { FAR_OFF, FAR_OFF, FAR_OFF + 1.0f, FAR_OFF, 0.0f, 0.2f, 1.0f, 0.01f };
- memcpy(segments[slot], far_segment, sizeof(far_segment));
- }
- const float ring[8] = { 0.0f, 0.0f, 0.0f, 0.0f, RING_RADIUS, -1.0f, 1.0f, RING_AGE };
- memcpy(segments[RING_SLOT], ring, sizeof(ring));
-
- unsigned char calm_middle = 0;
- unsigned char calm_corner = 0;
- unsigned char washed_middle = 0;
- unsigned char washed_corner = 0;
- CHECK(haze_levels(fixture, segments, RING_SLOT, calm_middle, calm_corner));
- CHECK(haze_levels(fixture, segments, RING_SLOT + 1, washed_middle, washed_corner));
- printf("middle %u calm, %u washed; corner %u calm, %u washed\n", calm_middle, washed_middle,
- calm_corner, washed_corner);
- CHECK(calm_middle >= washed_middle + CLEARED_BY_AT_LEAST);
- CHECK_EQ(calm_corner, washed_corner);
}
diff --git a/README.md b/README.md
index 86f6a2659..c273a2f07 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ yet. [CHANGELOG.md](CHANGELOG.md) has the measurements behind every line.
| Modern water, under Options > Water Style: waves that catch the sun, foam at the shore and off boat hulls; Classic stays the default | `main` |
| Volumetric hazard clouds, under Options > Cloud Style: toxin, anthrax and nuclear fields as moving smoke at their real size and length; Classic stays the default | `main` |
| Fire burns: 182 kinds of flame start white-hot and cool through yellow, orange and red to soot | `main` |
-| Warm Light and Haze, Team Color Glow and Water Foam, three Direct3D 11 looks, off until ticked; the haze costs 0.4 ms a frame | `main` |
+| Warm Light and Haze, Team Color Glow and Water Foam, three Direct3D 11 looks, off until ticked | `main` |
| Explosion, lit smoke and cloud shaders ship with the game, and one nobody recorded is built beside the game instead of stopping the picture | `main` |
![A night fight in a river valley under blue moonlight: an explosion and a burning patch of ground light the trees around them while an A-10 and Comanches cross overhead](.github/media/night-fire.jpg)