mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-25 03:40:40 +00:00
Merge branch '13' into 'master'
terrainshadowclusterculling See merge request OpenMW/openmw!141
This commit is contained in:
commit
a4d1068d1a
@ -3,6 +3,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <osg/Texture2D>
|
#include <osg/Texture2D>
|
||||||
|
#include <osg/ClusterCullingCallback>
|
||||||
|
|
||||||
#include <osgUtil/IncrementalCompileOperation>
|
#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)
|
for (unsigned int i=0; i<numUvSets; ++i)
|
||||||
geometry->setTexCoordArray(i, mBufferCache.getUVBuffer(numVerts));
|
geometry->setTexCoordArray(i, mBufferCache.getUVBuffer(numVerts));
|
||||||
|
|
||||||
|
geometry->createClusterCullingCallback();
|
||||||
|
|
||||||
if (useCompositeMap)
|
if (useCompositeMap)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<CompositeMap> compositeMap = new CompositeMap;
|
osg::ref_ptr<CompositeMap> compositeMap = new CompositeMap;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "terraindrawable.hpp"
|
#include "terraindrawable.hpp"
|
||||||
|
|
||||||
|
#include <osg/ClusterCullingCallback>
|
||||||
#include <osgUtil/CullVisitor>
|
#include <osgUtil/CullVisitor>
|
||||||
|
|
||||||
#include <components/sceneutil/lightmanager.hpp>
|
#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));
|
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)
|
void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
||||||
{
|
{
|
||||||
const osg::BoundingBox& bb = getBoundingBox();
|
const osg::BoundingBox& bb = getBoundingBox();
|
||||||
@ -43,6 +61,11 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||||||
if (_cullingActive && cv->isCulled(getBoundingBox()))
|
if (_cullingActive && cv->isCulled(getBoundingBox()))
|
||||||
return;
|
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();
|
osg::RefMatrix& matrix = *cv->getModelViewMatrix();
|
||||||
|
|
||||||
if (cv->getComputeNearFarMode() && bb.valid())
|
if (cv->getComputeNearFarMode() && bb.valid())
|
||||||
@ -55,7 +78,7 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||||||
if (osg::isNaN(depth))
|
if (osg::isNaN(depth))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cv->getCurrentCamera()->getName() == "ShadowCamera")
|
if (shadowcam)
|
||||||
{
|
{
|
||||||
cv->addDrawableAndDepth(this, &matrix, depth);
|
cv->addDrawableAndDepth(this, &matrix, depth);
|
||||||
return;
|
return;
|
||||||
@ -80,6 +103,11 @@ void TerrainDrawable::cull(osgUtil::CullVisitor *cv)
|
|||||||
cv->popStateSet();
|
cv->popStateSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerrainDrawable::createClusterCullingCallback()
|
||||||
|
{
|
||||||
|
mClusterCullingCallback = new osg::ClusterCullingCallback(this);
|
||||||
|
}
|
||||||
|
|
||||||
void TerrainDrawable::setPasses(const TerrainDrawable::PassVector &passes)
|
void TerrainDrawable::setPasses(const TerrainDrawable::PassVector &passes)
|
||||||
{
|
{
|
||||||
mPasses = passes;
|
mPasses = passes;
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
|
|
||||||
|
namespace osg
|
||||||
|
{
|
||||||
|
class ClusterCullingCallback;
|
||||||
|
}
|
||||||
|
|
||||||
namespace osgUtil
|
namespace osgUtil
|
||||||
{
|
{
|
||||||
class CullVisitor;
|
class CullVisitor;
|
||||||
@ -43,6 +48,8 @@ namespace Terrain
|
|||||||
|
|
||||||
void setLightListCallback(SceneUtil::LightListCallback* lightListCallback);
|
void setLightListCallback(SceneUtil::LightListCallback* lightListCallback);
|
||||||
|
|
||||||
|
void createClusterCullingCallback();
|
||||||
|
|
||||||
virtual void compileGLObjects(osg::RenderInfo& renderInfo) const;
|
virtual void compileGLObjects(osg::RenderInfo& renderInfo) const;
|
||||||
|
|
||||||
void setCompositeMap(CompositeMap* map) { mCompositeMap = map; }
|
void setCompositeMap(CompositeMap* map) { mCompositeMap = map; }
|
||||||
@ -51,6 +58,8 @@ namespace Terrain
|
|||||||
private:
|
private:
|
||||||
PassVector mPasses;
|
PassVector mPasses;
|
||||||
|
|
||||||
|
osg::ref_ptr<osg::ClusterCullingCallback> mClusterCullingCallback;
|
||||||
|
|
||||||
osg::ref_ptr<SceneUtil::LightListCallback> mLightListCallback;
|
osg::ref_ptr<SceneUtil::LightListCallback> mLightListCallback;
|
||||||
osg::ref_ptr<CompositeMap> mCompositeMap;
|
osg::ref_ptr<CompositeMap> mCompositeMap;
|
||||||
osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer;
|
osg::ref_ptr<CompositeMapRenderer> mCompositeMapRenderer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user