From 4f521a94d7a7b659b71459e6ece501a0c6588062 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 31 Oct 2024 14:27:28 +0300 Subject: [PATCH] Allow opting out of water culling (#7318) --- CHANGELOG.md | 1 + apps/openmw/mwrender/renderingmanager.cpp | 1 + components/settings/categories/terrain.hpp | 1 + components/terrain/world.cpp | 10 ++++++++-- components/terrain/world.hpp | 1 + docs/source/reference/modding/settings/terrain.rst | 13 +++++++++++++ files/settings-default.cfg | 3 +++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf6b8062b..b540184c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -238,6 +238,7 @@ Feature #7194: Ori to show texture paths Feature #7214: Searching in the in-game console Feature #7248: Searching in the console with regex and toggleable case-sensitivity + Feature #7318: Ability to disable water culling Feature #7468: Factions API for Lua Feature #7477: NegativeLight Magic Effect flag Feature #7499: OpenMW-CS: Generate record filters by drag & dropping cell content to the filters field diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 2a105a1abc..3973a2006b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1495,6 +1495,7 @@ namespace MWRender newChunkMgr.mTerrain->setTargetFrameRate(Settings::cells().mTargetFramerate); float distanceMult = std::cos(osg::DegreesToRadians(std::min(mFieldOfView, 140.f)) / 2.f); newChunkMgr.mTerrain->setViewDistance(mViewDistance * (distanceMult ? 1.f / distanceMult : 1.f)); + newChunkMgr.mTerrain->enableHeightCullCallback(Settings::terrain().mWaterCulling); return mWorldspaceChunks.emplace(worldspace, std::move(newChunkMgr)).first->second; } diff --git a/components/settings/categories/terrain.hpp b/components/settings/categories/terrain.hpp index f26cc264b8..d366aad97b 100644 --- a/components/settings/categories/terrain.hpp +++ b/components/settings/categories/terrain.hpp @@ -37,6 +37,7 @@ namespace Settings makeMaxStrictSanitizerFloat(0) }; SettingValue mObjectPagingMinSizeCostMultiplier{ mIndex, "Terrain", "object paging min size cost multiplier", makeMaxStrictSanitizerFloat(0) }; + SettingValue mWaterCulling{ mIndex, "Terrain", "water culling" }; }; } diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index 9c409b3bc2..58cfc0b068 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -23,7 +23,6 @@ namespace Terrain , mParent(parent) , mResourceSystem(resourceSystem) , mBorderVisible(false) - , mHeightCullCallback(new HeightCullCallback) , mWorldspace(worldspace) { mTerrainRoot = new osg::Group; @@ -67,7 +66,6 @@ namespace Terrain , mChunkManager(nullptr) , mCellBorder(nullptr) , mBorderVisible(false) - , mHeightCullCallback(nullptr) , mWorldspace(worldspace) { mTerrainRoot = new osg::Group; @@ -143,6 +141,14 @@ namespace Terrain mChunkManager->clearCache(); } + void World::enableHeightCullCallback(bool enable) + { + if (enable) + mHeightCullCallback = new HeightCullCallback; + else + mHeightCullCallback = nullptr; + } + osg::Callback* World::getHeightCullCallback(float highz, unsigned int mask) { if (!mHeightCullCallback || mTerrainRoot->getNumChildren() == 0) diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index 63b920146b..cfe9634773 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -106,6 +106,7 @@ namespace Terrain Storage* getStorage() { return mStorage; } + void enableHeightCullCallback(bool enable); osg::Callback* getHeightCullCallback(float highz, unsigned int mask); void setActiveGrid(const osg::Vec4i& grid) { mActiveGrid = grid; } diff --git a/docs/source/reference/modding/settings/terrain.rst b/docs/source/reference/modding/settings/terrain.rst index 44b02f59d4..767f549fc7 100644 --- a/docs/source/reference/modding/settings/terrain.rst +++ b/docs/source/reference/modding/settings/terrain.rst @@ -205,3 +205,16 @@ object paging min size cost multiplier This setting adjusts the calculated cost of merging an object used in the mentioned functionality. The larger this value is, the less expensive objects can be before they are discarded. See the formula above to figure out the math. + +water culling +------------- +:Type: boolean +:Range: True/False +:Default: True + +Controls whether water culling is used. + +Water culling is an optimisation that prevents the expensive rendering of water when it is +evaluated to be below any visible terrain chunk, potentially improving performance in many scenes. + +You may want to opt out of it if it causes framerate instability or inappropriately invisible water on your setup. diff --git a/files/settings-default.cfg b/files/settings-default.cfg index e4636f0ce9..5acce45df5 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -119,6 +119,9 @@ object paging min size merge factor = 0.3 # Controls how inexpensive an object needs to be to utilize 'min size merge factor'. object paging min size cost multiplier = 25 +# Don't draw water if it's evaluated to be below all visible terrain +water culling = true + [Fog] # If true, use extended fog parameters for distant terrain not controlled by