From a9e0489867401192d1bfa51a2903a287c8ab579c Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Fri, 19 May 2023 10:19:16 +0200 Subject: [PATCH] fixes stutters => bugs in the way cells were updated. --- apps/openmw/mwrender/renderingmanager.cpp | 3 +++ components/terrain/quadtreeworld.cpp | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 0f0691bbe0..e8fbee1a09 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1363,6 +1363,9 @@ namespace MWRender mTerrainStorage.get(), Mask_Terrain, worldspace, Mask_PreCompile, Mask_Debug); newTerrain->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells")); + float distanceMult = std::cos(osg::DegreesToRadians(std::min(mFieldOfView, 140.f)) / 2.f); + newTerrain->setViewDistance(mViewDistance * (distanceMult ? 1.f / distanceMult : 1.f)); + mWorldspaceTerrains[worldspace] = std::move(newTerrain); return mWorldspaceTerrains[worldspace].get(); } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 50415cc8a8..8449f3df25 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -39,13 +39,14 @@ namespace Terrain class DefaultLodCallback : public LodCallback { public: - DefaultLodCallback( - float factor, float minSize, float viewDistance, const osg::Vec4i& grid, float distanceModifier = 0.f) + DefaultLodCallback(float factor, float minSize, float viewDistance, const osg::Vec4i& grid, int cellSizeInUnits, + float distanceModifier = 0.f) : mFactor(factor) , mMinSize(minSize) , mViewDistance(viewDistance) , mActiveGrid(grid) , mDistanceModifier(distanceModifier) + , mCellSizeInUnits(cellSizeInUnits) { } @@ -69,7 +70,8 @@ namespace Terrain dist = std::max(0.f, dist + mDistanceModifier); if (dist > mViewDistance && !activeGrid) // for Scene<->ObjectPaging sync the activegrid must remain loaded return StopTraversal; - return getNativeLodLevel(node, mMinSize) <= convertDistanceToLodLevel(dist, mMinSize, mFactor) + return getNativeLodLevel(node, mMinSize) + <= convertDistanceToLodLevel(dist, mMinSize, mFactor, mCellSizeInUnits) ? StopTraversalAndUse : Deeper; } @@ -77,9 +79,9 @@ namespace Terrain { return Log2(static_cast(node->getSize() / minSize)); } - static unsigned int convertDistanceToLodLevel(float dist, float minSize, float factor) + static unsigned int convertDistanceToLodLevel(float dist, float minSize, float factor, int cellSize) { - return Log2(static_cast(dist / (Constants::CellSizeInUnits * minSize * factor))); + return Log2(static_cast(dist / (cellSize * minSize * factor))); } private: @@ -88,6 +90,7 @@ namespace Terrain float mViewDistance; osg::Vec4i mActiveGrid; float mDistanceModifier; + int mCellSizeInUnits; }; class RootNode : public QuadTreeNode @@ -471,7 +474,8 @@ namespace Terrain if (needsUpdate) { vd->reset(); - DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, mActiveGrid); + DefaultLodCallback lodCallback( + mLodFactor, mMinSize, mViewDistance, mActiveGrid, ESM::getCellSize(mWorldspace)); mRootNode->traverseNodes(vd, viewPoint, &lodCallback); } @@ -549,7 +553,7 @@ namespace Terrain distanceModifier = 1024; else if (pass == 2) distanceModifier = -1024; - DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, distanceModifier); + DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, cellWorldSize, distanceModifier); mRootNode->traverseNodes(vd, viewPoint, &lodCallback); if (pass == 0) @@ -605,8 +609,9 @@ namespace Terrain mChunkManagers.push_back(m); mTerrainRoot->setNodeMask(mTerrainRoot->getNodeMask() | m->getNodeMask()); if (m->getViewDistance()) - m->setMaxLodLevel(DefaultLodCallback::convertDistanceToLodLevel( - m->getViewDistance() + mViewDataMap->getReuseDistance(), mMinSize, mLodFactor)); + m->setMaxLodLevel( + DefaultLodCallback::convertDistanceToLodLevel(m->getViewDistance() + mViewDataMap->getReuseDistance(), + mMinSize, ESM::getCellSize(mWorldspace), mLodFactor)); } void QuadTreeWorld::rebuildViews()