mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 09:15:38 +00:00
terrainclusterculling
This commit is contained in:
parent
2fa4aa9f3f
commit
480302d634
3 changed files with 41 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/ClusterCullingCallback>
|
||||
|
||||
#include <osgUtil/IncrementalCompileOperation>
|
||||
|
||||
|
@ -198,6 +199,8 @@ osg::ref_ptr<osg::Node> ChunkManager::createChunk(float chunkSize, const osg::Ve
|
|||
for (unsigned int i=0; i<numUvSets; ++i)
|
||||
geometry->setTexCoordArray(i, mBufferCache.getUVBuffer(numVerts));
|
||||
|
||||
geometry->createClusterCullingCallback();
|
||||
|
||||
if (useCompositeMap)
|
||||
{
|
||||
osg::ref_ptr<CompositeMap> compositeMap = new CompositeMap;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "terraindrawable.hpp"
|
||||
|
||||
#include <osg/ClusterCullingCallback>
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
#include <components/sceneutil/lightmanager.hpp>
|
||||
|
@ -36,6 +37,23 @@ inline float distance(const osg::Vec3& coord,const osg::Matrix& matrix)
|
|||
return -((float)coord[0]*(float)matrix(0,2)+(float)coord[1]*(float)matrix(1,2)+(float)coord[2]*(float)matrix(2,2)+matrix(3,2));
|
||||
}
|
||||
|
||||
//canot use ClusterCullingCallback::cull: viewpoint != eyepoint
|
||||
// !osgfixpotential!
|
||||
bool clusterCull(osg::ClusterCullingCallback* cb, const osg::Vec3f& eyePoint, bool shadowcam)
|
||||
{
|
||||
float _deviation = cb->getDeviation();
|
||||
const osg::Vec3& _controlPoint = cb->getControlPoint();
|
||||
osg::Vec3 _normal = cb->getNormal();
|
||||
if (shadowcam) _normal = _normal * -1; //inverting for shadowcam frontfaceculing
|
||||
float _radius = cb->getRadius();
|
||||
if (_deviation<=-1.0f) return false;
|
||||
osg::Vec3 eye_cp = eyePoint - _controlPoint;
|
||||
float radius = eye_cp.length();
|
||||
if (radius<_radius) return false;
|
||||
float deviation = (eye_cp * _normal)/radius;
|
||||
return deviation < _deviation;
|
||||
}
|
||||
|
||||
void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
||||
{
|
||||
const osg::BoundingBox& bb = getBoundingBox();
|
||||
|
@ -43,6 +61,11 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||
if (_cullingActive && cv->isCulled(getBoundingBox()))
|
||||
return;
|
||||
|
||||
bool shadowcam = cv->getCurrentCamera()->getName() == "ShadowCamera";
|
||||
|
||||
if (cv->getCullingMode() & osg::CullStack::CLUSTER_CULLING && clusterCull(mClusterCullingCallback, cv->getEyePoint(), shadowcam))
|
||||
return;
|
||||
|
||||
osg::RefMatrix& matrix = *cv->getModelViewMatrix();
|
||||
|
||||
if (cv->getComputeNearFarMode() && bb.valid())
|
||||
|
@ -55,7 +78,7 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||
if (osg::isNaN(depth))
|
||||
return;
|
||||
|
||||
if (cv->getCurrentCamera()->getName() == "ShadowCamera")
|
||||
if (shadowcam)
|
||||
{
|
||||
cv->addDrawableAndDepth(this, &matrix, depth);
|
||||
return;
|
||||
|
@ -80,6 +103,11 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||
cv->popStateSet();
|
||||
}
|
||||
|
||||
void TerrainDrawable::createClusterCullingCallback()
|
||||
{
|
||||
mClusterCullingCallback = new osg::ClusterCullingCallback(this);
|
||||
}
|
||||
|
||||
void TerrainDrawable::setPasses(const TerrainDrawable::PassVector &passes)
|
||||
{
|
||||
mPasses = passes;
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <osg/Geometry>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class ClusterCullingCallback;
|
||||
}
|
||||
|
||||
namespace osgUtil
|
||||
{
|
||||
class CullVisitor;
|
||||
|
@ -43,6 +48,8 @@ namespace Terrain
|
|||
|
||||
void setLightListCallback(SceneUtil::LightListCallback* lightListCallback);
|
||||
|
||||
void createClusterCullingCallback();
|
||||
|
||||
virtual void compileGLObjects(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
void setCompositeMap(CompositeMap* map) { mCompositeMap = map; }
|
||||
|
@ -51,6 +58,8 @@ namespace Terrain
|
|||
private:
|
||||
PassVector mPasses;
|
||||
|
||||
osg::ref_ptr<osg::ClusterCullingCallback> mClusterCullingCallback;
|
||||
|
||||
osg::ref_ptr<SceneUtil::LightListCallback> mLightListCallback;
|
||||
osg::ref_ptr<CompositeMap> mCompositeMap;
|
||||
osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer;
|
||||
|
|
Loading…
Reference in a new issue