mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
improves groundcover view distance (#3219)
This PR aims to solve all issues with `Groundcover` view distance handling in a satisfying way while preserving other optimisations that benefit other features. The main idea here is not to rely on `ViewData` updates for distance culling calculations because we can not accurately determine distance against lazily updated views. Instead, we perform an accurate measurement in a cull callback we can run every frame in `Groundcover` itself. While we do have to add some code to handle this feature, it is quite loosely coupled code that could be useful elsewhere in the future. These changes should address a performance regression @akortunov experienced.
This commit is contained in:
parent
b6718ecb10
commit
5f1bf89369
11 changed files with 98 additions and 65 deletions
|
@ -10,6 +10,29 @@
|
|||
namespace Terrain
|
||||
{
|
||||
|
||||
float distance(const osg::BoundingBox& box, const osg::Vec3f& v)
|
||||
{
|
||||
if (box.contains(v))
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
osg::Vec3f maxDist(0,0,0);
|
||||
if (v.x() < box.xMin())
|
||||
maxDist.x() = box.xMin() - v.x();
|
||||
else if (v.x() > box.xMax())
|
||||
maxDist.x() = v.x() - box.xMax();
|
||||
if (v.y() < box.yMin())
|
||||
maxDist.y() = box.yMin() - v.y();
|
||||
else if (v.y() > box.yMax())
|
||||
maxDist.y() = v.y() - box.yMax();
|
||||
if (v.z() < box.zMin())
|
||||
maxDist.z() = box.zMin() - v.z();
|
||||
else if (v.z() > box.zMax())
|
||||
maxDist.z() = v.z() - box.zMax();
|
||||
return maxDist.length();
|
||||
}
|
||||
}
|
||||
|
||||
ChildDirection reflect(ChildDirection dir, Direction dir2)
|
||||
{
|
||||
assert(dir != Root);
|
||||
|
@ -78,25 +101,7 @@ QuadTreeNode *QuadTreeNode::getNeighbour(Direction dir)
|
|||
float QuadTreeNode::distance(const osg::Vec3f& v) const
|
||||
{
|
||||
const osg::BoundingBox& box = getBoundingBox();
|
||||
if (box.contains(v))
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
osg::Vec3f maxDist(0,0,0);
|
||||
if (v.x() < box.xMin())
|
||||
maxDist.x() = box.xMin() - v.x();
|
||||
else if (v.x() > box.xMax())
|
||||
maxDist.x() = v.x() - box.xMax();
|
||||
if (v.y() < box.yMin())
|
||||
maxDist.y() = box.yMin() - v.y();
|
||||
else if (v.y() > box.yMax())
|
||||
maxDist.y() = v.y() - box.yMax();
|
||||
if (v.z() < box.zMin())
|
||||
maxDist.z() = box.zMin() - v.z();
|
||||
else if (v.z() > box.zMax())
|
||||
maxDist.z() = v.z() - box.zMax();
|
||||
return maxDist.length();
|
||||
}
|
||||
return Terrain::distance(box, v);
|
||||
}
|
||||
|
||||
void QuadTreeNode::initNeighbours()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue