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
merge: direct3d 11 modern water, hazard clouds and tree sun shadows
Olcay Seygan00bf39e46a05
diff --cc CHANGELOG.mdindex 0ba212452,4fc264a54..d75a9537d--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -712,7 -727,6 +727,7 @@@ found and fixed — EA's own, nottheirs, which they have to: a shadow crawling across fogged ground is the position of a unit youare 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. Warm Light and Haze, on the Graphics page after Heat Haze, 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 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.## Every replay, not just the last onediff --cc GeneralsMD/Code/Data/Patch.strindex 6b1164a2b,b3895d05c..88de4ebc7--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@@ -1290,30 -1322,6 +1322,30 @@@ TOOLTIP:DebrisTrail"Blasts throw fragments that trail smoke, and wrecks shed burning shrapnel. Off keeps the original explosions. Applies when you press Accept."END+GUI:MapLight+"Warm Light and Haze"+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."+END++GUI:TeamGlow+"Team Color Glow"+END++TOOLTIP:TeamGlow+"The bright patches of each side's color on units and buildings glow in that color. Direct3D 11 only. Applies from the next map."+END++GUI:WaterFoam+"Water Foam"+END++TOOLTIP:WaterFoam- "Rivers and lakes carry flecks of foam and a band of it along the shore, and the sun's shadows fall on the water. The sea's waves are unchanged. Direct3D 11 only, and off under Classic Graphics. Applies when you press Accept."++"Rivers and lakes carry flecks of foam and a band of it along the shore, and the sun's shadows fall on the water. The sea's waves are unchanged. Direct3D 11 and Classic water only, and off under Classic Graphics. Applies when you press Accept."+END+GUI:FormationDrag"Drag Out A Formation"ENDdiff --cc GeneralsMD/Code/Data/Turkish/Generals.strindex 90ad3dea3,ba28b48e8..378f9b57a--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@@ -15705,30 -15737,6 +15737,30 @@@ TOOLTIP:DebrisTrail"Patlamalar arkasında duman bırakan parçalar savurur, enkazdan yanan şarapnel saçılır. Kapalıyken patlamalar orijinal haliyle kalır. Kabul Et'e basınca uygulanır."END+GUI:MapLight+"Sıcak Işık ve Pus"+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."+END++GUI:TeamGlow+"Takım Rengi Parlaması"+END++TOOLTIP:TeamGlow+"Birimlerin ve binaların üstündeki parlak takım rengi bölgeleri kendi renginde parlar. Yalnızca Direct3D 11. Bir sonraki haritada uygulanır."+END++GUI:WaterFoam+"Su Köpüğü"+END++TOOLTIP:WaterFoam- "Nehirlerde ve göllerde köpük benekleri ve kıyı boyunca bir köpük şeridi belirir, güneşin gölgeleri suya düşer. Denizin dalgaları değişmez. Yalnızca Direct3D 11, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."++"Nehirlerde ve göllerde köpük benekleri ve kıyı boyunca bir köpük şeridi belirir, güneşin gölgeleri suya düşer. Denizin dalgaları değişmez. Yalnızca Direct3D 11 ve Klasik su ile, Klasik Grafikler açıkken kapalıdır. Kabul Et'e basınca uygulanır."+END+GUI:FormationDrag"Sürükleyerek Düzen Kur"ENDdiff --cc GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wndindex 68508228d,53e13ea2f..f2aab67b8--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenuClassic.wnd@@@ -4484,6 -4484,6 +4484,100 @@@ WINDOIMAGE: NoImage, COLOR: 255 255 255 255, BORDERCOLOR: 255 255 255 255;ENDCHILD++ WINDOW++ WINDOWTYPE = CHECKBOX;++ SCREENRECT = UPPERLEFT: 288 378, BOTTOMRIGHT: 512 402, CREATIONRESOLUTION: 800 600;++ NAME = "OptionsMenu.wnd:CheckMapLight";++ 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:MapLight";++ TOOLTIPDELAY = -1;++ TEXT = "GUI:MapLight";++ 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 406, BOTTOMRIGHT: 512 430, CREATIONRESOLUTION: 800 600;++ NAME = "OptionsMenu.wnd:CheckTeamGlow";++ 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:TeamGlow";++ TOOLTIPDELAY = -1;++ TEXT = "GUI:TeamGlow";++ 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++ CHILDWINDOWWINDOWTYPE = STATICTEXT;SCREENRECT = UPPERLEFT: 530 150, BOTTOMRIGHT: 754 174, CREATIONRESOLUTION: 800 600;diff --cc GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cppindex 6260de1d3,6ee310d92..bc0e3f19c--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp@@@ -215,37 -232,12 +232,39 @@@ void doSkyBoxSet(Bool startDraw#define AMP_SCALE2 (10.0f/120.0f)#define NOISE_FREQ (2.0f*PI/WAVE_FREQ)-#define NOISE_REPEAT_FACTOR ((float)(1.0f/(16.0f)))+#define NOISE_REPEAT_FACTOR ((float)(1.0f/(16.0f))) //the foam programs undo this (TexCoord2 * 16) to find the world+ static const Real WATER_SCROLL_SPEED = 0.2f;+ static const Real AUTHORED_FPS = 30.0f;-static Bool wireframeForDebug = 0;+//+// The Water Foam option (WaterFoam): whitecap flecks, a foam band and a soft blend where the+// water gets shallow, and the sun's shadow on the surface. It is the D3D11 water program under a+// second name (engineshader.cpp, "water foam"); the D3D9 bytecode is the same, so -d3d9 and the+// Classic setting, which has no sun's map to take the pixel back to the world through, keep the- // plain water and its destination alpha feather.++// plain water and its destination alpha feather. It dresses the Classic water only: the Modern++// style draws the plain names with a text of its own, which the foam program would replace.+//+#define WATER_FOAM_CYCLE 10.0f //swell cycles per unit of m_riverVOrigin: about eight seconds a cycle++static Bool waterFoam(void)+{+ return TheGlobalData->m_waterFoam && !TheGlobalData->m_classicGraphics- && Direct3D11_Present_Is_Enabled();++ && TheGlobalData->m_waterStyle == 0 && Direct3D11_Present_Is_Enabled();+}++// What the foam programs read out of the texture factor: green is the swell's phase, alpha the+// opacity deep water reaches and red the depth that reaches it over 32. Alpha zero keeps the+// water's own alpha, which is every water body that is not feathered.+static UnsignedInt waterFoamFactor(Real riverVOrigin, Real opaqueDepth, Real deepOpacity)+{+ const Real phase = fmodf(riverVOrigin * WATER_FOAM_CYCLE, 1.0f);+ const Int depth = REAL_TO_INT(WWMath::Clamp(opaqueDepth / 32.0f, 0.0f, 1.0f) * 255.0f);+ const Int opacity = REAL_TO_INT(WWMath::Clamp(deepOpacity, 0.0f, 1.0f) * 255.0f);+ return ((UnsignedInt)opacity << 24) | ((UnsignedInt)depth << 16) | ((UnsignedInt)REAL_TO_INT(phase * 255.0f) << 8);+}+//// The river used to get its shroud from a second pass that redrew the whole quad through// ST_SHROUD_TEXTURE. That pass multiplies the frame buffer by the shroud and knows nothing about@@@ -353,13 -343,1016 +370,1020 @@@ void WaterRenderObjClass::setupJbaWaterif (m_riverWaterPixelShader){DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);DX8Wrapper::Set_Pixel_Shader(m_riverWaterPixelShader);+ if (waterFoam()) {+ DX8Wrapper::Set_DX8_Render_State(D3DRS_TEXTUREFACTOR, waterFoamFactor(m_riverVOrigin, 0.0f, 0.0f));+ DX8Wrapper::Set_Pixel_Shader(m_riverWaterFoamPixelShader);+ }+ setupModernWaterShader(TRUE);+ }+ }++ // SDL's map water composites the coloured mirror in its surface shader. Windows retains the+ // original assembly and its separate reflection pass. No texture assets or game data are changed.+ namespace {+ struct WaterHullMesh : WaterHullPoseCache::Mesh {+ MeshModelClass *model;+ };+ static_assert(WaterHullPoseCache::MaxMeshes==WaterHullModel::MaxMeshes,"Hull pose snapshots share the collector bound");+ static Bool CollectWaterHullMeshes(RenderObjClass *object,const Vector3 &origin,float axisX,float axisY,+ float level,float crestRise,std::vector<WaterHullMesh> &meshes,unsigned &visited,unsigned depth=0)+ {+ if (!object || object->Is_Hidden() || object->Is_Animation_Hidden()) return TRUE;+ if (depth>6 || ++visited>WaterHullModel::MaxMeshes) return FALSE;+ if (object->Class_ID()==RenderObjClass::CLASSID_MESH) {+ MeshModelClass *model=static_cast<MeshClass*>(object)->Peek_Model();+ if (!model || model->Get_Flag(MeshGeometryClass::SKIN) || object->Is_Additive()) return TRUE;+ const AABoxClass &bounds=object->Get_Bounding_Box();+ if (level+crestRise<bounds.Center.Z-bounds.Extent.Z-0.01f || level>bounds.Center.Z+bounds.Extent.Z+0.01f) return TRUE;+ if (model->Get_Vertex_Count()<=0 || model->Get_Polygon_Count()<=0) return TRUE;+ const Matrix3D &matrix=object->Get_Transform();+ WaterHullMesh mesh;mesh.model=model;+ mesh.crossesMean=level>=bounds.Center.Z-bounds.Extent.Z-0.01f && level<=bounds.Center.Z+bounds.Extent.Z+0.01f;+ mesh.identity=model;mesh.vertexArray=model->Get_Vertex_Array();mesh.triangleArray=model->Get_Polygon_Array();+ mesh.vertexCount=model->Get_Vertex_Count();mesh.triangleCount=model->Get_Polygon_Count();+ AABoxClass localBounds;model->Get_Bounding_Box(&localBounds);+ const float localCenter[3]={localBounds.Center.X,localBounds.Center.Y,localBounds.Center.Z};+ const float localExtent[3]={localBounds.Extent.X,localBounds.Extent.Y,localBounds.Extent.Z};+ mesh.supportRadius=WaterHullPoseCache::SupportRadius(localCenter,localExtent);+ if(!std::isfinite(mesh.supportRadius)) return FALSE;+ for (unsigned column=0;column<4;++column) {+ const float x=matrix[0][column]-(column==3?origin.X:0.0f);+ const float y=matrix[1][column]-(column==3?origin.Y:0.0f);+ mesh.transform[0][column]=x*axisX+y*axisY;+ mesh.transform[1][column]=-x*axisY+y*axisX;+ mesh.transform[2][column]=matrix[2][column]-(column==3?level:0.0f);+ for (unsigned row=0;row<3;++row) {+ if (!std::isfinite(mesh.transform[row][column]) || std::abs(mesh.transform[row][column])>1.0e6f) return FALSE;+ }+ }+ if(!WaterHullPoseCache::Valid(mesh)) return FALSE;+ meshes.push_back(mesh);+ return TRUE;+ }+ if (object->Class_ID()==RenderObjClass::CLASSID_HLOD) {+ HLodClass *hlod=static_cast<HLodClass*>(object);+ // Retain the most detailed authored contour as visual LODs change. It is independent+ // of deck/superstructure bounds and is never used for collision or pathfinding.+ const int lod=hlod->Get_Lod_Count()-1;+ if (lod>=0) for (int i=0;i<hlod->Get_Lod_Model_Count(lod);++i)+ if (!CollectWaterHullMeshes(hlod->Peek_Lod_Model(lod,i),origin,axisX,axisY,level,crestRise,meshes,visited,depth+1)) return FALSE;+ for (int i=0;i<hlod->Get_Additional_Model_Count();++i)+ if (!CollectWaterHullMeshes(hlod->Peek_Additional_Model(i),origin,axisX,axisY,level,crestRise,meshes,visited,depth+1)) return FALSE;+ return TRUE;+ }+ const int children=object->Get_Num_Sub_Objects();+ if (children>(int)WaterHullModel::MaxMeshes) return FALSE;+ for(int i=0;i<children;++i) {+ RenderObjClass *child=object->Get_Sub_Object(i);+ const Bool ok=CollectWaterHullMeshes(child,origin,axisX,axisY,level,crestRise,meshes,visited,depth+1);+ REF_PTR_RELEASE(child);+ if (!ok) return FALSE;+ }+ return TRUE;+ }+ static Real WaterTerrainDepth(WorldHeightMap *map,Real x,Real y,Real level)+ {+ if(!map || map->getXExtent()<2 || map->getYExtent()<2) return 0.0f;+ const Real mx=clamp(x/MAP_XY_FACTOR+map->getBorderSize(),0.0f,(Real)map->getXExtent()-1.001f);+ const Real my=clamp(y/MAP_XY_FACTOR+map->getBorderSize(),0.0f,(Real)map->getYExtent()-1.001f);+ const Int ix=(Int)mx,iy=(Int)my;const Real fx=mx-ix,fy=my-iy;+ const Real a=map->getHeight(ix,iy)*(1-fx)+map->getHeight(ix+1,iy)*fx;+ const Real b=map->getHeight(ix,iy+1)*(1-fx)+map->getHeight(ix+1,iy+1)*fx;+ return level-(a*(1-fy)+b*fy)*MAP_HEIGHT_SCALE;+ }+ static WaterHullModel::Point3 WaterHullPoint(const WaterHullMesh &mesh,const Vector3 &p)+ {+ WaterHullModel::Point3 out;+ out.x=mesh.transform[0][0]*p.X+mesh.transform[0][1]*p.Y+mesh.transform[0][2]*p.Z+mesh.transform[0][3];+ out.y=mesh.transform[1][0]*p.X+mesh.transform[1][1]*p.Y+mesh.transform[1][2]*p.Z+mesh.transform[1][3];+ out.z=mesh.transform[2][0]*p.X+mesh.transform[2][1]*p.Y+mesh.transform[2][2]*p.Z+mesh.transform[2][3];+ return out;+ }+ }++ void WaterRenderObjClass::clearModernWaterHulls(Bool admissions)+ {+ if (admissions)+ m_modernBowAdmissions.Clear();+ for (ModernHullCache &cache : m_modernHullCache) {+ for (MeshModelClass *mesh : cache.slicedModels)+ REF_PTR_RELEASE(mesh);+ for (MeshModelClass *mesh : cache.visualModels)+ REF_PTR_RELEASE(mesh);+ REF_PTR_RELEASE(cache.model);+ }+ m_modernHullCache.clear();+ m_modernHulls.clear();+ m_modernContactHulls.clear();+ m_modernVisualHulls.clear();+ m_modernHullObjectIDs.clear();+ m_modernHullSerial = 0;+ }++ Bool WaterRenderObjClass::modernHasHull(UnsignedInt objectID) const+ {+ return std::find(m_modernHullObjectIDs.begin(), m_modernHullObjectIDs.end(), objectID)+ != m_modernHullObjectIDs.end();+ }++ Bool WaterRenderObjClass::hasModernVesselFoam(UnsignedInt objectID) const+ {+ #if ZH_MODERN_WATER+ return m_useModernWater && !m_renderingMirror && m_trapezoidWaterPixelShader+ && m_modernFoamDrawFrame == WW3D::Get_Frame_Count()+ && std::find(m_modernFoamDrawObjectIDs.begin(), m_modernFoamDrawObjectIDs.end(), objectID)+ != m_modernFoamDrawObjectIDs.end();+ #else+ return FALSE;+ #endif+ }++ #if ZH_MODERN_WATER+ void WaterRenderObjClass::takeWaterPolygonsForDraw(void)+ {+ LOGIC_WINDOW_READ( WINDOW_TERRAIN );+ m_waterPolygonsForDraw.clear();+ for (PolygonTrigger *trigger=PolygonTrigger::getFirstPolygonTrigger();trigger;trigger=trigger->getNext()) {+ if (!trigger->isWaterArea() || trigger->getNumPoints()<1) continue;+ WaterPolygonForDraw polygon;+ polygon.center.z=0.0f;+ polygon.river=trigger->isRiver();polygon.riverStart=trigger->getRiverStart();+ polygon.owner=reinterpret_cast<uintptr_t>(trigger);+ trigger->getCenterXY(&polygon.center);polygon.radius=trigger->getRadius();+ polygon.points.reserve(trigger->getNumPoints());+ for (Int i=0;i<trigger->getNumPoints();++i) polygon.points.push_back(*trigger->getPoint(i));+ m_waterPolygonsForDraw.push_back(std::move(polygon));+ }+ }++ void WaterRenderObjClass::takeMotionReadsForRender(void)+ {+ m_modernMotionFrame=TheGameLogic ? TheGameLogic->getFrame() : 0;+ m_modernMotionFrozen=(TheGameLogic && TheGameLogic->isGamePaused()) || (TheScriptEngine &&+ (TheScriptEngine->isTimeFrozenScript() || TheScriptEngine->isTimeFrozenDebug()));+ }++ void WaterRenderObjClass::takeReadsForRender(void)+ {+ // Logic owns the water tables and object values; model transforms stay on the render side+ // so the hull slice follows the same interpolated pose as the displayed vessel.+ synchronizeWaterStyle();+ takeWaterPolygonsForDraw();+ takeMotionReadsForRender();+ m_modernObjectsForDraw.clear();m_modernObstacles.clear();m_modernObstacleObjectIDs.clear();+ m_modernReadsReady=m_useModernWater && TheGameLogic && TheTerrainLogic &&+ TheTerrainRenderObject && TheTerrainRenderObject->getMap();+ #if defined(__linux__)+ // Windows' wave tracks still update in their own flush, as they always have.+ if (m_waterTrackSystem) m_waterTrackSystem->takeReadsForRender();+ #endif+ if (!m_modernReadsReady) return;++ for (const Object *object=TheGameLogic->getFirstObject();object;object=object->getNextObject()) {+ if (object->isDestroyed()) continue;+ const Coord3D &position=*object->getPosition();+ if (object->isKindOf(KINDOF_STRUCTURE) || object->isKindOf(KINDOF_BRIDGE) || object->isKindOf(KINDOF_IMMOBILE)) {+ const GeometryInfo &geometry=object->getGeometryInfo();+ ModernWaterObstacle obstacle;+ obstacle.position.Set(position.x,position.y,position.z);+ obstacle.radius=geometry.getBoundingCircleRadius();+ obstacle.height=geometry.getMaxHeightAbovePosition();+ obstacle.box=geometry.getGeomType()==GEOMETRY_BOX;+ obstacle.major=geometry.getMajorRadius();obstacle.minor=geometry.getMinorRadius();+ obstacle.cosine=cosf(object->getOrientation());obstacle.sine=sinf(object->getOrientation());+ if (obstacle.radius>1.0f) {+ m_modernObstacles.push_back(obstacle);+ m_modernObstacleObjectIDs.push_back((UnsignedInt)object->getID());+ }+ }+ Drawable *drawable=object->getDrawable();+ if (!drawable || drawable->isDrawableEffectivelyHidden() || drawable->getFullyObscuredByShroud()) continue;+ Real level=0.0f;+ if (!TheTerrainLogic->isUnderwater(position.x,position.y,&level)) continue;+ ModernWaterObject read={drawable,Vector3(position.x,position.y,position.z),level,{},FALSE};+ read.vessel=!object->isKindOf(KINDOF_AIRCRAFT) && (object->isKindOf(KINDOF_AIRCRAFT_CARRIER) ||+ object->isKindOf(KINDOF_BOAT) || object->isKindOf(KINDOF_VEHICLE));+ const PhysicsBehavior *physics=read.vessel?object->getPhysics():NULL;+ if (physics) {+ const Coord3D &velocity=*physics->getVelocity();+ read.initialVelocity={velocity.x*LOGICFRAMES_PER_SECOND,velocity.y*LOGICFRAMES_PER_SECOND};+ }+ m_modernObjectsForDraw.emplace((UnsignedInt)object->getID(),read);+ }+ }+ #endif++ Bool WaterRenderObjClass::isModernWaterMirrorForOwner(UnsignedInt objectID) const+ {+ #if ZH_MODERN_WATER+ if(!m_useModernWater || !m_renderingMirror || m_waterType!=WATER_TYPE_0_TRANSLUCENT || !m_trapezoidWaterPixelShader ||+ !m_pReflectionTexture || !m_modernReadsReady) return FALSE;+ const auto found=m_modernObjectsForDraw.find(objectID);+ if(found==m_modernObjectsForDraw.end()) return FALSE;+ Drawable *drawable=found->second.drawable;+ const Real level=found->second.level;+ if(drawable->isDrawableEffectivelyHidden() || drawable->getFullyObscuredByShroud() ||+ !WaterFoamParticlePolicy::SameMirrorSurface(true,true,level,m_reflectionLevel)) return FALSE;+ for(DrawModule **modules=drawable->getDrawModules();modules && *modules;++modules) {+ const ObjectDrawInterface *draw=(*modules)->getObjectDrawInterface();+ if(!draw) continue;+ RenderObjClass *model=((W3DModelDraw*)draw)->getRenderObject();+ if(!model || model->Is_Hidden() || model->Is_Animation_Hidden()) continue;+ const AABoxClass &bounds=model->Get_Bounding_Box();+ if(level>=bounds.Center.Z-bounds.Extent.Z-0.1f && level<=bounds.Center.Z+bounds.Extent.Z+0.1f) return TRUE;+ }+ #endif+ return FALSE;+ }++ Real WaterRenderObjClass::modernHullDamping(Real x,Real y,Real level) const+ {+ Real damping=1.0f;+ for (size_t i=0;i<m_modernHulls.size();++i) damping=min(damping,WaterHullModel::Damping(m_modernHulls[i],x,y,level));+ return damping;+ }++ void WaterRenderObjClass::updateModernWaterHulls(void)+ {+ #if ZH_MODERN_WATER+ m_modernHulls.clear();+ m_modernContactHulls.clear();+ m_modernVisualHulls.clear();+ m_modernHullObjectIDs.clear();+ if (!m_modernReadsReady || !TheTerrainRenderObject || !TheTerrainRenderObject->getMap()) {+ clearModernWaterHulls();clearModernWaterFoam();return;+ }+ ++m_modernHullSerial;+ const UnsignedInt motionFrame=m_modernMotionFrame;+ const Bool motionFrozen=m_modernMotionFrozen;+ struct Candidate { UnsignedInt objectID; const ModernWaterObject *object; RenderObjClass *model; Real level,score,samplePhase,crestRise; Bool influenceVisible; };+ m_modernFoamHistory.Advance(m_modernWaveTime);+ std::vector<Candidate> candidates;+ for (const auto &entry:m_modernObjectsForDraw) {+ const ModernWaterObject &object=entry.second;+ if (!object.vessel) continue;+ Drawable *drawable=object.drawable;+ if (drawable->isDrawableEffectivelyHidden() || drawable->getFullyObscuredByShroud()) continue;+ const Vector3 &position=object.position;+ const Real level=object.level;+ Real localOffshore=0.0f;+ for (size_t i=0;i<m_modernOpticalTextures.size();++i)+ if (m_modernOpticalTextures[i].level==level && !m_modernOpticalTextures[i].ocean.empty())+ localOffshore=max(localOffshore,WaterSurfaceModel::SampleOffshore(m_modernOpticalTextures[i].ocean.data(),m_modernHeightWidth,m_modernHeightHeight,+ position.X/MAP_XY_FACTOR+m_modernHeightBorder,position.Y/MAP_XY_FACTOR+m_modernHeightBorder,MAP_XY_FACTOR).height);+ if (localOffshore<=0.001f) continue;+ const Real terrainDepth=WaterTerrainDepth(TheTerrainRenderObject->getMap(),position.X,position.Y,level);+ const Real crestRise=WaterHullContact::ReachableCrest(terrainDepth,WaterSurfaceModel::TerrainDamping(terrainDepth,localOffshore));+ for (DrawModule **modules=drawable->getDrawModules();modules && *modules;++modules) {+ const ObjectDrawInterface *draw=(*modules)->getObjectDrawInterface();+ if (!draw) continue;+ // All W3D object draw interfaces are W3DModelDraw implementations (also used by+ // projected shadows and ghost snapshots); use the displayed, interpolated transform.+ W3DModelDraw *modelDraw=(W3DModelDraw*)draw;+ RenderObjClass *model=modelDraw->getRenderObject();+ // Scene visibility culls the hull itself, but an offscreen vessel can still disturb+ // visible water. Keep explicit visibility/shroud exclusions, then cull its influence.+ if (!model || model->Is_Hidden() || model->Is_Animation_Hidden()) continue;+ const AABoxClass &bounds=model->Get_Bounding_Box();+ if (level<bounds.Center.Z-bounds.Extent.Z-0.01f || level>bounds.Center.Z+bounds.Extent.Z+0.01f) continue;+ AABoxClass influence=bounds;+ influence.Extent.X+=122.0f;influence.Extent.Y+=122.0f;+ influence.Extent.Z+=WaterSurfaceModel::MaxDisplacement;+ const Bool influenceVisible=!m_modernRenderCamera || !m_modernRenderCamera->Cull_Box(influence);+ const Real dx=bounds.Center.X-m_modernCamera.X,dy=bounds.Center.Y-m_modernCamera.Y;+ const Real radius=sqrtf(bounds.Extent.X*bounds.Extent.X+bounds.Extent.Y*bounds.Extent.Y);+ const Real score=max(0.0f,sqrtf(dx*dx+dy*dy)-radius);+ Candidate candidate={entry.first,&object,model,level,score,modelDraw->clientOnly_getRenderMotionSamplePhase(),crestRise,influenceVisible};+ size_t insert=0;+ while(insert<candidates.size() && (candidates[insert].score<score ||+ (candidates[insert].score==score && candidates[insert].objectID<entry.first))) ++insert;+ if (insert<WaterFoamHistory::MaxEmitters) {+ candidates.insert(candidates.begin()+insert,candidate);+ if(candidates.size()>WaterFoamHistory::MaxEmitters) candidates.pop_back();+ }+ break;+ }+ }+ for (const Candidate &candidate:candidates) {+ const Matrix3D &matrix=candidate.model->Get_Transform();+ const Vector3 origin=matrix.Get_Translation();+ float axisX=matrix[0][0],axisY=matrix[1][0],axisLength=sqrtf(axisX*axisX+axisY*axisY);+ if (!(axisLength>0.0001f)) continue;+ axisX/=axisLength;axisY/=axisLength;+ std::vector<WaterHullMesh> meshes;unsigned visited=0;+ if (!CollectWaterHullMeshes(candidate.model,origin,axisX,axisY,candidate.level,candidate.crestRise,meshes,visited)) continue;+ size_t slot=0;+ for (;slot<m_modernHullCache.size();++slot)+ if(m_modernHullCache[slot].model==candidate.model && m_modernHullCache[slot].objectID==(UnsignedInt)candidate.objectID) break;+ if (slot==m_modernHullCache.size()) {+ if (slot==WaterHullModel::MaxCacheEntries) {+ slot=0;+ for(size_t i=1;i<m_modernHullCache.size();++i) if(m_modernHullCache[i].lastUse<m_modernHullCache[slot].lastUse) slot=i;+ for(MeshModelClass *mesh:m_modernHullCache[slot].slicedModels) REF_PTR_RELEASE(mesh);+ for(MeshModelClass *mesh:m_modernHullCache[slot].visualModels) REF_PTR_RELEASE(mesh);+ REF_PTR_RELEASE(m_modernHullCache[slot].model);+ m_modernHullCache[slot]=ModernHullCache();+ } else m_modernHullCache.push_back(ModernHullCache());+ m_modernHullCache[slot].model=candidate.model;candidate.model->Add_Ref();+ m_modernHullCache[slot].objectID=(UnsignedInt)candidate.objectID;+ }+ ModernHullCache &cache=m_modernHullCache[slot];cache.lastUse=m_modernHullSerial;+ if(!cache.poses.Reusable(meshes,candidate.crestRise)) {+ cache.polygon=WaterHullModel::Polygon();cache.contact=WaterHullModel::Polygon();+ std::vector<WaterHullModel::Point> points,contactPoints;unsigned triangles=0,contactTriangles=0;Bool valid=TRUE,contactValid=TRUE;+ for(const WaterHullMesh &mesh:meshes) {+ const unsigned count=mesh.model->Get_Polygon_Count();+ // Contact-only meshes cannot consume the independent mean-waterline budget.+ if(mesh.crossesMean && valid) {+ if(count>WaterHullModel::MaxSliceTriangles-triangles) valid=FALSE;+ else triangles+=count;+ }+ if(contactValid) {+ if(count>WaterHullModel::MaxSliceTriangles-contactTriangles) contactValid=FALSE;+ else contactTriangles+=count;+ }+ if(!valid && !contactValid) break;+ if((!mesh.crossesMean || !valid) && !contactValid) continue;+ const Vector3 *vertices=mesh.model->Get_Vertex_Array();+ const TriIndex *indices=mesh.model->Get_Polygon_Array();+ for(unsigned i=0;i<count;++i) {+ const TriIndex &t=indices[i];+ if(t[0]>=mesh.model->Get_Vertex_Count() || t[1]>=mesh.model->Get_Vertex_Count() || t[2]>=mesh.model->Get_Vertex_Count()) {+ if(mesh.crossesMean) valid=FALSE;+ contactValid=FALSE;break;+ }+ const WaterHullModel::Point3 a=WaterHullPoint(mesh,vertices[t[0]]),b=WaterHullPoint(mesh,vertices[t[1]]),c=WaterHullPoint(mesh,vertices[t[2]]);+ if(mesh.crossesMean && valid && !WaterHullModel::SliceTriangle(a,b,c,points)) valid=FALSE;+ if(contactValid && !WaterHullContact::ProjectTriangle(a,b,c,candidate.crestRise,contactPoints)) contactValid=FALSE;+ }+ if(!valid && !contactValid) break;+ }+ if(valid) {+ cache.polygon=WaterHullModel::BuildPolygon(points);+ if(contactValid) cache.contact=WaterHullModel::BuildPolygon(contactPoints);+ }+ // Keep exactly the poses that produced these contours, including an empty result.+ // Retained children prevent identity reuse when an HLOD replaces its mesh assets.+ for(MeshModelClass *mesh:cache.slicedModels) REF_PTR_RELEASE(mesh);+ cache.slicedModels.clear();+ if(cache.slicedModels.capacity()<meshes.size()) cache.slicedModels.reserve(meshes.size());+ for(const WaterHullMesh &mesh:meshes) { mesh.model->Add_Ref();cache.slicedModels.push_back(mesh.model); }+ cache.poses.Store(meshes,candidate.crestRise);++ cache.forwardSign=1.0f;+ const int bow=candidate.model->Get_Bone_Index("BOWWAKE"),stern=candidate.model->Get_Bone_Index("PROPELLERWAKE");+ if(bow>0 && stern>0) {+ const Vector3 direction=candidate.model->Get_Bone_Transform(bow).Get_Translation()-candidate.model->Get_Bone_Transform(stern).Get_Translation();+ cache.forwardSign=direction.X*axisX+direction.Y*axisY<0.0f?-1.0f:1.0f;+ } else if(cache.polygon.count>=3) {+ // Assets without wake bones use the narrower end of their actual waterline.+ float minX=1.0e30f,maxX=-1.0e30f;+ for(unsigned i=0;i<cache.polygon.count;++i) {minX=min(minX,cache.polygon.points[i].x);maxX=max(maxX,cache.polygon.points[i].x);}+ float leftMin=1.0e30f,leftMax=-1.0e30f,rightMin=1.0e30f,rightMax=-1.0e30f;+ const float band=(maxX-minX)*0.2f;+ for(unsigned i=0;i<cache.polygon.count;++i) {+ const WaterHullModel::Point p=cache.polygon.points[i];+ if(p.x<minX+band) {leftMin=min(leftMin,p.y);leftMax=max(leftMax,p.y);}+ if(p.x>maxX-band) {rightMin=min(rightMin,p.y);rightMax=max(rightMax,p.y);}+ }+ if(leftMax-leftMin<rightMax-rightMin) cache.forwardSign=-1.0f;+ }+ }++ if(cache.polygon.count<3) continue;+ const WaterVesselMotion::Point initialVelocity=candidate.object->initialVelocity;+ const WaterVesselMotion::State previousMotion=cache.motion;+ const WaterVesselMotion::Point velocity=WaterVesselMotion::Update(cache.motion,{origin.X,origin.Y},+ candidate.level,motionFrame,motionFrozen,initialVelocity,float(LOGICFRAMES_PER_SECOND),candidate.samplePhase);+ auto packHull=[&](const WaterHullModel::Polygon &polygon,WaterHullModel::Hull &hull,float sign)->Bool {+ if(polygon.count<3) return FALSE;+ float minX=1.0e30f,maxX=-1.0e30f,minY=1.0e30f,maxY=-1.0e30f;+ for(unsigned i=0;i<polygon.count;++i) {+ const WaterHullModel::Point p=polygon.points[i];+ minX=min(minX,p.x);maxX=max(maxX,p.x);minY=min(minY,p.y);maxY=max(maxY,p.y);+ }+ if(maxX-minX<2.0f || maxY-minY<1.0f) return FALSE;+ const float centerX=(minX+maxX)*0.5f,centerY=(minY+maxY)*0.5f;+ hull.data[0][0]=origin.X+axisX*centerX-axisY*centerY;hull.data[0][1]=origin.Y+axisY*centerX+axisX*centerY;+ hull.data[0][2]=candidate.level;hull.data[0][3]=float(polygon.count);+ hull.data[1][0]=axisX*sign;hull.data[1][1]=axisY*sign;+ hull.data[1][2]=(maxX-minX)*0.5f;hull.data[1][3]=(maxY-minY)*0.5f;+ hull.data[2][0]=velocity.x;hull.data[2][1]=velocity.y;+ hull.data[2][2]=float((unsigned(candidate.objectID)*2654435761U)&65535U)/65535.0f;+ hull.data[2][3]=sqrtf(hull.data[1][2]*hull.data[1][2]+hull.data[1][3]*hull.data[1][3]);+ hull.data[3][0]=-hull.data[1][2];hull.data[3][2]=hull.data[1][2];+ float sternY=0.0f,bowY=0.0f;unsigned sternCount=0,bowCount=0;+ for(unsigned i=0;i<WaterHullModel::MaxVertices;++i) {+ const WaterHullModel::Point p=polygon.points[min(i,polygon.count-1)];+ hull.data[4+i/2][(i%2)*2]=(p.x-centerX)*sign;+ hull.data[4+i/2][(i%2)*2+1]=(p.y-centerY)*sign;+ if(i<polygon.count) {+ const float localX=(p.x-centerX)*sign,localY=(p.y-centerY)*sign;+ if(localX<-hull.data[1][2]+0.5f) {sternY+=localY;++sternCount;}+ if(localX>hull.data[1][2]-0.5f) {bowY+=localY;++bowCount;}+ }+ }+ hull.data[3][1]=sternCount?sternY/sternCount:0.0f;+ hull.data[3][3]=bowCount?bowY/bowCount:0.0f;+ return TRUE;+ };+ WaterHullModel::Hull hull,contactHull;+ if(!packHull(cache.polygon,hull,cache.forwardSign)) continue;+ // The displayed model axis is stable through pitch/roll. A sliced narrow-end+ // heuristic can reverse on a keel sliver; actual velocity selects contact ends.+ if(!packHull(cache.contact,contactHull,1.0f)) packHull(cache.polygon,contactHull,1.0f);+ // Keep deposition independent of the eight nearest hulls sent to the shader. Visible+ // vessels outside the camera still leave history in world space, subject to a fixed bound.+ const double motionDt=(double(motionFrame)-previousMotion.frame+candidate.samplePhase-previousMotion.phase)/LOGICFRAMES_PER_SECOND;+ const double motionDx=origin.X-previousMotion.position.x,motionDy=origin.Y-previousMotion.position.y;+ const Bool resetMotion=!previousMotion.initialized || (motionFrame<previousMotion.frame || candidate.level!=previousMotion.level ||+ motionDx*motionDx+motionDy*motionDy>pow(max(32.0,250.0*max(0.0,motionDt)),2.0));+ const WaterFoamHistory::Point motionPosition={origin.X,origin.Y};+ m_modernFoamHistory.Observe((UnsignedInt)candidate.objectID,contactHull,m_modernWaveTime,TRUE,resetMotion,&motionPosition);+ if(candidate.influenceVisible && m_modernHulls.size()<WaterHullModel::MaxHulls) {+ WaterHullVisual::Packet visualPacket={};+ {+ // A separate cache keeps the mean-water clearance, pressure and history unchanged.+ // Only the eight admitted shader hulls collect full reachable visual geometry.+ const float bound=WaterFftGeometry::MaxVerticalDisplacement;+ std::vector<WaterHullMesh> visualMeshes;unsigned visualVisited=0;+ const Bool complete=CollectWaterHullMeshes(candidate.model,origin,axisX,axisY,+ candidate.level-bound,2.0f*bound,visualMeshes,visualVisited);+ const Bool reusable=complete && cache.visualPoses.Reusable(visualMeshes,2.0f*bound,0.0);+ if(!complete) {+ cache.visual=WaterHullVisual::Packet();cache.visualPoses.Clear();+ for(MeshModelClass *mesh:cache.visualModels) REF_PTR_RELEASE(mesh);+ cache.visualModels.clear();+ } else if(!reusable) {+ WaterHullVisual::Builder builder(-bound,bound);+ Bool valid=TRUE;unsigned inspected=0;+ for(const WaterHullMesh &mesh:visualMeshes) {+ const unsigned count=mesh.model->Get_Polygon_Count();+ if(count>WaterHullModel::MaxSliceTriangles-inspected) {valid=FALSE;break;}+ inspected+=count;+ const Vector3 *vertices=mesh.model->Get_Vertex_Array();+ const TriIndex *indices=mesh.model->Get_Polygon_Array();+ for(unsigned ti=0;ti<count;++ti) {+ const TriIndex &triangle=indices[ti];+ if(triangle[0]>=mesh.vertexCount || triangle[1]>=mesh.vertexCount || triangle[2]>=mesh.vertexCount) {valid=FALSE;break;}+ WaterHullVisual::Point3 p[3];+ for(unsigned vi=0;vi<3;++vi) {+ const auto q=WaterHullPoint(mesh,vertices[triangle[vi]]);+ p[vi]={q.x,q.y,q.z-bound};+ }+ if(!builder.AddTriangle(p[0],p[1],p[2])) {valid=FALSE;break;}+ }+ if(!valid) break;+ }+ cache.visual=WaterHullVisual::Packet();+ if(valid) builder.Finish(cache.visual);+ // Cache even complete-but-over-budget geometry; never truncate it to fit.+ // Exact poses are required because nearly tangent slices amplify small motion.+ for(MeshModelClass *mesh:cache.visualModels) REF_PTR_RELEASE(mesh);+ cache.visualModels.clear();cache.visualModels.reserve(visualMeshes.size());+ for(const WaterHullMesh &mesh:visualMeshes) {mesh.model->Add_Ref();cache.visualModels.push_back(mesh.model);}+ cache.visualPoses.Store(visualMeshes,2.0f*bound);+ }+ const float deltaX=contactHull.data[0][0]-origin.X,deltaY=contactHull.data[0][1]-origin.Y;+ WaterHullVisual::Reframe(cache.visual,deltaX*axisX+deltaY*axisY,+ -deltaX*axisY+deltaY*axisX,visualPacket);++ }+ m_modernVisualHulls.push_back(visualPacket);++ m_modernHulls.push_back(hull);+ m_modernContactHulls.push_back(contactHull);+ m_modernHullObjectIDs.push_back((UnsignedInt)candidate.objectID);+ }+ }+ #endif+ }++ // Foam is stored in world-space path sections. The sampled window only controls raster cost;+ // moving the camera reconstructs the same history instead of moving or forgetting that history.+ void WaterRenderObjClass::clearModernWaterFoam(Bool history)+ {+ m_modernFoamDrawFrame = ~0u;+ m_modernFoamDrawObjectIDs.clear();+ for (ModernFoamTexture &field : m_modernFoamTextures) REF_PTR_RELEASE(field.texture);+ m_modernFoamTextures.clear();+ if (history) m_modernFoamHistory.Clear();+ }++ void WaterRenderObjClass::invalidateModernWaterShore(void)+ {+ m_modernShoreHistory.Clear();+ m_modernShoreSource.Clear();+ m_modernShoreReady = FALSE;+ if (++m_modernShoreRevision == 0) m_modernShoreRevision = 1;+ m_modernShoreAttempted = 0;+ for (ModernFoamTexture &field : m_modernFoamTextures) field.valid = FALSE;+ }++ void WaterRenderObjClass::updateModernWaterShore(void)+ {+ #if ZH_MODERN_WATER+ if (m_modernShoreAttempted != m_modernShoreRevision) {+ m_modernShoreAttempted = m_modernShoreRevision;+ m_modernShoreReady = FALSE;+ std::vector<double> levels;+ for (const auto &polygon : m_modernOpticalPolygons) {+ if (polygon.points.size() < 3) continue;+ const double level = polygon.points[0].z;+ Bool flat = TRUE;+ for (const auto &p : polygon.points) flat = flat && fabs(double(p.z) - level) < .01;+ if (flat && std::find(levels.begin(), levels.end(), level) == levels.end()) levels.push_back(level);+ }+ std::sort(levels.begin(), levels.end());+ WaterShoreHistory::BuildResult result = WaterShoreHistory::BuildResult::Invalid;+ if (m_modernOpticalPolygonsValid && !m_modernHeights.empty() && levels.size() <= WaterShoreHistory::MaxLevels) {+ // Complete every level before collecting pointers: texture-vector reallocation cannot+ // invalidate a source field, and camera order cannot choose the retained history levels.+ for (double level : levels) modernWaterOpticalTexture(Real(level));+ std::vector<WaterShoreSource::Level> fields;+ for (double level : levels) for (const auto &field : m_modernOpticalTextures)+ if (field.level == level) {+ fields.push_back({level, &field.shoreContext});+ break;+ }+ WaterShoreSource::Batch candidate;+ if (fields.size() == levels.size()) result = candidate.Build(m_modernHeights.data(), m_modernHeightWidth,+ m_modernHeightHeight, m_modernHeightBorder, MAP_XY_FACTOR, MAP_HEIGHT_SCALE, m_modernOpticalPolygons, fields);+ if (result == WaterShoreHistory::BuildResult::Ready) {+ WaterShoreHistory::Parameters settings;+ settings.maximumRate = WaterShoreFoam::MaximumRate;+ result = m_modernShoreHistory.Install(candidate.Grid(), candidate.Cells(), m_modernShoreRevision, m_modernWaveTime, settings);+ if (result == WaterShoreHistory::BuildResult::Ready) {+ m_modernShoreSource = std::move(candidate);+ m_modernShoreReady = TRUE;+ }+ }+ }++ }+ if (m_modernShoreReady && m_modernShoreHistory.ValidFor(m_modernShoreRevision)) {+ const auto result = m_modernShoreHistory.Advance(m_modernWaveTime, m_modernShoreSource);+ if (result == WaterShoreHistory::AdvanceResult::Invalid) m_modernShoreReady = FALSE;+ if (result == WaterShoreHistory::AdvanceResult::Rewound)+ for (ModernFoamTexture &field : m_modernFoamTextures) field.valid = FALSE;+ }+ #endif+ }++ namespace ModernWater {++ bool Supported()+ {+ #if defined(_WIN32)+ return Direct3D11_Is_Active() && Direct3D11_Present_Is_Enabled();+ #else+ return ZH_MODERN_WATER;+ #endif+ }++ } // namespace ModernWater++ #if ZH_MODERN_WATER+ /** The Modern water's registers run to c895, past any Direct3D 9 device; on Windows they go to the+ Direct3D 11 backend's own bank, which is the only device that draws with them. */+ static void setModernWaterConstants(UnsignedInt first, const float *values, size_t count)+ {+ #if defined(_WIN32)+ Direct3D11_Set_Water_Constants(first, values, (UnsignedInt)count);+ #else+ DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(first, values, (UnsignedInt)count);+ #endif+ }+ #endif++ void WaterRenderObjClass::bindModernWaterFoam(Real level, Bool river)+ {+ #if ZH_MODERN_WATER+ D3DXVECTOR4 area(0, 0, 0, 0), parameters(0, level, 0, m_modernWaveTime);+ TextureClass *texture = NULL;+ const Bool vessel = m_modernFoamHistory.HasFoam();+ const Bool coast = m_modernShoreReady && m_modernShoreHistory.ValidFor(m_modernShoreRevision)+ && !m_modernShoreHistory.Domain().Cells().empty();+ const unsigned channels = ((vessel ? 1 : 0)|(coast ? 2 : 0))|((vessel || coast) ? 4 : 0);+ if (!river && channels && m_modernRenderCamera) {+ size_t index = 0;+ for (; index < m_modernFoamTextures.size(); ++index) if (m_modernFoamTextures[index].level == level) break;+ if (index == m_modernFoamTextures.size() && index < WaterOpticalContext::MaxLevels) {+ m_modernFoamTextures.push_back(ModernFoamTexture());+ m_modernFoamTextures.back().level = level;+ }+ if (index < m_modernFoamTextures.size()) {+ ModernFoamTexture &field = m_modernFoamTextures[index];+ const Vector2 ndc[5] = {Vector2(0, 0), Vector2(-1, -1), Vector2(1, -1), Vector2(1, 1), Vector2(-1, 1)};+ WaterFoamWindow::Point rays[5];+ for (unsigned i = 0; i < 5; ++i) {+ Vector3 target;+ m_modernRenderCamera->Un_Project(target, ndc[i]);+ const Vector3 d = target - m_modernCamera;+ rays[i] = {d.X, d.Y, d.Z};+ }+ const WaterFoamHistory::Mapping map = WaterFoamWindow::Choose({m_modernCamera.X, m_modernCamera.Y, m_modernCamera.Z}, rays, level);+ const Bool remap = map.originX != field.mapping.originX || map.originY != field.mapping.originY ||+ map.widthWorld != field.mapping.widthWorld || map.heightWorld != field.mapping.heightWorld+ || map.widthPixels != field.mapping.widthPixels || map.heightPixels != field.mapping.heightPixels;+ // At most ten uploads per elapsed water second for a stable camera. The shader ages+ // coverage between uploads, and pause freezes both fields. Camera changes may reproject.+ if (!field.valid || field.channels != channels || remap || m_modernWaveTime - field.timestamp >= 0.1f+ || m_modernWaveTime < field.timestamp) {+ std::vector<std::uint32_t> pixels, direction;+ Bool atlas = TRUE;+ if (vessel) atlas = m_modernFoamHistory.BuildAtlas(map, level, pixels, &direction);+ else {+ pixels.assign(size_t(map.widthPixels) * map.heightPixels, 0);+ direction.assign(pixels.size(), 0);+ }+ if (atlas && coast) {+ const auto &states = m_modernShoreHistory.Preview(m_modernShoreSource);+ const WaterShoreHistory::Mapping shoreMap = {map.originX, map.originY, map.widthWorld, map.heightWorld,+ map.widthPixels, map.heightPixels};+ auto coverage = WaterShoreSource::Coverage;+ atlas = WaterShoreHistory::RasterizeAlpha(m_modernShoreHistory.Domain(), states, shoreMap, level, m_modernWaveTime,+ coverage, pixels, m_modernShoreSource.Support());+ }+ if (atlas) {+ // Merge coastal alpha before appending the direction tile: its rasterizer+ // owns exactly the original logical window. Both tiles share one upload/lifetime.+ pixels.insert(pixels.end(), direction.begin(), direction.end());+ const unsigned physicalHeight = map.heightPixels * 2;+ if (field.texture && (field.textureWidth != map.widthPixels || field.textureHeight != physicalHeight)) {+ REF_PTR_RELEASE(field.texture);+ field.valid = FALSE;+ }+ if (!field.texture) {+ field.texture = NEW_REF(TextureClass, (map.widthPixels, physicalHeight, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1));+ field.textureWidth = map.widthPixels;+ field.textureHeight = physicalHeight;+ }+ SurfaceClass *surface = field.texture ? field.texture->Get_Surface_Level() : NULL;+ Int pitch = 0;+ void * bits = surface ? surface->Lock(&pitch) : NULL;+ const Bool uploaded = bits && pitch >= Int(map.widthPixels * 4);+ if (uploaded)+ for (unsigned y = 0; y < physicalHeight; ++y) memcpy((char*) bits + y * pitch,+ pixels.data() + size_t(y) * map.widthPixels, map.widthPixels * 4);+ if (bits) surface->Unlock();+ if (uploaded) {+ field.mapping = map;+ field.timestamp = m_modernWaveTime;+ field.channels = channels;+ field.valid = TRUE;+ }+ else field.valid = FALSE; // missing surface/lock must not expose a stale or partial pair+ REF_PTR_RELEASE(surface);+ } else field.valid = FALSE;+ }+ if (field.valid) {+ texture = field.texture;+ area = D3DXVECTOR4(float(field.mapping.originX), float(field.mapping.originY), float(1.0 / field.mapping.widthWorld),+ float(1.0 / field.mapping.heightWorld));+ parameters = D3DXVECTOR4(float(field.channels), level, float(max(field.mapping.widthWorld / field.mapping.widthPixels,+ field.mapping.heightWorld / field.mapping.heightPixels)), field.timestamp);+ }+ }+ }+ setModernWaterConstants(88, area, 1);+ setModernWaterConstants(89, parameters, 1);+ DX8Wrapper::Set_DX8_Texture(14, texture ? texture->Peek_D3D_Texture() : NULL);+ #endif+ }+++ void WaterRenderObjClass::registerWaterStyleShaders(void)+ {+ // The Classic names draw the transcription of EA's shaders; the plain names draw the Modern text.+ #if ZH_MODERN_WATER+ const Bool modern = m_useModernWater;+ #else+ const Bool modern = FALSE;+ #endif+ if (m_riverWaterPixelShader)+ Direct3D11_Register_Engine_Shader(m_riverWaterPixelShader, modern+ ? "river water ps.1.1" : "classic river water ps.1.1");+ if (m_trapezoidWaterPixelShader)+ Direct3D11_Register_Engine_Shader(m_trapezoidWaterPixelShader, modern+ ? "trapezoid water ps.1.1" : "classic trapezoid water ps.1.1");+ }++ void WaterRenderObjClass::synchronizeWaterStyle(void)+ {+ #if ZH_MODERN_WATER+ const Bool modern = TheGlobalData && TheGlobalData->m_waterStyle != 0 && ModernWater::Supported();+ if (modern == m_useModernWater) return;++ // Apply before any reflected or main-scene water draw. Existing recorded draws keep+ // their immutable GPU programs; both styles have separate program/pipeline cache keys.+ m_useModernWater = modern;+ registerWaterStyleShaders();+ clearModernWaterFoam();+ clearModernWaterHulls();+ invalidateModernWaterShore();+ m_modernProjectedSamples.clear();+ m_modernObstacles.clear();+ m_modernPatchObstacles.clear();+ m_modernObstacleIndex.Clear();++ // Classic clears the mirror to white; Modern clears it transparent. Bypass the+ // stationary-camera reuse once, so neither style samples the other's background.+ m_reflectionReused = TRUE;+ // Keep wave time, capture/pause clock, gameplay levels and water-grid motion intact.+ #endif+ }++ void WaterRenderObjClass::setupModernWaterShader(Bool river, Bool heightCorrection, Bool waveCage)+ {+ #if ZH_MODERN_WATER+ if (!m_useModernWater) return;+ updateModernWaterTextures();+ const Bool reflection = m_pReflectionTexture && !m_renderingMirror &&+ m_reflectionAreaMax.X > m_reflectionAreaMin.X && m_reflectionAreaMax.Y > m_reflectionAreaMin.Y;+ TextureClass *mirror = reflection ? m_pReflectionTexture : m_whiteTexture;+ if (!mirror->Is_Initialized()) mirror->Init();+ DX8Wrapper::Set_DX8_Texture(1, mirror->Peek_D3D_Texture());+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);+ const D3DXVECTOR4 parameters(m_modernWaveTime,+ river ? 1.0f : 0.0f, reflection ? 1.0f : 0.0f, m_reflectionLevel);+ const D3DXVECTOR4 area(m_reflectionAreaMin.X, m_reflectionAreaMin.Y,+ m_reflectionAreaMax.X, m_reflectionAreaMax.Y);+ const Coord3D &sun = TheGlobalData->m_terrainLightPos[0];+ const RGBColor &colour = TheGlobalData->m_terrainDiffuse[0];+ const D3DXVECTOR4 direction(-sun.x, -sun.y, -sun.z, 0.0f);+ const D3DXVECTOR4 light(colour.red, colour.green, colour.blue, 0.0f);+ setModernWaterConstants(1, parameters, 1);+ setModernWaterConstants(2, area, 1);+ setModernWaterConstants(3, direction, 1);+ setModernWaterConstants(4, light, 1);+ WorldHeightMap *map = TheTerrainRenderObject ? TheTerrainRenderObject->getMap() : NULL;+ const D3DXVECTOR4 terrain(map ? map->getBorderSize() * MAP_XY_FACTOR : 0.0f,+ m_modernHeightSide * MAP_XY_FACTOR, 255.0f * MAP_HEIGHT_SCALE, m_modernHeightTexture ? 1.0f : 0.0f);+ setModernWaterConstants(5, terrain, 1);+ TextureClass *optical = river ? NULL : modernWaterOpticalTexture(m_modernOpticalLevel);+ const D3DXVECTOR4 optics(TheWaterTransparency->m_transparentWaterDepth,+ TheWaterTransparency->m_minWaterOpacity, optical ? 1.0f : 0.0f, heightCorrection && !river ? 1.0f : 0.0f);+ setModernWaterConstants(6, optics, 1);+ D3DXVECTOR4 materialColor, materialParameters;+ getModernWaterMaterial(&materialColor.x, &materialParameters.x);+ setModernWaterConstants(ModernWaterMaterial::RegisterColor, materialColor, 1);+ setModernWaterConstants(ModernWaterMaterial::RegisterParameters, materialParameters, 1);+ const RGBColor &ambient = TheGlobalData->m_terrainAmbient[0];+ const D3DXVECTOR4 hullParameters(river ? 0.0f : float(m_modernHulls.size()), ambient.red, ambient.green, ambient.blue);+ setModernWaterConstants(7, hullParameters, 1);+ // Match the terrain's authored ambient + up to three directional lights. Reset all+ // fill slots on every draw so a later one-light map cannot inherit old illumination.+ D3DXVECTOR4 foamFillLights[4] = {D3DXVECTOR4(0, 0, 0, 0), D3DXVECTOR4(0, 0, 0, 0),+ D3DXVECTOR4(0, 0, 0, 0), D3DXVECTOR4(0, 0, 0, 0)};+ foamFillLights[0].w = TheGlobalData->m_numGlobalLights > 0 ? 1.0f : 0.0f;+ for (Int lightIndex = 1; lightIndex < min(3, TheGlobalData->m_numGlobalLights); ++lightIndex) {+ const Coord3D &position = TheGlobalData->m_terrainLightPos[lightIndex];+ const RGBColor &diffuse = TheGlobalData->m_terrainDiffuse[lightIndex];+ Vector3 fillDirection(-position.x, -position.y, -position.z);+ const float magnitude = fillDirection.Length();+ if (magnitude > 0.000001f) fillDirection /= magnitude;+ else fillDirection = Vector3(0, 0, 0);+ const Int slot = (lightIndex - 1) * 2;+ foamFillLights[slot].x = fillDirection.X;+ foamFillLights[slot].y = fillDirection.Y;+ foamFillLights[slot].z = fillDirection.Z;+ foamFillLights[slot + 1] = D3DXVECTOR4(diffuse.red, diffuse.green, diffuse.blue, 0);+ }+ setModernWaterConstants(90, &foamFillLights[0].x, 4);+ if (!river && !m_modernHulls.empty()) {+ setModernWaterConstants(8, &m_modernHulls[0].data[0][0],+ m_modernHulls.size() * WaterHullModel::RegistersPerHull);+ setModernWaterConstants(96, &m_modernContactHulls[0].data[0][0],+ m_modernContactHulls.size() * WaterHullModel::RegistersPerHull);+ }+ {+ // Every slot is initialized, including absent hulls and river draws. The backend takes+ // immutable draw snapshots before a different surface can replace these registers.+ float metadata[WaterHullVisualLayout::MaxHulls][4] = {};+ float packets[WaterHullVisualLayout::PacketRegisters][4] = {};+ if (!river) for (unsigned h = 0; h < m_modernVisualHulls.size() && h < WaterHullVisualLayout::MaxHulls; ++h) {+ memcpy(metadata[h], m_modernVisualHulls[h].metadata, sizeof(metadata[h]));+ memcpy(packets[h * WaterHullVisualLayout::RegistersPerHull], m_modernVisualHulls[h].data, sizeof(m_modernVisualHulls[h].data));+ }+ setModernWaterConstants(WaterHullVisualLayout::MetadataRegister,+ &metadata[0][0], WaterHullVisualLayout::MaxHulls);+ setModernWaterConstants(WaterHullVisualLayout::PacketRegister,+ &packets[0][0], WaterHullVisualLayout::PacketRegisters);+ }+ DX8Wrapper::Set_DX8_Texture(4, optical ? optical->Peek_D3D_Texture() : NULL);+ bindModernWaterFoam(m_modernOpticalLevel, river);+ TextureClass *heightTexture = m_modernHeightTexture;+ if (waveCage && !river && heightCorrection)+ for (const ModernOpticalTexture &cached : m_modernOpticalTextures)+ if (cached.level == m_modernOpticalLevel && cached.waveCage) {+ heightTexture = cached.waveCage;+ break;+ }+ DX8Wrapper::Set_DX8_Texture(2, heightTexture ? heightTexture->Peek_D3D_Texture() : NULL);+ if (m_modernBedTexture) {+ DX8Wrapper::Set_DX8_Texture(7, m_modernBedTexture->Peek_D3D_Texture());+ // Sampling policy is local to the POSIX water draw, leaving the device's stage-7 state intact.}+ // The modern surface carries displacement damping and its original elevation in UV1.+ // Only the new flat-patch mesh uses UV0 for a geometric height correction. Legacy grids+ // and rivers retain their authored base UVs; stale texture matrices must not transform metadata.+ if (heightCorrection && !river) {+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|0);+ DX8Wrapper::Set_DX8_Texture_Stage_State(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);+ }+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXCOORDINDEX, 1);+ DX8Wrapper::Set_DX8_Texture_Stage_State(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);+ DX8Wrapper::Set_DX8_Texture_Stage_State(2, D3DSAMP_MIPFILTER, D3DTEXF_NONE);+ #endif}+ // Bed material detail and its mip chain are generated once and ship with the executable.+ // The terrain fallback refreshes when the map heights or dimensions change.+ void WaterRenderObjClass::updateModernWaterTextures(void)+ {+ #if ZH_MODERN_WATER+ if (!m_modernBedTexture) {+ const Int side=256;+ std::vector<UnsignedInt> pixels(side*side);+ for (Int y=0;y<side;++y) for (Int x=0;x<side;++x) pixels[y*side+x]=WaterBedMaterial::Texel(x,y,side);+ m_modernBedTexture=NEW_REF(TextureClass,(side,side,WW3D_FORMAT_A8R8G8B8,MIP_LEVELS_ALL));+ for (Int size=side,level=0;size>0;size/=2,++level) {+ SurfaceClass *surface=m_modernBedTexture->Get_Surface_Level(level);+ Int pitch; void *bits=surface->Lock(&pitch);+ if (bits) {+ for (Int y=0;y<size;++y) memcpy((char*)bits+y*pitch,&pixels[y*size],size*4);+ surface->Unlock();+ }+ REF_PTR_RELEASE(surface);+ if (size==1) break;+ std::vector<UnsignedInt> mip(size*size/4);+ for (Int y=0;y<size/2;++y) for (Int x=0;x<size/2;++x) {+ UnsignedInt packed=0;+ for (Int shift=0;shift<32;shift+=8) {+ UnsignedInt sum=0;+ for (Int j=0;j<2;++j) for (Int i=0;i<2;++i) sum+=(pixels[(2*y+j)*size+2*x+i]>>shift)&255;+ packed|=((sum+2)/4)<<shift;+ }+ mip[y*(size/2)+x]=packed;+ }+ pixels.swap(mip);+ }+ }+ WorldHeightMap *map = TheTerrainRenderObject ? TheTerrainRenderObject->getMap() : NULL;+ if (!map || map->getXExtent()<=0 || map->getYExtent()<=0 || !map->getDataPtr()) {+ m_modernBowAdmissions.Clear();+ if(m_modernHeightMap || m_modernShoreReady) invalidateModernWaterShore();+ clearModernWaterOpticalTextures();+ REF_PTR_RELEASE(m_modernHeightTexture);+ m_modernHeights.clear();+ m_modernHeightWidth=0; m_modernHeightHeight=0; m_modernHeightSide=0; m_modernHeightBorder=-1;+ m_modernHeightMap=NULL; m_modernHeightData=NULL;+ return;+ }+ const Int width = map->getXExtent(), height = map->getYExtent();+ const size_t count = (size_t)width * height;+ const Bool sameTerrain=map == m_modernHeightMap && map->getDataPtr() == m_modernHeightData &&+ map->getBorderSize() == m_modernHeightBorder && width == m_modernHeightWidth && height == m_modernHeightHeight &&+ m_modernHeights.size() == count && memcmp(m_modernHeights.data(), map->getDataPtr(), count) == 0;+ if(sameTerrain && m_modernHeightTexture) return;+ if(!sameTerrain) invalidateModernWaterShore();+ if(m_modernHeightMap && (m_modernHeightMap!=map || m_modernHeightData!=map->getDataPtr())) { clearModernWaterFoam();m_modernBowAdmissions.Clear(); }+ clearModernWaterOpticalTextures();+ m_modernHeightMap=map; m_modernHeightData=map->getDataPtr();+ m_modernHeightBorder=map->getBorderSize();+ m_modernHeights.assign(map->getDataPtr(), map->getDataPtr() + count);+ if (width != m_modernHeightWidth || height != m_modernHeightHeight || !m_modernHeightTexture) {+ REF_PTR_RELEASE(m_modernHeightTexture);+ m_modernHeightSide = 1; while (m_modernHeightSide < max(width,height)) m_modernHeightSide *= 2;+ m_modernHeightTexture = NEW_REF(TextureClass, (m_modernHeightSide, m_modernHeightSide, WW3D_FORMAT_A8R8G8B8, MIP_LEVELS_1));+ }+ m_modernHeightWidth = width; m_modernHeightHeight = height;+ SurfaceClass *surface = m_modernHeightTexture->Get_Surface_Level();+ Int pitch; void *bits = surface->Lock(&pitch);+ if (bits) {+ for (Int y = 0; y < m_modernHeightSide; ++y) for (Int x = 0; x < m_modernHeightSide; ++x) {+ const UnsignedInt h = map->getHeight(min(x,width-1), min(y,height-1));+ // Alpha zero makes the height-only fallback explicitly opt out of wave cages.+ ((UnsignedInt *)((char *)bits+y*pitch))[x] = (h<<16) | (h<<8) | h;+ }+ surface->Unlock();+ }+ REF_PTR_RELEASE(surface);+ #endif+ }++ void WaterRenderObjClass::clearModernWaterOpticalTextures(void)+ {+ m_modernProjectedSamples.clear();+ m_modernObstacleIndex.Clear();+ for (size_t i=0;i<m_modernOpticalTextures.size();++i) {+ REF_PTR_RELEASE(m_modernOpticalTextures[i].texture);+ REF_PTR_RELEASE(m_modernOpticalTextures[i].waveCage);+ }+ m_modernOpticalTextures.clear();+ }++ void WaterRenderObjClass::refreshModernWaterOpticalPolygons(void)+ {+ #if ZH_MODERN_WATER+ std::vector<WaterOpticalContext::Polygon> polygons;+ size_t points=0;+ Bool valid=TRUE;+ for (const WaterPolygonForDraw &waterPolygon:m_waterPolygonsForDraw) {+ const WaterPolygonForDraw *trigger=&waterPolygon;+ if (!trigger->isWaterArea() || trigger->isRiver() || trigger->getNumPoints()<3) continue;+ if ((size_t)trigger->getNumPoints()>WaterOpticalContext::MaxPoints-points) { valid=FALSE; break; }+ points+=trigger->getNumPoints();+ WaterOpticalContext::Polygon polygon;+ polygon.points.reserve(trigger->getNumPoints());+ for (Int i=0;i<trigger->getNumPoints();++i) {+ const ICoord3D *p=trigger->getPoint(i);+ polygon.points.push_back({(float)p->x,(float)p->y,(float)p->z});+ }+ polygons.push_back(polygon);+ }+ if (valid!=m_modernOpticalPolygonsValid || !WaterOpticalContext::SamePolygons(polygons,m_modernOpticalPolygons)) {+ invalidateModernWaterShore();+ clearModernWaterOpticalTextures();+ if(m_modernOpticalPolygonsValid) { clearModernWaterFoam();m_modernBowAdmissions.Clear(); }+ m_modernOpticalPolygons.swap(polygons);+ m_modernOpticalPolygonsValid=valid;+ }+ #endif+ }++ TextureClass *WaterRenderObjClass::modernWaterOpticalTexture(Real level)+ {+ #if ZH_MODERN_WATER+ if (!m_modernOpticalPolygonsValid) return NULL;+ for (size_t i=0;i<m_modernOpticalTextures.size();++i)+ if (m_modernOpticalTextures[i].level==level) return m_modernOpticalTextures[i].texture;+ // Keep the first levels for this map revision. Overflow stays on the clear-water profile instead+ // of evicting/rebuilding textures every frame on maps with many water elevations.+ if (m_modernOpticalTextures.size()>=WaterOpticalContext::MaxLevels) return NULL;+ m_modernOpticalTextures.push_back({level,NULL});+ WaterOpticalContext::Field field;+ if (!WaterOpticalContext::Build(m_modernHeights.empty()?NULL:m_modernHeights.data(),+ m_modernHeightWidth,m_modernHeightHeight,m_modernHeightBorder,MAP_XY_FACTOR,MAP_HEIGHT_SCALE,+ level,m_modernOpticalPolygons,field)) return NULL;+ m_modernOpticalTextures.back().shoreContext=field;+ TextureClass *texture=NEW_REF(TextureClass,(m_modernHeightSide,m_modernHeightSide,WW3D_FORMAT_A8R8G8B8,MIP_LEVELS_1));+ SurfaceClass *surface=texture->Get_Surface_Level();+ Int pitch; void *bits=surface->Lock(&pitch);+ if (bits) {+ for (Int y=0;y<m_modernHeightSide;++y) for (Int x=0;x<m_modernHeightSide;++x) {+ const size_t n=(size_t)min(y,m_modernHeightHeight-1)*m_modernHeightWidth+min(x,m_modernHeightWidth-1);+ ((UnsignedInt*)((char*)bits+y*pitch))[x]=WaterOpticalContext::Texel(field,n);+ }+ surface->Unlock();+ }+ REF_PTR_RELEASE(surface);+ if (!bits) { REF_PTR_RELEASE(texture); return NULL; }+ ModernOpticalTexture &cached=m_modernOpticalTextures.back();+ cached.texture=texture;+ {+ WaterWaveCage::Field cage;+ if(WaterWaveCage::Build(m_modernHeights.data(),m_modernHeightWidth,m_modernHeightHeight,+ m_modernHeightBorder,MAP_XY_FACTOR,MAP_HEIGHT_SCALE,level,field,cage)) {+ TextureClass *cageTexture=NEW_REF(TextureClass,(m_modernHeightSide,m_modernHeightSide,WW3D_FORMAT_A8R8G8B8,MIP_LEVELS_1));+ SurfaceClass *cageSurface=cageTexture?cageTexture->Get_Surface_Level():NULL;+ Int cagePitch=0;void *cageBits=cageSurface?cageSurface->Lock(&cagePitch):NULL;+ const Bool uploaded=cageBits && cagePitch>=m_modernHeightSide*4;+ if(uploaded)+ for(Int y=0;y<m_modernHeightSide;++y) for(Int x=0;x<m_modernHeightSide;++x) {+ const size_t n=size_t(min(y,m_modernHeightHeight-1))*m_modernHeightWidth+min(x,m_modernHeightWidth-1);+ ((UnsignedInt*)((char*)cageBits+y*cagePitch))[x]=WaterWaveCage::Texel(cage,n);+ }+ if(cageBits) cageSurface->Unlock();+ REF_PTR_RELEASE(cageSurface);+ if(uploaded) {+ cached.waveCage=cageTexture;+ cached.waveCageSupport.resize(cage.texels.size());+ for(size_t n=0;n<cage.texels.size();++n) cached.waveCageSupport[n]=UnsignedByte(cage.texels[n]>>24);+ }+ else REF_PTR_RELEASE(cageTexture); // fall back to the original height texture, with zero support+ }+ }+ cached.ocean.swap(field.ocean);+ // Retain exactly the bytes uploaded to Texture4, including its bilinear shoreline blend.+ Int oceanMinX=m_modernHeightWidth,oceanMinY=m_modernHeightHeight,oceanMaxX=-1,oceanMaxY=-1;+ for (Int y=0;y<m_modernHeightHeight;++y) for (Int x=0;x<m_modernHeightWidth;++x)+ if (cached.ocean[y*m_modernHeightWidth+x]) {+ oceanMinX=min(oceanMinX,x);oceanMinY=min(oceanMinY,y);oceanMaxX=max(oceanMaxX,x);oceanMaxY=max(oceanMaxY,y);+ }+ if (oceanMaxX>=0) cached.oceanExtent=max(oceanMaxX-oceanMinX,oceanMaxY-oceanMinY)*MAP_XY_FACTOR;+ return texture;+ #else+ return NULL;+ #endif+ }@@@ -1061,11 -2058,7 +2099,10 @@@ void WaterRenderObjClass::ReAcquireResohr = D3DXAssembleShader( shader, (UINT)strlen(shader), NULL, NULL, 0, &compiledShader, NULL);if (hr==0) {hr = DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((RenderUInt32*)compiledShader->GetBufferPointer(), &m_riverWaterPixelShader);+ // the same bytecode under a second name, which the D3D11 backend draws with foam (WaterFoam)+ DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((RenderUInt32*)compiledShader->GetBufferPointer(), &m_riverWaterFoamPixelShader);compiledShader->Release();- Direct3D11_Register_Engine_Shader(m_riverWaterPixelShader, "river water ps.1.1");+ Direct3D11_Register_Engine_Shader(m_riverWaterFoamPixelShader, "river water foam ps.1.1");}shader ="ps.1.1\n \@@@ -1094,10 -2087,7 +2131,9 @@@hr = D3DXAssembleShader( shader, (UINT)strlen(shader), NULL, NULL, 0, &compiledShader, NULL);if (hr==0) {hr = DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((RenderUInt32*)compiledShader->GetBufferPointer(), &m_trapezoidWaterPixelShader);+ DX8Wrapper::_Get_D3D_Device()->CreatePixelShader((RenderUInt32*)compiledShader->GetBufferPointer(), &m_trapezoidWaterFoamPixelShader);compiledShader->Release();- Direct3D11_Register_Engine_Shader(m_trapezoidWaterPixelShader, "trapezoid water ps.1.1");+ Direct3D11_Register_Engine_Shader(m_trapezoidWaterFoamPixelShader, "trapezoid water foam ps.1.1");}shader ="ps.1.1\n \@@@ -1792,11 -2828,103 +2874,108 @@@ void WaterRenderObjClass::Render(Renderreturn;}+ // The foam reads how deep the water is out of the scene's depth, which the ground and every+ // opaque object have written by now: a copy, taken once here, before the water writes any.+ if (waterFoam())+ Direct3D11_Take_Scene_Depth();++ #if ZH_MODERN_WATER+ WaterShoreOverlay::Scope shoreScope(DX8Wrapper::_Get_D3D_Device(),+ m_useModernWater && m_waterType==WATER_TYPE_0_TRANSLUCENT && m_trapezoidWaterPixelShader &&+ !TheGlobalData->m_isWorldBuilder && !TheGlobalData->m_usingWaterTrackEditor);+ m_modernFoamDrawFrame=~0u;m_modernFoamDrawObjectIDs.clear();+ unsigned oldModernCoordIndex=0,oldModernTransformFlags=0;+ unsigned oldModernBaseCoordIndex=0,oldModernBaseTransformFlags=0;+ Bool oldModernStagesKnown=FALSE;+ IDirect3DBaseTexture9 *oldModernBed=NULL,*oldModernOptical=NULL,*oldModernFoam=NULL;+ if (m_useModernWater) {+ // The wrapper's own record: under Direct3D 11 the Direct3D 9 device is behind it (Defer_D3D9_State).+ // Stage 14 is past the wrapper's stages and is set on the device at once.+ oldModernStagesKnown=DX8Wrapper::Get_DX8_Texture_Stage_State(0,D3DTSS_TEXCOORDINDEX,oldModernBaseCoordIndex)+ & DX8Wrapper::Get_DX8_Texture_Stage_State(0,D3DTSS_TEXTURETRANSFORMFLAGS,oldModernBaseTransformFlags)+ & DX8Wrapper::Get_DX8_Texture_Stage_State(1,D3DTSS_TEXCOORDINDEX,oldModernCoordIndex)+ & DX8Wrapper::Get_DX8_Texture_Stage_State(1,D3DTSS_TEXTURETRANSFORMFLAGS,oldModernTransformFlags);+ oldModernBed=DX8Wrapper::Get_DX8_Texture(7);+ if (oldModernBed) oldModernBed->AddRef();+ oldModernOptical=DX8Wrapper::Get_DX8_Texture(4);+ if (oldModernOptical) oldModernOptical->AddRef();+ DX8Wrapper::_Get_D3D_Device()->GetTexture(14,&oldModernFoam);+ updateModernWaterTextures();+ refreshModernWaterOpticalPolygons();+ m_modernRenderCamera=&rinfo.Camera;+ m_modernCamera=rinfo.Camera.Get_Position();+ Int modernPatches=0,modernFlatPatches=0,visibleFlatPatches=0;+ Real highestModernWater=m_level;+ Bool hasModernWater=FALSE;+ for (const WaterPolygonForDraw &polygon:m_waterPolygonsForDraw) {+ const WaterPolygonForDraw *trigger=&polygon;+ if (!trigger->isWaterArea() || trigger->getNumPoints()<3) continue;+ modernPatches+=trigger->isRiver() ? max(0,trigger->getNumPoints()/2-1) :+ ((trigger->getNumPoints()-1)/2);+ if (!trigger->isRiver()) {+ modernFlatPatches+=(trigger->getNumPoints()-1)/2;+ // This count only controls sample reuse, never topology or density. Conservatively+ // include every visible planar flat patch that could use the projected path.+ for (Int k=1;k<trigger->getNumPoints()-1;k+=2) {+ const Int corner[4]={k+2<trigger->getNumPoints()?k+2:k+1,k+1,k,0};+ Vector3 minimum,maximum;float levels[4];+ for (Int n=0;n<4;++n) {+ const ICoord3D &p=*trigger->getPoint(corner[n]);levels[n]=float(p.z);+ if (n==0) minimum=maximum=Vector3(float(p.x),float(p.y),float(p.z));+ else { minimum.X=min(minimum.X,float(p.x));minimum.Y=min(minimum.Y,float(p.y));minimum.Z=min(minimum.Z,float(p.z));+ maximum.X=max(maximum.X,float(p.x));maximum.Y=max(maximum.Y,float(p.y));maximum.Z=max(maximum.Z,float(p.z)); }+ }+ minimum.Z-=WaterSurfaceModel::MaxDisplacement;maximum.Z+=WaterSurfaceModel::MaxDisplacement;+ minimum.X-=WaterFftGeometry::MaxHorizontalDisplacement;minimum.Y-=WaterFftGeometry::MaxHorizontalDisplacement;+ maximum.X+=WaterFftGeometry::MaxHorizontalDisplacement;maximum.Y+=WaterFftGeometry::MaxHorizontalDisplacement;+ if (WaterProjectedMesh::HasSingleLevel(levels) && fabsf(m_modernCamera.Z-levels[0])>WaterSurfaceModel::MaxDisplacement*2 &&+ !rinfo.Camera.Cull_Box(AABoxClass((minimum+maximum)*0.5f,(maximum-minimum)*0.5f))) ++visibleFlatPatches;+ }+ }+ for (Int point=0;point<trigger->getNumPoints();++point) {+ const Real elevation=trigger->getPoint(point)->z;+ if (!hasModernWater || elevation>highestModernWater) highestModernWater=elevation;+ hasModernWater=TRUE;+ }+ }+ // One map-wide subdivision count keeps all common edges welded. The authored polygon count+ // itself is irreducible; added tessellation stays within the shared model's vertex budget.+ for (size_t i=0;i<m_modernOpticalPolygons.size();++i) if (!m_modernOpticalPolygons[i].points.empty())+ modernWaterOpticalTexture(m_modernOpticalPolygons[i].points[0].z);+ updateModernWaterShore(); // same time is a no-op; also initializes before a first draw without a client update+ // Rivers retain their old camera-height detail. Ocean interiors use a visible projected+ // lattice and constrain boundary samples to these same morphed edge polylines.+ const Int baseCells=WaterSurfaceModel::CellsForPatches(modernPatches);+ const WaterSurfaceModel::MeshLOD modernLOD=WaterSurfaceModel::LODForCameraHeight(+ baseCells,m_modernCamera.Z-highestModernWater);+ m_modernMeshCells=modernLOD.cells;+ m_modernMeshMorph=modernLOD.morph;+ const size_t baseVertices=size_t(baseCells+1)*(baseCells+1);+ const size_t retainedVertices=size_t(max(0,modernPatches-modernFlatPatches))*baseVertices;+ const size_t available=retainedVertices<WaterSurfaceModel::VertexBudget?WaterSurfaceModel::VertexBudget-retainedVertices:0;+ Int targetWidth,targetHeight,targetBits;bool targetWindowed;+ WW3D::Get_Render_Target_Resolution(targetWidth,targetHeight,targetBits,targetWindowed);+ const WaterProjectedMesh::Resolution projected=WaterProjectedMesh::ChooseResolution(targetWidth,targetHeight,modernFlatPatches,available,4u*(baseCells+1));+ m_modernProjectedColumns=projected.columns;m_modernProjectedRows=projected.rows;+ m_modernProjectedWidth=targetWidth;m_modernProjectedHeight=targetHeight;+ m_modernProjectedBudget=min(size_t(60000),available/size_t(max(1,modernFlatPatches)));+ // Per-frame reuse shares lattice vertices across flat patches/levels, while never keeping+ // stale terrain, moving hulls, wave time or camera state from a previous render.+ m_modernProjectedSamples.clear();+ m_modernObstacleIndex.Clear();++ m_modernProjectedCacheEnabled=visibleFlatPatches>1;+ m_modernBowVertices=m_modernBowTriangles=0;+ m_modernBowAdmissions.Begin(m_modernWaveTime);++ updateModernWaterHulls();++ for (size_t i=0;i<m_modernObstacles.size();++i)+ m_modernObstacles[i].hasHull=modernHasHull(m_modernObstacleObjectIDs[i]);++ }+ #endif+switch(m_waterType){case WATER_TYPE_0_TRANSLUCENT:@@@ -3144,11 -4981,7 +5038,12 @@@ void WaterRenderObjClass::setupFlatWateif (m_trapezoidWaterPixelShader){DX8Wrapper::_Get_D3D_Device()->SetPixelShaderConstantF(0, D3DXVECTOR4(REFLECTION_FACTOR, REFLECTION_FACTOR, REFLECTION_FACTOR, 1.0f), 1);DX8Wrapper::Set_Pixel_Shader(m_trapezoidWaterPixelShader);+ if (waterFoam()) {+ // unfeathered unless drawTrapezoidWater hands over the depth curve+ DX8Wrapper::Set_DX8_Render_State(D3DRS_TEXTUREFACTOR, waterFoamFactor(m_riverVOrigin, 0.0f, 0.0f));+ DX8Wrapper::Set_Pixel_Shader(m_trapezoidWaterFoamPixelShader);+ }+ setupModernWaterShader(FALSE,heightCorrection,waveCage);}}diff --cc GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cppindex 26962e659,872d89403..7746956cb--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8renderer.cpp@@@ -1918,17 -1919,12 +1919,18 @@@ void DX8TextureCategoryClass::Render(vo// The object's look on the Direct3D 11 frame (RTS3DScene::renderOneObject picks it), for this// mesh's draws only. A sorted mesh draws later, from the sorting pool, which keeps the look- // with its triangles (SortingRendererClass::Insert_Triangles).+ // with its triangles (SortingRendererClass::Insert_Triangles), and on Linux its sun shadow+ // coverage too.const unsigned draw_effect = mesh->Get_Draw_Effect();if (draw_effect != 0) {- Direct3D11_Set_Draw_Effect(draw_effect, mesh->Get_Draw_Effect_Parameters());+ SunShadow::SetCasterEffect(DX8Wrapper::_Get_D3D_Device(),draw_effect, mesh->Get_Draw_Effect_Parameters());}+ // A house colour mesh under the Team Glow option. Immediate draws only: a sorted one draws later,+ // after this has been put back, and goes without.+ const bool team_glow = mesh->Peek_Model()->Get_Flag(MeshGeometryClass::TEAM_GLOW) != 0;+ if (team_glow) {+ Direct3D11_Set_Team_Glow(true);+ }if ((!!mesh->Peek_Model()->Get_Flag(MeshGeometryClass::SORT)) && WW3D::Is_Sorting_Enabled()) {renderer->Render_Sorted(mesh->Get_Base_Vertex_Offset(),mesh->Get_Bounding_Sphere());@@@ -1986,11 -1982,8 +1988,11 @@@}if (draw_effect != 0) {static const float no_effect[4] = { 0.0f, 0.0f, 0.0f, 0.0f };- Direct3D11_Set_Draw_Effect(0, no_effect);+ SunShadow::SetCasterEffect(DX8Wrapper::_Get_D3D_Device(),0, no_effect);}+ if (team_glow) {+ Direct3D11_Set_Team_Glow(false);+ }//--------------------------------------------------------------------if (mesh->Get_ObjectScale() != 1.0f)DX8Wrapper::Set_DX8_Render_State(D3DRS_NORMALIZENORMALS, false);diff --cc GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.hindex 3ee0c4b58,54755db02..4100cc0d2--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/engineshader.h@@@ -71,11 -71,9 +71,14 @@@ enum EngineShaderPrograENGINE_SHADER_FLAT_TERRAIN_NOISE_2,ENGINE_SHADER_ROAD_NOISE_2,ENGINE_SHADER_MONOCHROME,- // The trapezoid and river water again with foam, shore depth and the sun's shadow+ // Explicit Classic variants keep the SDL shader cache independent of the selected water style.+ ENGINE_SHADER_WATER_CLASSIC_TRAPEZOID,- ENGINE_SHADER_WATER_CLASSIC_RIVER++ ENGINE_SHADER_WATER_CLASSIC_RIVER,++ // The Classic trapezoid and river water again with foam, shore depth and the sun's shadow+ // (the Water Foam option). Same D3D9 bytecode, a second name; after the table's last shipped program+ // so the shader case sweep and its reference set stay as they were.+ ENGINE_SHADER_WATER_TRAPEZOID_FOAM,+ ENGINE_SHADER_WATER_RIVER_FOAM};// The name the engine loaded the shader under: a path for the ones that ship as files@@@ -101,10 -99,13 +104,17 @@@ bool EngineShader_Pixel_Program(EngineS// the trees are not among them: both have shadows of their own.bool EngineShader_Paints_Ground(EngineShaderProgram program);+// Which transcribed programs read the scene's depth copy at t7: the foam water, for how deep the+// water is under each pixel. The copy is the soft particles' (DX11BackendClass::Take_Scene_Depth).+bool EngineShader_Reads_Scene_Depth(EngineShaderProgram program);++ // The two programs the Modern water style draws with: the plain names, which W3DWater registers+ // only under that style. Their text reads the water's own constant block and fifteen stages.+ inline bool EngineShader_Is_Modern_Water(EngineShaderProgram program)+ {+ return program == ENGINE_SHADER_WATER_TRAPEZOID || program == ENGINE_SHADER_WATER_RIVER;+ }+// What the pipeline cache keys this program under and what the dump calls its file.const char * EngineShader_Name(EngineShaderProgram program);diff --cc GeneralsMD/Code/Tools/optionsmenu_layout.pyindex 375c6bd95,909d2eaf4..7d4d4e6fc--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py@@@ -336,7 -337,7 +340,10 @@@ GROUP_LAYOUT =("check", "CheckClassicGraphics"),setting("LabelMSAA", "ComboBoxMSAA"),setting("LabelTextureFilter", "ComboBoxTextureFilter"),-- setting("LabelAnisotropy", "SliderAnisotropy", "ValueAnisotropy")]),++ setting("LabelAnisotropy", "SliderAnisotropy", "ValueAnisotropy"),++ # the Lighting column is full with the water and cloud styles++ ("check", "CheckMapLight"),++ ("check", "CheckTeamGlow")]),("GUI:OptionsGroupLighting", [setting("LabelLightingStyle", "ComboBoxLightingStyle"),setting("LabelBloom", "ComboBoxBloom"),