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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(w3ddevice): reforged lighting style for map lights and picture
Olcay Seyganac4d32302f00
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d84072214..982ce4bc2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -453,6 +453,7 @@ found and fixed — EA's own, not port damage.**- The fake relief is gone, and the sharp textures stay. Every model and the ground used to be lit through bumps guessed from the colours of the texture itself, so a dark stain read as a dent and a painted stripe as a ridge, and soot on a damaged wall turned into black and white marble. Units, buildings and the ground are lit the way EA lit them in 2003 again, on top of the textures at twice their size. The update is 333 MB smaller, and a game folder that has the old surface detail file loses it on the next update.- 625 sharpened textures no longer turn black from the normal camera height. Their far-off copies were made by a tool that dimmed each one by how see-through it was, and some of these pictures are almost entirely see-through in a layer the game never shows, so the tech reinforcement pad in the middle of Twilight Flame drew pitch black unless you zoomed right in. Its far copy measured 1.5 out of 255 where the close one measured 118. They are made again the way EA made theirs, and the pad keeps its colour at every zoom.- Headlights light the road. On a night map a Humvee, an Avenger or a truck used to drive behind two glowing cones that lit nothing, and the ground in front of it stayed as dark as the rest of the map. Now the lamps throw a warm pool of light ahead of the vehicle that moves with it, across the ground, the buildings and the other units standing in it. Most of a map's trees and its water are not lit by it yet. The sixteen lit vehicles nearest the camera shine; an enemy's lamps show only where you can see the enemy. Twenty lit vehicles on Dark Night at 1920x1080 ran at 2.63ms a frame against 2.67ms without, which is inside the noise. It is part of the new picture: on the old renderer or the Classic graphics setting the lamps are the glowing cones they always were.+- The light has weight. Every map shipped with about half its light coming from nowhere in particular, plus two fill lights from the other sides, so the dark side of a tank was two thirds as bright as its sunny side and the whole battlefield looked washed out. Each map now takes its own lights and moves that share to the sun: the shade side of a building or a tank goes properly dark, the sun turns a little warmer and the shade a little cooler, shadows on the ground are deeper, and the picture gets a gentle film curve with the candy colour taken down a notch. A dusk map stays a dusk map and a night map keeps its moonlight. Over seven maps from noon desert to snow and night the contrast rose by up to 19% while bright desert, dusk and snow kept their brightness within 3%; the darker scenes, a night village, a forest and an alpine town in shade, come out about a tenth darker, which is the point. It cost nothing we could measure, 2.63ms a frame either way over 1800 frames of two Hard computers. Lighting on the launcher's options page sets it, Reforged by default, and Classic puts 2003's flat light back from the next map. The old renderer gets the deeper light without the film curve, and Classic Graphics always means Classic light.- A long thin texture loads at the size it was drawn at. Anything wider than eight to one used to be stretched onto a bigger, blurrier one, because that was the limit of a 2002 graphics card; the card is asked now, and modern ones have no such limit.- Anything standing still keeps its shadow in the fog. A town you have already walked through usedto sit on flat ground the moment you looked away, buildings and derricks and walls with nothingdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 84e1b5eb3..66b0cc4fa 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -110,6 +110,18 @@ enum TextLanguageTypeTEXT_LANGUAGE_COUNT = 3,};+/** The LightingStyle option. Classic draws a map's lights as the map gives them; Reforged takes+ * the same lights and moves weight from the flat ambient and the fill lights to the sun, warms the+ * sun and cools the ambient (reforgeLighting), deepens the sun's shadow to match, and grades the+ * Direct3D 11 picture. Client only: nothing in GameLogic reads a light. */+enum LightingStyleType+{+ LIGHTING_STYLE_CLASSIC = 0,+ LIGHTING_STYLE_REFORGED = 1,++ LIGHTING_STYLE_COUNT = 2,+};+/** The AI profile knobs -aiknobsoff can switch off for a measurement. */enum{@@ -214,6 +226,7 @@ public:Bool m_volumetricSmokeShadows; // "VolumetricSmokeShadows": smoke and dust shade the world and themselves through the sun's map (Direct3D 11)Bool m_smokeFireLighting; // "SmokeFireLighting": smoke takes light from the fire beside itBool m_classicGraphics; // "ClassicGraphics": the game's own art, tile, shadows and picture; read at startup+ Int m_lightingStyle; // "LightingStyle": LightingStyleType; the map's lights are rebalanced as each map loadsBool m_shadowMap; // "-shadowmap": draw the casters into the sun's depth buffer as wellBool m_shadowMapReport; // "-shadowmapreport": log what ended up in that buffer, once a secondBool m_shadowMapOnly; // "-shadowmaponly": the map's shadows with the stencil volumes' own darkening off@@ -766,4 +779,10 @@ extern GlobalData* TheWritableGlobalData;* a borderless Options.ini from disagreeing about what borderless entails. */extern void applyWindowMode( void );+/** The Reforged lighting style applied to one time of day's lights, in place: the first light is+ * the sun, the other two the map's fills. Derived from the values the map gave, so a dusk map+ * stays a dusk map; WorldHeightMap calls it on the tables it has just read, which is why it can+ * never be applied twice to the same numbers. */+extern void reforgeLighting( GlobalData::TerrainLighting lights[MAX_GLOBAL_LIGHTS] );+#endifdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex 854dff85a..4568fdeb2 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -1010,6 +1010,23 @@ Int parseNoSmokeFireLight(char *args[], int)return 1;}+/* -lighting <classic|reforged>: the LightingStyle option for one run, the before and after of any+ picture of it. */+Int parseLightingStyle(char *args[], int num)+{+ if (TheWritableGlobalData && num > 1)+ {+ if (strcasecmp(args[1], "classic") == 0)+ TheWritableGlobalData->m_lightingStyle = LIGHTING_STYLE_CLASSIC;+ else if (strcasecmp(args[1], "reforged") == 0)+ TheWritableGlobalData->m_lightingStyle = LIGHTING_STYLE_REFORGED;+ else+ DEBUG_LOG(("-lighting: '%s' is neither classic nor reforged, keeping the saved style\n", args[1]));+ return 2;+ }+ return 1;+}+Int parseNoShaders(char *args[], int){if (TheWritableGlobalData)@@ -2596,6 +2613,7 @@ static CommandLineParam params[] ={ "-noparticleshadows", parseNoParticleShadows },{ "-novolumetricsmoke", parseNoVolumetricSmoke },{ "-nosmokefirelight", parseNoSmokeFireLight },+ { "-lighting", parseLightingStyle },{ "-quickstart", parseQuickStart },/* In every build: EA kept them to Debug and Internal, so a Release run could not skip the logo or themovies. */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 6d4fbbe74..f1e32d09d 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -695,6 +695,7 @@ GlobalData::GlobalData()m_volumetricSmokeShadows = TRUE;m_smokeFireLighting = TRUE;m_classicGraphics = FALSE;+ m_lightingStyle = LIGHTING_STYLE_REFORGED;m_shadowMap = TRUE; //the sun's own shadows are what the game draws with nowm_shadowMapOnly = TRUE; //and they replace the stencil volumes rather than joining themm_shadowMapReport = FALSE;@@ -1348,6 +1349,89 @@ Bool GlobalData::setTimeOfDay( TimeOfDay tod )}+//-------------------------------------------------------------------------------------------------+static Real lightLuminance( const RGBColor &c )+{+ return 0.299f * c.red + 0.587f * c.green + 0.114f * c.blue;+}++/** Multiply a colour by a tint and bring it back to the luminance it had, so the tint moves the hue+ * and never the brightness. */+static void tintLight( RGBColor &c, Real r, Real g, Real b )+{+ const Real before = lightLuminance( c );+ c.red *= r;+ c.green *= g;+ c.blue *= b;+ const Real after = lightLuminance( c );+ if( after > 0.0001f )+ {+ const Real keep = before / after;+ c.red *= keep;+ c.green *= keep;+ c.blue *= keep;+ }+}++static void scaleLight( RGBColor &c, Real s )+{+ c.red *= s;+ c.green *= s;+ c.blue *= s;+}++/* What makes the shipped maps read washed out is the share of their light that has no direction.+ A typical afternoon gives the ground an ambient of about half the sun and two fill lights from the+ other sides, so the shadow side of a tank is two thirds as bright as its lit side and nothing has+ a form. The style moves weight from the ambient and the fills to the sun and leaves the sum a+ sunlit surface receives where it was, so the picture keeps its exposure and gains its contrast.+ The ambient goes a little toward the sky's blue and the sun a little toward late light's yellow,+ by how much of a sun there is: a moonlit night keeps its own cast. */+static const Real REFORGED_AMBIENT_SHARE = 0.72f; // what is left of the flat ambient under a full sun+static const Real REFORGED_NIGHT_AMBIENT_KEPT = 0.16f; // how much more of it a sunless map keeps+static const Real REFORGED_FILL_SHARE = 0.6f; // what is left of the two fill lights+static const Real REFORGED_SUN_PUNCH = 1.04f; // the lit side ends a touch brighter than it was+static const Real REFORGED_SUN_MOST = 1.35f; // never more than this much more sun++void reforgeLighting( GlobalData::TerrainLighting lights[MAX_GLOBAL_LIGHTS] )+{+ GlobalData::TerrainLighting &sun = lights[0];+ const Real ambient = lightLuminance( sun.ambient );+ const Real diffuse = lightLuminance( sun.diffuse );++ // How square the sun stands to flat ground; a map whose sun skims the horizon keeps a floor.+ const Real length = (Real)sqrt( sun.lightPos.x * sun.lightPos.x + sun.lightPos.y * sun.lightPos.y+ + sun.lightPos.z * sun.lightPos.z );+ Real incidence = (length > 0.0001f) ? -sun.lightPos.z / length : 1.0f;+ if( incidence < 0.3f )+ incidence = 0.3f;++ const Real daylight = (diffuse - 0.25f) / 0.5f;+ const Real warmth = (daylight < 0.0f) ? 0.0f : (daylight > 1.0f) ? 1.0f : daylight;++ // A night map's light is mostly ambient already and its moon cannot make up a cut, so the less+ // sun there is the less of the ambient goes.+ const Real ambientShare = REFORGED_AMBIENT_SHARE + (1.0f - warmth) * REFORGED_NIGHT_AMBIENT_KEPT;+ scaleLight( sun.ambient, ambientShare );+ tintLight( sun.ambient, 1.0f - 0.06f * warmth, 1.0f, 1.0f + 0.10f * warmth );++ const Real sunlit = diffuse * incidence;+ if( sunlit > 0.001f )+ {+ Real gain = (sunlit + ambient * (1.0f - ambientShare)) / sunlit * REFORGED_SUN_PUNCH;+ if( gain > REFORGED_SUN_MOST )+ gain = REFORGED_SUN_MOST;+ scaleLight( sun.diffuse, gain );+ }+ tintLight( sun.diffuse, 1.0f + 0.06f * warmth, 1.0f, 1.0f - 0.10f * warmth );++ for( Int i = 1; i < MAX_GLOBAL_LIGHTS; ++i )+ {+ scaleLight( lights[i].ambient, REFORGED_AMBIENT_SHARE );+ scaleLight( lights[i].diffuse, REFORGED_FILL_SHARE );+ }+}+//-------------------------------------------------------------------------------------------------/** Create a new global data instance to override the existing data set. The* initial values of the newly created instance will be a copy of the current@@ -1524,6 +1608,7 @@ void GlobalData::parseGameDataDefinition( INI* ini ){TheWritableGlobalData->m_shadowMap = FALSE;TheWritableGlobalData->m_volumetricSmokeShadows = FALSE;+ TheWritableGlobalData->m_lightingStyle = LIGHTING_STYLE_CLASSIC;TheWritableGlobalData->m_direct3D11PostChain = "off";}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex 883df15d1..411436498 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -100,6 +100,7 @@ OPTION_INT_ACCESSORS( m_fullscreenScaling )OPTION_INT_ACCESSORS( m_msaaLevel )OPTION_BOOL_ACCESSORS( m_vsync )OPTION_BOOL_ACCESSORS( m_classicGraphics )+OPTION_INT_ACCESSORS( m_lightingStyle )OPTION_INT_ACCESSORS( m_healthBarMode )OPTION_INT_ACCESSORS( m_hudScale )OPTION_INT_ACCESSORS( m_playerColorScheme )@@ -499,6 +500,14 @@ const OptionDef TheOptionCatalog[] =OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_volumetricSmokeShadows, set_m_volumetricSmokeShadows },+ // Classic or Reforged light. Reforged rebalances each map's lights as the map loads (so a change+ // shows on the next map), deepens the sun's shadow to match and grades the Direct3D 11 picture,+ // which follows the setting every frame. ClassicGraphics forces Classic. No control in the+ // game's menu; the launcher writes it and -lighting picks it for one run.+ { "LightingStyle", "", "",+ OPTION_ENUM, APPLY_NEXT_MAP, 0, LIGHTING_STYLE_COUNT - 1,+ get_m_lightingStyle, set_m_lightingStyle },+// Smoke lit by the fire beside it. No control yet; -nosmokefirelight turns it off for a run.{ "SmokeFireLighting", "", "",OPTION_BOOL, APPLY_LIVE, 0, 1,diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cppindex 6a98e94ee..d51bedaf3 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp@@ -142,6 +142,10 @@ const Real cosAngleToCare = cos ((0.2 * PI) / 180.0); //1.5 degree difference// ground read at a quarter of the sunlit sand, black in front of every wall, and the owner took// 0.45 from three panels of the same base on 2026-09-21.#define SHADOW_MAP_STRENGTH 0.45f+// The Reforged lighting style moves light from the ambient to the sun, and a shadow is the share+// the sun brought: on the rebalanced maps sun over sun plus ambient comes out 0.6 to 0.7 by day+// and by night alike. Held short of that and of the 0.55 found black in front of every wall.+#define SHADOW_MAP_REFORGED_STRENGTH 0.52f// How wide the filter may open and how narrow it stays on the ground, in texels of the map, and how// much penumbra a unit of gap between a caster and what its shadow falls on is worth. The last is// the number the whole picture turns on: a tank's tracks are on the ground and keep a hard edge, a@@ -4443,8 +4447,10 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )? TheGlobalData->m_shadowMapPenumbra : SHADOW_MAP_PENUMBRA_PER_UNIT;const Real skyFill = (TheGlobalData->m_shadowMapSkyFill > 0.0f)? TheGlobalData->m_shadowMapSkyFill : SHADOW_MAP_SKY_FILL;- const Real strength = (TheGlobalData->m_shadowMapStrength > 0.0f)+ Real strength = (TheGlobalData->m_shadowMapStrength > 0.0f)? TheGlobalData->m_shadowMapStrength : SHADOW_MAP_STRENGTH;+ if (TheGlobalData->m_lightingStyle == LIGHTING_STYLE_REFORGED && TheGlobalData->m_shadowMapStrength <= 0.0f)+ strength = SHADOW_MAP_REFORGED_STRENGTH;Direct3D11_Set_Shadow_Parameters( depthBias, strength, widest,narrowest, penumbra / worldPerTexel, unitsPerUnitOfDepth, skyFill );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cppindex 3d88ca291..62fce030c 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp@@ -271,6 +271,7 @@ static Int fixedFunctionBloomIntensity(void)//Pushed every frame, so a change on the options screen shows at once.const GlowTuning tuning = glowTuning();DX11Post_Set_Bloom(tuning.threshold, tuning.intensity, tuning.additiveGain, tuning.blurPasses);+ DX11Post_Set_Grade(TheGlobalData->m_lightingStyle == LIGHTING_STYLE_REFORGED ? 1.0f : 0.0f);#endifreturn 0;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cppindex 31045f803..6b48e7a64 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp@@ -440,6 +440,23 @@ Bool WorldHeightMap::ParseLightingDataChunk(DataChunkInput &file, DataChunkInfoTheW3DShadowManager->setShadowColor(shadowColor);}}++ // The tables were filled from the file just now, so this is always the map's own numbers it+ // rebalances, however many maps came before.+ if (TheGlobalData->m_lightingStyle == LIGHTING_STYLE_REFORGED) {+ const Int tod = TheGlobalData->m_timeOfDay;+ const GlobalData::TerrainLighting before = TheGlobalData->m_terrainObjectsLighting[tod][0];+ for (i=TIME_OF_DAY_FIRST; i<TIME_OF_DAY_COUNT; i++) {+ reforgeLighting(TheWritableGlobalData->m_terrainLighting[i]);+ reforgeLighting(TheWritableGlobalData->m_terrainObjectsLighting[i]);+ }+ const GlobalData::TerrainLighting &after = TheGlobalData->m_terrainObjectsLighting[tod][0];+ DEBUG_LOG(("LIGHTING reforged, time of day %d: object ambient %.2f %.2f %.2f -> %.2f %.2f %.2f, sun %.2f %.2f %.2f -> %.2f %.2f %.2f\n",+ tod, before.ambient.red, before.ambient.green, before.ambient.blue,+ after.ambient.red, after.ambient.green, after.ambient.blue,+ before.diffuse.red, before.diffuse.green, before.diffuse.blue,+ after.diffuse.red, after.diffuse.green, after.diffuse.blue));+ }DEBUG_ASSERTCRASH(file.atEndOfChunk(), ("Unexpected data left over."));return true;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cppindex 405ae6113..fbe11b0bf 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.cpp@@ -106,6 +106,20 @@ float DX11Post_Additive_Gain()return (BloomIntensity > 0.0f) ? BloomAdditiveGain : 1.0f;}+// How far the grade bends the picture at full strength: the power the S raises each side of its+// pivot to, less one, what is left of the colour around its grey, and how far a channel moves warm+// or cool for each step away from the pivot.+static const float GRADE_CONTRAST = 0.18f;+static const float GRADE_SATURATION = 0.86f;+static const float GRADE_SPLIT = 0.05f;++static float GradeAmount = 0.0f;++void DX11Post_Set_Grade(float amount)+{+ GradeAmount = (amount < 0.0f) ? 0.0f : (amount > 1.0f) ? 1.0f : amount;+}+static DX11PostWarp Warps[DX11_POST_WARP_LIMIT];static unsigned WarpCount = 0;@@ -141,6 +155,9 @@ struct PostConstantBlockfloat WarpInfo[4];float WarpCentre[DX11_POST_WARP_LIMIT][4];float WarpRing[DX11_POST_WARP_LIMIT][4];++ // The grade's amount, contrast, saturation and warm/cool split.+ float Grade[4];};// A triangle big enough to cover the screen, made out of nothing. No vertex buffer and no input@@ -181,6 +198,7 @@ static const char * const PIXEL_SHADER_PROLOGUE =" float4 WarpInfo;\n"" float4 WarpCentre[4];\n"" float4 WarpRing[4];\n"+ " float4 Grade;\n""};\n""\n"// Below the knee nothing moves, so a frame with nothing overbright in it comes back out as the@@ -194,6 +212,28 @@ static const char * const PIXEL_SHADER_PROLOGUE =" float3 excess = max(colour - knee, 0.0);\n"" return min(colour, knee) + headroom * (1.0 - exp(-excess / headroom));\n""}\n"+ "\n"+ // The lighting style's grade, on the curve's output, so everything it sees is already between+ // nought and one. The S turns about the grey a battlefield frame averages (under a third of+ // white, not a half, or the whole picture goes darker; at a third a forest and a snowed-in town+ // still lost an eighth of their brightness): black, white and that grey stay where they+ // are, what is below it sinks and what is above it rises. Then the colour goes toward its own+ // grey, and a pixel brighter than the pivot leans to red, a darker one to blue, by how far it is+ // from it.+ "static const float GRADE_PIVOT = 0.28;\n"+ "float3 grade(float3 colour)\n"+ "{\n"+ " if (Grade.x <= 0.0) return colour;\n"+ " float3 c = saturate(colour);\n"+ " float k = 1.0 + Grade.y;\n"+ " float3 low = GRADE_PIVOT * pow(max(c, 0.00001) / GRADE_PIVOT, k);\n"+ " float3 high = 1.0 - (1.0 - GRADE_PIVOT) * pow(max(1.0 - c, 0.00001) / (1.0 - GRADE_PIVOT), k);\n"+ " float3 graded = (c < GRADE_PIVOT) ? low : high;\n"+ " float grey = dot(graded, float3(0.299, 0.587, 0.114));\n"+ " graded = lerp(grey.xxx, graded, Grade.z);\n"+ " graded += float3(1.0, 0.25, -1.0) * (grey - GRADE_PIVOT) * Grade.w;\n"+ " return lerp(c, saturate(graded), Grade.x);\n"+ "}\n""\n";static const char * const COPY_SHADER_BODY =@@ -205,7 +245,7 @@ static const char * const COPY_SHADER_BODY =static const char * const TONE_MAP_SHADER_BODY ="float4 main(VertexOutput input) : SV_TARGET\n""{\n"- " return float4(tone_curve(Source.Sample(Sampler, input.Texture).rgb), 1.0);\n"+ " return float4(grade(tone_curve(Source.Sample(Sampler, input.Texture).rgb)), 1.0);\n""}\n";// FXAA, the 2009 shape of it: read the luminance of the four diagonal neighbours and the centre,@@ -398,7 +438,7 @@ static const char * const BLOOM_COMPOSITE_SHADER_BODY ="{\n"" float3 scene = Source.Sample(Sampler, input.Texture).rgb;\n"" float3 glow = Extra.Sample(Sampler, input.Texture).rgb;\n"- " return float4(tone_curve(scene + glow * Tuning.y), 1.0);\n"+ " return float4(grade(tone_curve(scene + glow * Tuning.y)), 1.0);\n""}\n";// A blast bending the picture, one read per pixel whatever the number of warps: every warp adds@@ -931,6 +971,10 @@ void DX11PostProcessClass::Draw_Pass(const PassSetup & pass)block.WarpRing[index][2] = warp.RingStrength;block.WarpRing[index][3] = warp.RingSquash;}+ block.Grade[0] = pass.Ungraded ? 0.0f : GradeAmount;+ block.Grade[1] = GRADE_CONTRAST;+ block.Grade[2] = GRADE_SATURATION;+ block.Grade[3] = GRADE_SPLIT;memcpy(mapped.pData, &block, sizeof(block));context->Unmap(ConstantBuffer, 0);@@ -1129,6 +1173,7 @@ bool DX11PostProcessClass::Copy_Through()PassSetup pass;memset(&pass, 0, sizeof(pass));pass.Shader = TargetsAreFloat ? ToneMapShader : PixelShaders[DX11_POST_COPY];+ pass.Ungraded = true;pass.Source = SceneTarget.Resource;pass.Destination = back_buffer;pass.DestinationWidth = Width;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.hindex f30686e7d..19899abf7 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11post.h@@ -114,6 +114,14 @@ void DX11Post_Set_Bloom(float threshold, float intensity, float additive_gain, u// The gain the scene's additive draws take this frame: one whenever the glow is off.float DX11Post_Additive_Gain();+// The Reforged lighting style's grade, laid on wherever the half float scene comes down to eight+// bits (after the tone curve, in the bloom composite and the plain tone pass): a gentle S that+// sinks the darks and lifts the lights, a little colour taken out, and the lights pushed warm and+// the shade cool around mid grey. Zero, the default and what the tests measure, is no grade; one+// is the whole of it. The game sets it every frame from the LightingStyle option. A chain that+// does not start with bloom keeps its scene in eight bits and is never graded.+void DX11Post_Set_Grade(float amount);+// 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@@ -215,6 +223,9 @@ private:float BlurY;// This pass reads the frame's depth rather than the frame, and wants the clip planes with it.bool Occlusion;+ // The scene came down without a match finishing it (the loading screen, interface and all+ // drawn into the scene target): the tone curve, but never the lighting style's grade.+ bool Ungraded;};bool Create_Shaders();diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 47e267599..b1110b0fc 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -17086,6 +17086,41 @@ TEST(particle_cap_in_force_is_the_switch_else_the_slider)TheWritableGlobalData = saved;}+/** The Reforged lighting style keeps what a sunlit surface receives and takes it out of the shade:+ on an ordinary afternoon (ambient half the sun, a fill on each side) the lit side of flat ground+ lands within a few percent of where it was, the shadow side loses a quarter, the sun turns warmer+ than the ambient, and a dim moon keeps its blue. */+TEST(reforged_lighting_keeps_the_lit_side_and_darkens_the_shade)+{+ GlobalData::TerrainLighting lights[MAX_GLOBAL_LIGHTS];+ memset( lights, 0, sizeof(lights) );+ lights[0].ambient.red = lights[0].ambient.green = lights[0].ambient.blue = 0.4f;+ lights[0].diffuse.red = lights[0].diffuse.green = lights[0].diffuse.blue = 0.8f;+ lights[0].lightPos.x = -0.5f; lights[0].lightPos.y = 0.0f; lights[0].lightPos.z = -0.866f;+ lights[1].diffuse.red = lights[1].diffuse.green = lights[1].diffuse.blue = 0.3f;+ const Real incidence = 0.866f;+ const Real litBefore = 0.4f + 0.8f * incidence;++ reforgeLighting( lights );++ const Real ambient = 0.299f * lights[0].ambient.red + 0.587f * lights[0].ambient.green + 0.114f * lights[0].ambient.blue;+ const Real sun = 0.299f * lights[0].diffuse.red + 0.587f * lights[0].diffuse.green + 0.114f * lights[0].diffuse.blue;+ CHECK_NEAR( ambient, 0.4f * 0.72f, 0.01f );+ CHECK( ambient + sun * incidence >= litBefore );+ CHECK( ambient + sun * incidence <= litBefore * 1.06f );+ CHECK( lights[0].diffuse.red > lights[0].diffuse.blue );+ CHECK( lights[0].ambient.blue > lights[0].ambient.red );+ CHECK_NEAR( lights[1].diffuse.green, 0.3f * 0.6f, 0.0001f );++ GlobalData::TerrainLighting moon[MAX_GLOBAL_LIGHTS];+ memset( moon, 0, sizeof(moon) );+ moon[0].ambient.blue = 0.2f; moon[0].ambient.red = moon[0].ambient.green = 0.1f;+ moon[0].diffuse.blue = 0.3f; moon[0].diffuse.red = moon[0].diffuse.green = 0.15f;+ moon[0].lightPos.z = -1.0f;+ reforgeLighting( moon );+ CHECK( moon[0].diffuse.blue > 1.8f * moon[0].diffuse.red );+}+// A veterancy level's or death type's flag bit is bit (value - 1) with the count taken modulo 32, which is// what EA's `1UL << (dt - 1)` gave on Windows, where unsigned long is 32 bits and shl reads five bits of the// count. REGULAR and NORMAL are 0: bit 31, inside ALL. With a 64-bit unsigned long it was bit 63, outside