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): models take the ambient from the sky and the ground

Olcay Seygancf4ab7679262
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03891765d..17aae2cc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## Sky above, ground below
+
+- Sky And Ground Light, under Options, Effects, is a new setting, off by default until it has been looked at on more maps. EA gave every model one flat ambient colour, so the shaded side of a tank was the same dull tone from deck to belly. Now a face looking up takes the map's ambient lifted and a little bluer, up to 40% in blue, and a face looking down takes it lowered and warmer, while a wall stays exactly as it was. The numbers come from the map's own light, so a night map stays a night map. In a battle of three armies and three superweapons the graphics card's frame reads 8.0 ms with it off and 8.15 with it on, less than two runs of one setting differ by. The ground and the batched trees keep their light, and so do the Direct3D 9 picture and Classic Graphics.
+
## Fires light what stands around them
- Firelight, under Options, Effects, is a new setting, off by default until it has been played. A burning building, a wreck or a blast throws a flickering orange light on the ground around it, where before only the one-off flash of an explosion lit anything and a town could burn all night over unlit paving. On Dark Night the moonlit ground beside a fire goes from cold blue-grey to warm tan. Twelve fires at most are lit at once, the strongest in view, and with all twelve going in a battle of three armies and three superweapons they add about a millisecond to a frame already at 18. The Direct3D 9 picture and Classic Graphics keep the old light.
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index ea6428028..bddc4754a 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -1516,6 +1516,14 @@ TOOLTIP:Firelight
"Burning buildings, wrecks and explosions throw a flickering orange light on the ground, the walls and the units around them. It shows most on night maps. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
END
+GUI:HemiAmbient
+"Sky And Ground Light"
+END
+
+TOOLTIP:HemiAmbient
+"Models take the map's ambient light from the sky above and the ground below instead of evenly, so a tank's deck is lighter than its belly. Walls keep the light they had and a night map stays dark. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."
+END
+
GUI:FormationDrag
"Drag Out A Formation"
END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index fd3f98e0f..cab6e3116 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15909,6 +15909,14 @@ TOOLTIP:Firelight
"Yanan binalar, enkazlar ve patlamalar çevrelerindeki zemine, duvarlara ve birimlere titreyen turuncu bir ışık vurur. En çok gece haritalarında belli olur. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
END
+GUI:HemiAmbient
+"Gökyüzü ve Zemin Işığı"
+END
+
+TOOLTIP:HemiAmbient
+"Modeller haritanın ortam ışığını eşit almak yerine yukarıdan gökyüzünden, aşağıdan zeminden alır, böylece bir tankın üstü altından açık görünür. Duvarlar aynı ışıkta kalır, gece haritası karanlık kalır. Yalnızca Direct3D 11 ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."
+END
+
GUI: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 d2e08a734..642439ac8 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd
@@ -6907,6 +6907,53 @@ WINDOW
WINDOW
WINDOWTYPE = CHECKBOX;
SCREENRECT = UPPERLEFT: 288 294, BOTTOMRIGHT: 512 318, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckHemiAmbient";
+ 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:HemiAmbient";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:HemiAmbient";
+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,
+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,
+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;
+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,
+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,
+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ END
+ CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 288 322, BOTTOMRIGHT: 512 346, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckExtraAnimations";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
@@ -6953,7 +7000,7 @@ WINDOW
CHILD
WINDOW
WINDOWTYPE = CHECKBOX;
- SCREENRECT = UPPERLEFT: 288 322, BOTTOMRIGHT: 512 346, CREATIONRESOLUTION: 800 600;
+ SCREENRECT = UPPERLEFT: 288 350, BOTTOMRIGHT: 512 374, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckTreeSway";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
@@ -7000,7 +7047,7 @@ WINDOW
CHILD
WINDOW
WINDOWTYPE = CHECKBOX;
- SCREENRECT = UPPERLEFT: 288 350, BOTTOMRIGHT: 512 374, CREATIONRESOLUTION: 800 600;
+ SCREENRECT = UPPERLEFT: 288 378, BOTTOMRIGHT: 512 402, CREATIONRESOLUTION: 800 600;
NAME = "OptionsMenu.wnd:CheckBehindBuilding";
STATUS = ENABLED+IMAGE+BORDER;
STYLE = CHECKBOX+MOUSETRACK;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 421bf5dcf..80e46f0dd 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -708,6 +708,7 @@ public:
Bool m_waterFoam; ///< "WaterFoam": foam, shore band and the sun's shadow on water (Direct3D 11, client only)
Bool m_groundMarks; ///< "GroundMarks": craters, stains and longer treads that fade over minutes (Direct3D 11, client only)
Bool m_firelight; ///< "Firelight": flames light the ground, walls and units around them (Direct3D 11, client only)
+ Bool m_hemiAmbient; ///< "HemiAmbient": models take the ambient from the sky above and the ground below (Direct3D 11, client only)
Int m_maxParticleCount; ///< maximum number of particles that can exist
Int m_maxFieldParticleCount; ///< maximum number of field-type particles that can exist (roughly)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 279970dff..cf5aaf768 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -1137,6 +1137,7 @@ GlobalData::GlobalData()
m_waterFoam = FALSE;
m_groundMarks = FALSE;
m_firelight = FALSE;
+ m_hemiAmbient = 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 8ea4f158e..1ebc57609 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -144,6 +144,7 @@ OPTION_BOOL_ACCESSORS( m_teamGlow )
OPTION_BOOL_ACCESSORS( m_waterFoam )
OPTION_BOOL_ACCESSORS( m_groundMarks )
OPTION_BOOL_ACCESSORS( m_firelight )
+OPTION_BOOL_ACCESSORS( m_hemiAmbient )
OPTION_INT_ACCESSORS( m_shadowQuality )
OPTION_INT_ACCESSORS( m_graphicsQuality )
@@ -627,6 +628,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_BOOL, APPLY_LIVE, 0, 1,
get_m_firelight, set_m_firelight },
+ // Models take the map's ambient from the sky above and the ground below instead of evenly. The
+ // scene hands it to the backend every frame. Off under Classic graphics and -d3d9, and no row in
+ // the quality table: an opt-in until it has been seen. On Options > Effects.
+ { "HemiAmbient", OPT_WND( "CheckHemiAmbient" ), "GUI:HemiAmbient",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_hemiAmbient, set_m_hemiAmbient },
+
// The size of the sun's depth map. The shadow pass asks for it every frame and the backend makes
// the map again when the size changes, so a new level shows on the next frame. On Options >
// Effects. Classic graphics and -d3d9 draw no map at all.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index 59e940b59..38033eeb3 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" };
+ static const char *const direct3D11Only[] = { "MapLight", "TeamGlow", "WaterFoam", "GroundMarks", "Firelight", "HemiAmbient" };
for( Int i = 0; i < (Int)( sizeof( direct3D11Only ) / sizeof( direct3D11Only[ 0 ] ) ); ++i )
findOptionWidget( *findOptionDef( direct3D11Only[ i ] ) )->winEnable( FALSE );
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index 5d8ee327a..b6e7ec301 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -1490,6 +1490,8 @@ void RTS3DScene::Customized_Render( RenderInfoClass &rinfo )
}
}
+ Direct3D11_Set_Hemi_Ambient(TheGlobalData->m_hemiAmbient);
+
// After the lights' fade has stepped and before the terrain and the models are lit.
if (m_customPassMode == SCENE_PASS_DEFAULT && !ShaderClass::Is_Backface_Culling_Inverted())
handBlastLights(m_dynamicLightList, rinfo.Camera.Get_Position());
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
index 03a862d30..8bd047f3a 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
@@ -267,6 +267,7 @@ DX11BackendClass::DX11BackendClass()
, FireLook(false)
, Emissive(false)
, TeamGlow(false)
+ , HemiAmbient(false)
, AdditiveGain(1.0f)
, GlowDraw(false)
, SceneStandIn(NULL)
@@ -1603,6 +1604,15 @@ void DX11BackendClass::Set_Team_Glow(bool glow)
}
}
+void DX11BackendClass::Set_Hemi_Ambient(bool hemi)
+{
+ if (HemiAmbient != hemi) {
+ HemiAmbient = hemi;
+ PipelineChanged = true;
+ VertexConstantsChanged = true;
+ }
+}
+
/** An opaque fixed-function draw into the scene's own target, under no other look: blended, the
stripe would add light behind a fading or cloaked body, and a mirror, a portrait or the sun's
map has no bloom to feed. Like Additive_Glow it wants the half float scene (a gain off one)
@@ -3211,6 +3221,9 @@ bool DX11BackendClass::Build_Vertex_Description(VertexPipelineDescription & desc
description.SmokeGlow = Smoke_Glow();
description.SoftParticle = Soft_Particle() != SOFT_PARTICLE_NONE;
description.FireLook = Fire_Look() != FIRE_LOOK_NONE;
+ // SoftParticlesAllowed carries the Classic setting, and the sun's caster pass writes depth alone.
+ description.HemiAmbient = HemiAmbient && SoftParticlesAllowed && !ShadowMapBound
+ && description.LightingEnabled && (VertexFormat & D3DFVF_XYZRHW) == 0;
return true;
}
@@ -3586,6 +3599,11 @@ void DX11BackendClass::Upload_Vertex_Constants()
memcpy(vertex_block.MaterialSpecular, MaterialSpecular, sizeof(MaterialSpecular));
memcpy(vertex_block.MaterialEmissive, MaterialEmissive, sizeof(MaterialEmissive));
vertex_block.MaterialPower[0] = MaterialPower;
+ if (HemiAmbient) {
+ // The world's up through the view, for the HemiAmbient programs. Without the option these
+ // stay nought, so the block's bytes are what they always were.
+ memcpy(&vertex_block.MaterialPower[1], &View[8], sizeof(float) * 3);
+ }
const DWORD ambient = RenderStates.Get_Render_State(D3DRS_AMBIENT);
vertex_block.GlobalAmbient[0] = static_cast<float>((ambient >> 16) & 0xff) / 255.0f;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
index 0f9a423b9..75aefd4c5 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h
@@ -330,6 +330,10 @@ public:
// around such a mesh's draws. A draw it does not suit takes none (Team_Glow).
void Set_Team_Glow(bool glow);
+ // The Hemispheric Ambient option: lit draws take the scene ambient from the sky above and the ground
+ // below (ffvertex.h, HemiAmbient). Off under Classic, whose picture is -d3d9's.
+ void Set_Hemi_Ambient(bool hemi);
+
// The look the draws that follow are dressed in (a DRAW_EFFECT_* value, ffshader.h) and its
// four numbers: wall clock seconds, strength, a per-object seed and the object's opacity. The
// mesh renderer sets it around one object's draws and puts DRAW_EFFECT_NONE back after them.
@@ -726,6 +730,8 @@ private:
// Set_Team_Glow, and whether the current draw takes it.
bool TeamGlow;
bool Team_Glow() const;
+ // Set_Hemi_Ambient.
+ bool HemiAmbient;
// Set_Draw_Effect's look and numbers, and the look the current draw takes after the checks.
unsigned DrawEffect;
float DrawEffectNumbers[4];
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
index 49d4c2ab2..247006c47 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp
@@ -715,6 +715,13 @@ void Direct3D11_Set_Team_Glow(bool glow)
}
}
+void Direct3D11_Set_Hemi_Ambient(bool hemi)
+{
+ if (Active) {
+ Backend.Set_Hemi_Ambient(hemi);
+ }
+}
+
static bool DrawEffectsAllowed = true;
void Direct3D11_Set_Draw_Effect(unsigned effect, const float parameters[4])
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
index cdb22087d..43ae64b56 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h
@@ -238,6 +238,11 @@ void Direct3D11_Set_Emissive(bool emissive);
// (DX11BackendClass::Set_Team_Glow, the Team Glow option). The mesh renderer sets it around the mesh.
void Direct3D11_Set_Team_Glow(bool glow);
+// The Hemispheric Ambient option (DX11BackendClass::Set_Hemi_Ambient): lit models take the scene
+// ambient from the sky above and the ground below. The scene hands it over every frame. -d3d9,
+// -headless and the SDL3 port keep the flat ambient.
+void Direct3D11_Set_Hemi_Ambient(bool hemi);
+
// The look one object's draws are dressed in (DRAW_EFFECT_* in ffshader.h) and its four numbers
// (DX11BackendClass::Set_Draw_Effect). The mesh renderer sets it around a mesh's draws and puts
// zero back after them. -d3d9, -headless and the SDL3 port draw the object as they always did.
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
index 8efa270bd..c3ce2c8f5 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp
@@ -85,6 +85,7 @@ void Direct3D11_Set_Smoke_Glow(bool) {}
void Direct3D11_Set_Fire_Look(bool) {}
void Direct3D11_Set_Emissive(bool) {}
void Direct3D11_Set_Team_Glow(bool) {}
+void Direct3D11_Set_Hemi_Ambient(bool) {}
void Direct3D11_Set_Draw_Effect(unsigned, const float [4]) {}
bool Direct3D11_Draw_Effects() { return false; }
void Direct3D11_Allow_Draw_Effects(bool) {}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp
index b803515d3..7f70c5c3e 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp
@@ -57,6 +57,12 @@ static const unsigned REGISTER_VIEWPORT = VERTEX_REGISTER_VIEWPORT;
static const unsigned REGISTER_LIGHTS = VERTEX_REGISTER_LIGHTS;
static const unsigned REGISTERS_PER_LIGHT = VERTEX_REGISTERS_PER_LIGHT;
+// How far the scene ambient swings per channel between a face looking straight up (one plus this) and
+// one looking straight down (one minus it). A wall keeps exactly the map's ambient, so a night map
+// stays a night map and the model's overall weight stays where the art had it. Blue swings most: the
+// sky is bluer than the ambient and the ground's bounce warmer.
+static const char * const HEMI_AMBIENT_SPREAD = "float3(0.25, 0.30, 0.40)";
+
static bool has_normal(FixedFunctionValue fvf)
{
return (fvf & FF_FVF_NORMAL) != 0;
@@ -519,6 +525,9 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,
|| description.StageCount > 1)) {
return false;
}
+ if (description.HemiAmbient && (!description.LightingEnabled || is_pretransformed(description.FVF))) {
+ return false;
+ }
// A pre-transformed vertex has been through the transform, the lighting and the coordinate
// generation already: its position is in pixels, its colour is in the vertex, and D3D9 reads
@@ -595,8 +604,15 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,
return false;
}
+ std::string scene_ambient = "GlobalAmbient.rgb";
+ if (description.HemiAmbient) {
+ body += std::string(" float3 hemi_ambient = GlobalAmbient.rgb * (1.0 + ") + HEMI_AMBIENT_SPREAD
+ + " * dot(view_normal, MaterialPower.yzw));\n";
+ scene_ambient = "hemi_ambient";
+ }
+
body += " output.Diffuse.rgb = saturate(" + diffuse + ".rgb * diffuse_light + "
- + ambient + ".rgb * (GlobalAmbient.rgb + ambient_light) + " + emissive + ".rgb);\n";
+ + ambient + ".rgb * (" + scene_ambient + " + ambient_light) + " + emissive + ".rgb);\n";
body += " output.Diffuse.a = " + diffuse + ".a;\n";
if (description.SpecularEnabled) {
@@ -776,5 +792,8 @@ std::string VertexShader_Key(const VertexPipelineDescription & description)
if (description.FireLook) {
key += ":B";
}
+ if (description.HemiAmbient) {
+ key += ":H";
+ }
return key;
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h
index 95e845af8..2f1c30ee1 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h
@@ -149,6 +149,12 @@ struct VertexPipelineDescription
// TexCoord1, which a one-stage draw leaves empty. Refused on a format with one set or none, a
// pretransformed one, or a draw with a second stage, whose coordinates that output is.
bool FireLook = false;
+
+ // A lit draw under the Hemispheric Ambient option: the scene ambient comes down from the sky and
+ // up from the ground instead of evenly. The world's up in camera space rides in MaterialPower.yzw,
+ // which nothing else reads, so every other program keeps its text and the block keeps its layout.
+ // Refused on an unlit or a pretransformed draw.
+ bool HemiAmbient = false;
};
// Which profile the generated text is for. The two differ in the output semantic and in how the
diff --git a/GeneralsMD/Code/Tests/test_dx11backend.cpp b/GeneralsMD/Code/Tests/test_dx11backend.cpp
index 97820a1ee..df417a33f 100644
--- a/GeneralsMD/Code/Tests/test_dx11backend.cpp
+++ b/GeneralsMD/Code/Tests/test_dx11backend.cpp
@@ -328,6 +328,126 @@ TEST(dx11backend_a_light_is_carried_into_camera_space)
backend.Shutdown();
}
+// The Hemispheric Ambient option on a quad lit by the scene ambient alone, whose normal stays (0,0,1)
+// in camera space. A view with no turn has the world's up at (0,0,1), so the quad faces straight up
+// and takes one plus the spread; turned half way round x, up is (0,0,-1) and the same quad faces
+// straight down. If the program read the wrong half of MaterialPower the two pixels would come out
+// the same. Tilted 45 degrees round x with no world, the quad still faces straight up; the view's
+// third column in place of its third row would read it as a wall. Off, the flat ambient comes back.
+TEST(dx11backend_the_hemispheric_ambient_follows_the_view)
+{
+ DX11DeviceClass device;
+ CHECK(device.Create_Offscreen());
+ ID3D11Device * d3d = device.Get_Device();
+
+ DX11BackendClass backend;
+ CHECK(backend.Initialise(&device));
+
+ D3D11_TEXTURE2D_DESC target_description;
+ memset(&target_description, 0, sizeof(target_description));
+ target_description.Width = TARGET_SIZE;
+ target_description.Height = TARGET_SIZE;
+ target_description.MipLevels = 1;
+ target_description.ArraySize = 1;
+ target_description.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
+ target_description.SampleDesc.Count = 1;
+ target_description.Usage = D3D11_USAGE_DEFAULT;
+ target_description.BindFlags = D3D11_BIND_RENDER_TARGET;
+
+ ID3D11Texture2D * target = NULL;
+ CHECK(SUCCEEDED(d3d->CreateTexture2D(&target_description, NULL, &target)));
+
+ D3D11_TEXTURE2D_DESC staging_description = target_description;
+ staging_description.Usage = D3D11_USAGE_STAGING;
+ staging_description.BindFlags = 0;
+ staging_description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
+
+ ID3D11Texture2D * staging = NULL;
+ CHECK(SUCCEEDED(d3d->CreateTexture2D(&staging_description, NULL, &staging)));
+
+ ID3D11RenderTargetView * target_view = NULL;
+ CHECK(SUCCEEDED(d3d->CreateRenderTargetView(target, NULL, &target_view)));
+
+ device.Get_Context()->OMSetRenderTargets(1, &target_view, NULL);
+
+ backend.Set_Viewport(0, 0, TARGET_SIZE, TARGET_SIZE);
+ configure_unlit_pass_through(backend);
+
+ backend.Set_Render_State(D3DRS_LIGHTING, TRUE);
+ backend.Set_Render_State(D3DRS_SPECULARENABLE, FALSE);
+ backend.Set_Render_State(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
+ backend.Set_Render_State(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
+ backend.Set_Render_State(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
+ backend.Set_Render_State(D3DRS_AMBIENT, 0x00808080);
+
+ const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ const float black[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+ backend.Set_Material(white, black, black, black, 1.0f);
+
+ ID3D11Buffer * vertices = NULL;
+ CHECK(DX11Resource_Create_Vertex_Buffer(d3d, sizeof(QUAD_VERTICES), D3DPOOL_MANAGED, 0,
+ QUAD_VERTICES, &vertices));
+
+ ID3D11Buffer * indices = NULL;
+ CHECK(DX11Resource_Create_Index_Buffer(d3d, sizeof(QUAD_INDICES), D3DPOOL_MANAGED, 0,
+ QUAD_INDICES, &indices));
+
+ backend.Set_Stream_Source(vertices, sizeof(BackendVertex), 0);
+ backend.Set_Indices(indices, DXGI_FORMAT_R16_UINT);
+
+ float identity[16];
+ set_identity(identity);
+ float half_turn[16]; // as the view and as the world that undoes it, so the same quad is drawn
+ set_identity(half_turn);
+ half_turn[5] = -1.0f;
+ half_turn[10] = -1.0f;
+
+ float tilt[16];
+ set_identity(tilt);
+ tilt[5] = 0.70710678f; tilt[6] = 0.70710678f;
+ tilt[9] = -0.70710678f; tilt[10] = 0.70710678f;
+
+ struct Shot { bool Hemi; const float * View; const float * World; unsigned char Bgr[3]; };
+ Shot shots[4] = {
+ { false, identity, identity, { 0, 0, 0 } },
+ { true, identity, identity, { 0, 0, 0 } },
+ { true, half_turn, half_turn, { 0, 0, 0 } },
+ { true, tilt, identity, { 0, 0, 0 } }
+ };
+ for (unsigned index = 0; index < 4; ++index) {
+ const float clear_colour[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ device.Get_Context()->ClearRenderTargetView(target_view, clear_colour);
+ backend.Set_Hemi_Ambient(shots[index].Hemi);
+ backend.Set_Transform(D3DTS_VIEW, shots[index].View);
+ backend.Set_Transform(D3DTS_WORLD, shots[index].World);
+ CHECK(backend.Draw_Indexed_Triangles(6, 0, 0));
+ device.Get_Context()->CopyResource(staging, target);
+ D3D11_MAPPED_SUBRESOURCE mapped;
+ CHECK(SUCCEEDED(device.Get_Context()->Map(staging, 0, D3D11_MAP_READ, 0, &mapped)));
+ const unsigned char * centre = static_cast<const unsigned char *>(mapped.pData)
+ + mapped.RowPitch * (TARGET_SIZE / 2) + (TARGET_SIZE / 2) * 4;
+ memcpy(shots[index].Bgr, centre, 3);
+ device.Get_Context()->Unmap(staging, 0);
+ }
+
+ // 0x80 flat; times 1.4, 1.3, 1.25 facing up and 0.6, 0.7, 0.75 facing down (blue, green, red).
+ CHECK(shots[0].Bgr[0] >= 126 && shots[0].Bgr[0] <= 130);
+ CHECK(shots[1].Bgr[0] >= 177 && shots[1].Bgr[0] <= 181);
+ CHECK(shots[1].Bgr[1] >= 164 && shots[1].Bgr[1] <= 168);
+ CHECK(shots[1].Bgr[2] >= 158 && shots[1].Bgr[2] <= 162);
+ CHECK(shots[2].Bgr[0] >= 75 && shots[2].Bgr[0] <= 79);
+ CHECK(shots[2].Bgr[1] >= 88 && shots[2].Bgr[1] <= 92);
+ CHECK(shots[2].Bgr[2] >= 94 && shots[2].Bgr[2] <= 98);
+ CHECK(shots[3].Bgr[0] >= 177 && shots[3].Bgr[0] <= 181);
+
+ indices->Release();
+ vertices->Release();
+ target_view->Release();
+ staging->Release();
+ target->Release();
+ backend.Shutdown();
+}
+
// The same state twice is one pipeline, and a changed stage program is a second. The engine sets
// the same handful of combinations thousands of times a frame, so a cache that missed would compile
// a shader per draw and the frame time would be the symptom rather than the picture.
diff --git a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp b/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp
index 36ac9c5df..7dfa147e3 100644
--- a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp
+++ b/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp
@@ -275,6 +275,41 @@ TEST(ffvertexcompile_a_soft_billboard_hands_its_half_width_on)
CHECK(compiles(compile, hlsl, D3D11_PROFILE));
}
+// The Hemispheric Ambient program is keyed apart and swings the scene ambient on the normal's height
+// through the unused half of MaterialPower. With the option off the text does not move, which is
+// what keeps the shipped shader cache whole. Refused on an unlit draw.
+TEST(ffvertexcompile_a_lit_draw_takes_the_ambient_from_sky_and_ground)
+{
+ VertexPipelineDescription flat = plain_description();
+ flat.LightingEnabled = true;
+ flat.LightCount = 1;
+ flat.Lights[0].Type = FF_LIGHT_DIRECTIONAL;
+ VertexPipelineDescription hemi = flat;
+ hemi.HemiAmbient = true;
+
+ std::string flat_hlsl;
+ std::string hemi_hlsl;
+ CHECK(VertexShader_Generate(flat, VERTEX_SHADER_TARGET_D3D11, flat_hlsl));
+ CHECK(VertexShader_Generate(hemi, VERTEX_SHADER_TARGET_D3D11, hemi_hlsl));
+ CHECK(flat_hlsl.find("MaterialPower.yzw") == std::string::npos);
+ CHECK(flat_hlsl.find("(GlobalAmbient.rgb + ambient_light)") != std::string::npos);
+ CHECK(hemi_hlsl.find("dot(view_normal, MaterialPower.yzw)") != std::string::npos);
+ CHECK(hemi_hlsl.find("(hemi_ambient + ambient_light)") != std::string::npos);
+ CHECK(VertexShader_Key(hemi) == VertexShader_Key(flat) + ":H");
+
+ VertexPipelineDescription unlit = plain_description();
+ unlit.HemiAmbient = true;
+ CHECK(!VertexShader_Generate(unlit, VERTEX_SHADER_TARGET_D3D11, hemi_hlsl));
+
+ D3DCompileFunction compile = load_compiler();
+ if (compile == NULL) {
+ printf(" d3dcompiler_47.dll not present, skipping the compile\n");
+ return;
+ }
+ CHECK(VertexShader_Generate(hemi, VERTEX_SHADER_TARGET_D3D11, hemi_hlsl));
+ CHECK(compiles(compile, hemi_hlsl, D3D11_PROFILE));
+}
+
// A fire billboard's age and seed ride the second coordinate set through to TexCoord1, written after
// the empty stages are zeroed so the zero does not win. Keyed apart; refused with one set or a
// second stage.
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index df2b5550f..b4d939a77 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -240,6 +240,7 @@ NEW_CONTROLS = [
(CHECK, "CheckWaterFoam", "GUI:WaterFoam"),
(CHECK, "CheckGroundMarks", "GUI:GroundMarks"),
(CHECK, "CheckFirelight", "GUI:Firelight"),
+ (CHECK, "CheckHemiAmbient", "GUI:HemiAmbient"),
(LABEL, "LabelGraphicsQuality", "GUI:GraphicsQuality"),
(SLIDER, "SliderGraphicsQuality", None),
]
@@ -380,6 +381,7 @@ GROUP_LAYOUT = [
("check", "CheckSmoothWater"),
("check", "CheckWaterFoam"),
("check", "CheckGroundMarks"),
+ ("check", "CheckHemiAmbient"),
("check", "CheckExtraAnimations"),
("check", "CheckTreeSway"),
("check", "CheckBehindBuilding")]),