fixes stutters => bugs in the way cells were updated.

macos_ci
florent.teppe 2 years ago
parent 0e4d21a40c
commit a9e0489867

@ -1363,6 +1363,9 @@ namespace MWRender
mTerrainStorage.get(), Mask_Terrain, worldspace, Mask_PreCompile, Mask_Debug); mTerrainStorage.get(), Mask_Terrain, worldspace, Mask_PreCompile, Mask_Debug);
newTerrain->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells")); 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); mWorldspaceTerrains[worldspace] = std::move(newTerrain);
return mWorldspaceTerrains[worldspace].get(); return mWorldspaceTerrains[worldspace].get();
} }

@ -39,13 +39,14 @@ namespace Terrain
class DefaultLodCallback : public LodCallback class DefaultLodCallback : public LodCallback
{ {
public: public:
DefaultLodCallback( DefaultLodCallback(float factor, float minSize, float viewDistance, const osg::Vec4i& grid, int cellSizeInUnits,
float factor, float minSize, float viewDistance, const osg::Vec4i& grid, float distanceModifier = 0.f) float distanceModifier = 0.f)
: mFactor(factor) : mFactor(factor)
, mMinSize(minSize) , mMinSize(minSize)
, mViewDistance(viewDistance) , mViewDistance(viewDistance)
, mActiveGrid(grid) , mActiveGrid(grid)
, mDistanceModifier(distanceModifier) , mDistanceModifier(distanceModifier)
, mCellSizeInUnits(cellSizeInUnits)
{ {
} }
@ -69,7 +70,8 @@ namespace Terrain
dist = std::max(0.f, dist + mDistanceModifier); dist = std::max(0.f, dist + mDistanceModifier);
if (dist > mViewDistance && !activeGrid) // for Scene<->ObjectPaging sync the activegrid must remain loaded if (dist > mViewDistance && !activeGrid) // for Scene<->ObjectPaging sync the activegrid must remain loaded
return StopTraversal; return StopTraversal;
return getNativeLodLevel(node, mMinSize) <= convertDistanceToLodLevel(dist, mMinSize, mFactor) return getNativeLodLevel(node, mMinSize)
<= convertDistanceToLodLevel(dist, mMinSize, mFactor, mCellSizeInUnits)
? StopTraversalAndUse ? StopTraversalAndUse
: Deeper; : Deeper;
} }
@ -77,9 +79,9 @@ namespace Terrain
{ {
return Log2(static_cast<unsigned int>(node->getSize() / minSize)); return Log2(static_cast<unsigned int>(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<unsigned int>(dist / (Constants::CellSizeInUnits * minSize * factor))); return Log2(static_cast<unsigned int>(dist / (cellSize * minSize * factor)));
} }
private: private:
@ -88,6 +90,7 @@ namespace Terrain
float mViewDistance; float mViewDistance;
osg::Vec4i mActiveGrid; osg::Vec4i mActiveGrid;
float mDistanceModifier; float mDistanceModifier;
int mCellSizeInUnits;
}; };
class RootNode : public QuadTreeNode class RootNode : public QuadTreeNode
@ -471,7 +474,8 @@ namespace Terrain
if (needsUpdate) if (needsUpdate)
{ {
vd->reset(); vd->reset();
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, mActiveGrid); DefaultLodCallback lodCallback(
mLodFactor, mMinSize, mViewDistance, mActiveGrid, ESM::getCellSize(mWorldspace));
mRootNode->traverseNodes(vd, viewPoint, &lodCallback); mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
} }
@ -549,7 +553,7 @@ namespace Terrain
distanceModifier = 1024; distanceModifier = 1024;
else if (pass == 2) else if (pass == 2)
distanceModifier = -1024; distanceModifier = -1024;
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, distanceModifier); DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, cellWorldSize, distanceModifier);
mRootNode->traverseNodes(vd, viewPoint, &lodCallback); mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
if (pass == 0) if (pass == 0)
@ -605,8 +609,9 @@ namespace Terrain
mChunkManagers.push_back(m); mChunkManagers.push_back(m);
mTerrainRoot->setNodeMask(mTerrainRoot->getNodeMask() | m->getNodeMask()); mTerrainRoot->setNodeMask(mTerrainRoot->getNodeMask() | m->getNodeMask());
if (m->getViewDistance()) if (m->getViewDistance())
m->setMaxLodLevel(DefaultLodCallback::convertDistanceToLodLevel( m->setMaxLodLevel(
m->getViewDistance() + mViewDataMap->getReuseDistance(), mMinSize, mLodFactor)); DefaultLodCallback::convertDistanceToLodLevel(m->getViewDistance() + mViewDataMap->getReuseDistance(),
mMinSize, ESM::getCellSize(mWorldspace), mLodFactor));
} }
void QuadTreeWorld::rebuildViews() void QuadTreeWorld::rebuildViews()

Loading…
Cancel
Save