Skip to content

Commit

Permalink
Merge branch 'nowaterculling' into 'master'
Browse files Browse the repository at this point in the history
Allow opting out of water culling (#7318)

Closes #7318

See merge request OpenMW/openmw!4441
  • Loading branch information
psi29a committed Nov 1, 2024
2 parents c3b575f + 4f521a9 commit 6207949
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions components/settings/categories/terrain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Settings
makeMaxStrictSanitizerFloat(0) };
SettingValue<float> mObjectPagingMinSizeCostMultiplier{ mIndex, "Terrain",
"object paging min size cost multiplier", makeMaxStrictSanitizerFloat(0) };
SettingValue<bool> mWaterCulling{ mIndex, "Terrain", "water culling" };
};
}

Expand Down
10 changes: 8 additions & 2 deletions components/terrain/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Terrain
, mParent(parent)
, mResourceSystem(resourceSystem)
, mBorderVisible(false)
, mHeightCullCallback(new HeightCullCallback)
, mWorldspace(worldspace)
{
mTerrainRoot = new osg::Group;
Expand Down Expand Up @@ -67,7 +66,6 @@ namespace Terrain
, mChunkManager(nullptr)
, mCellBorder(nullptr)
, mBorderVisible(false)
, mHeightCullCallback(nullptr)
, mWorldspace(worldspace)
{
mTerrainRoot = new osg::Group;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions components/terrain/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
13 changes: 13 additions & 0 deletions docs/source/reference/modding/settings/terrain.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions files/settings-default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6207949

Please sign in to comment.