1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 12:53:54 +00:00

Compute instance matrices once

This commit is contained in:
AnyOldName3 2023-04-30 00:41:09 +01:00
parent f2fa607f41
commit f0fcb5e5df

View file

@ -47,9 +47,11 @@ namespace MWRender
public: public:
InstancedComputeNearFarCullCallback( InstancedComputeNearFarCullCallback(
const std::vector<Groundcover::GroundcoverEntry>& instances, const osg::Vec3& chunkPosition) const std::vector<Groundcover::GroundcoverEntry>& instances, const osg::Vec3& chunkPosition)
: mInstances(instances) : mInstanceMatrices()
, mChunkPosition(chunkPosition)
{ {
mInstanceMatrices.reserve(instances.size());
for (const auto& instance : instances)
mInstanceMatrices.emplace_back(computeInstanceMatrix(instance, chunkPosition));
} }
bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const override bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const override
@ -100,9 +102,8 @@ namespace MWRender
if (dNear < computedZNear) if (dNear < computedZNear)
{ {
dNear = std::numeric_limits<value_type>::max(); dNear = std::numeric_limits<value_type>::max();
for (const auto& entry : mInstances) for (const auto& instanceMatrix : mInstanceMatrices)
{ {
osg::Matrix instanceMatrix = computeInstanceMatrix(entry, mChunkPosition);
value_type newNear = cullVisitor.computeNearestPointInFrustum( value_type newNear = cullVisitor.computeNearestPointInFrustum(
instanceMatrix * matrix, planes, *drawable); instanceMatrix * matrix, planes, *drawable);
dNear = std::min(dNear, newNear); dNear = std::min(dNear, newNear);
@ -114,9 +115,8 @@ namespace MWRender
if (cnfMode == osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES && dFar > computedZFar) if (cnfMode == osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES && dFar > computedZFar)
{ {
dFar = -std::numeric_limits<value_type>::max(); dFar = -std::numeric_limits<value_type>::max();
for (const auto& entry : mInstances) for (const auto& instanceMatrix : mInstanceMatrices)
{ {
osg::Matrix instanceMatrix = computeInstanceMatrix(entry, mChunkPosition);
value_type newFar = cullVisitor.computeFurthestPointInFrustum( value_type newFar = cullVisitor.computeFurthestPointInFrustum(
instanceMatrix * matrix, planes, *drawable); instanceMatrix * matrix, planes, *drawable);
dFar = std::max(dFar, newFar); dFar = std::max(dFar, newFar);
@ -131,8 +131,7 @@ namespace MWRender
} }
private: private:
std::vector<Groundcover::GroundcoverEntry> mInstances; std::vector<osg::Matrix> mInstanceMatrices;
osg::Vec3 mChunkPosition;
}; };
class InstancingVisitor : public osg::NodeVisitor class InstancingVisitor : public osg::NodeVisitor