Further work on moving culling functionality from CullVisitor into CullingSet,

in preperation for occlusion culling.
This commit is contained in:
Robert Osfield
2002-06-04 15:21:24 +00:00
parent 0732701e9d
commit f67be7c07f
6 changed files with 98 additions and 142 deletions

View File

@@ -19,12 +19,12 @@ class SG_EXPORT CullingSet : public Referenced
CullingSet();
CullingSet(const CullingSet& cs,const osg::Matrix& matrix):
CullingSet(const CullingSet& cs,const Matrix& matrix, const Vec4& pixelSizeVector):
_mask(cs._mask),
_clippingVolume(cs._clippingVolume),
_occluderList(cs._occluderList),
_pixelSizeOffset(cs._pixelSizeOffset),
_pixelSizeVector(cs._pixelSizeVector)
_pixelSizeVector(pixelSizeVector),
_smallFeatureCullingPixelSize(cs._smallFeatureCullingPixelSize)
{
_clippingVolume.transformProvidingInverse(matrix);
for(OccluderList::iterator itr=_occluderList.begin();
@@ -54,9 +54,29 @@ class SG_EXPORT CullingSet : public Referenced
void setFrustum(Polytope& cv) { _clippingVolume = cv; }
Polytope& getFrustum() { return _clippingVolume; }
const Polytope& getFrustum() const { return _clippingVolume; }
void addOccluder(ShadowOccluderVolume& cv) { _occluderList.push_back(cv); }
void setPixelSizeVector(const Vec4& v) { _pixelSizeVector = v; }
Vec4& getPixelSizeVector() { return _pixelSizeVector; }
const Vec4& getPixelSizeVector() const { return _pixelSizeVector; }
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
float& getSmallFeatureCullingPixelSize() { return _smallFeatureCullingPixelSize; }
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
/** Compute the pixel of an object at position v, with specified radius.*/
float pixelSize(const Vec3& v,float radius) const { return radius/(v*_pixelSizeVector); }
/** Compute the pixel of an bounding sphere.*/
float pixelSize(const BoundingSphere& bs) const { return bs.radius()/(bs.center()*_pixelSizeVector); }
inline bool isCulled(const BoundingBox& bb)
{
if (_mask&VIEW_FRUSTUM_CULLING)
@@ -96,7 +116,7 @@ class SG_EXPORT CullingSet : public Referenced
if (_mask&SMALL_FEATURE_CULLING)
{
if ((bs.center()*_pixelSizeVector+_pixelSizeOffset)>bs.radius()) return true;
if (((bs.center()*_pixelSizeVector)*_smallFeatureCullingPixelSize)>bs.radius()) return true;
}
if (_mask&SHADOW_OCCLUSION_CULLING)
@@ -149,14 +169,11 @@ class SG_EXPORT CullingSet : public Referenced
protected:
Mask _mask;
Polytope _clippingVolume;
OccluderList _occluderList;
float _pixelSizeOffset;
Vec3 _pixelSizeVector;
Mask _mask;
Polytope _clippingVolume;
OccluderList _occluderList;
Vec4 _pixelSizeVector;
float _smallFeatureCullingPixelSize;
};

View File

@@ -20,6 +20,10 @@ class SG_EXPORT ShadowOccluderVolume
typedef std::vector<Polytope> HoleList;
ShadowOccluderVolume(const ShadowOccluderVolume& soc):
_occluderVolume(soc._occluderVolume),
_holeList(soc._holeList) {}
ShadowOccluderVolume(const ShadowOccluderVolume& soc,Matrix& MVP);
ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP);

View File

@@ -217,6 +217,19 @@ class Vec4
}; // end of class Vec4
/** Compute the dot product of a (Vec3,1.0) and a Vec4.*/
inline float operator * (const Vec3& lhs,const Vec4& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
/** Compute the dot product of a Vec4 and a (Vec3,1.0).*/
inline float operator * (const Vec4& lhs,const Vec3& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
} // end of namespace osg
#endif

View File

@@ -232,64 +232,29 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
inline float pixelSize(const osg::Vec3& v, float const radius)
{
const osg::Matrix& mvpw = getMVPW();
if (_windowToModelFactorDirty)
{
_windowToModelFactorDirty=false;
_windowToModelFactor = osg::Vec3(mvpw(0,0),mvpw(1,0),mvpw(2,0)).length();
}
float W = v.x()*mvpw(0,3)+
v.y()*mvpw(1,3)+
v.z()*mvpw(2,3)+
mvpw(3,3);
return fabs(radius*_windowToModelFactor/W);
}
inline float pixelSize2(const osg::Vec3& v, float const radius)
{
const float R2 = osg::square(_viewportStack.back()->width()/osg::DegreesToRadians(38.0f))*1.15f;
//float p1 = fabs(radius*_windowToModelFactor/W);
return R2*radius*radius/(v-getEyeLocal()).length2();
return _modelviewCullingStack.back()->pixelSize(v,radius);
}
inline bool isCulled(const osg::Node& node)
{
if (node.isCullingActive())
{
const osg::BoundingSphere& sp = node.getBound();
if (!(_modelviewPolytopeStack.back().contains(sp))) return true;
// if (pixelSize(sp.center(),sp.radius())<_smallFeatureCullingPixelSize) return true;
if (pixelSize2(sp.center(),sp.radius())<osg::square(_smallFeatureCullingPixelSize)) return true;
}
return false;
return node.isCullingActive() && _modelviewCullingStack.back()->isCulled(node.getBound());
}
inline const bool isCulled(const osg::BoundingBox& bb)
{
if (!bb.isValid()) return true;
//return !_modelviewPolytopeStack.back().contains(bb,mode);
return !_modelviewPolytopeStack.back().contains(bb);
//return false;
return bb.isValid() && _modelviewCullingStack.back()->isCulled(bb);
}
inline void pushCurrentMask()
{
_modelviewPolytopeStack.back().pushCurrentMask();
_modelviewCullingStack.back()->pushCurrentMask();
}
inline void popCurrentMask()
{
_modelviewPolytopeStack.back().popCurrentMask();
_modelviewCullingStack.back()->popCurrentMask();
}
const CullingMode getCurrentCullingMode() const { return _cullingModeStack.back(); }
void updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable) { updateCalculatedNearFar(matrix,drawable.getBound()); }
void updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb);
void updateCalculatedNearFar(const osg::Vec3& pos);
@@ -352,33 +317,22 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
void popCullingSet();
// typedef std::vector<osg::Polytope> PolytopeStack;
// typedef std::vector<osg::ref_ptr<osg::Matrix> > MatrixStack;
typedef osg::fast_back_stack<osg::Polytope> PolytopeStack;
typedef osg::fast_back_stack< osg::ref_ptr<osg::Matrix> > MatrixStack;
MatrixStack _projectionStack;
MatrixStack _PW_Stack;
PolytopeStack _projectionPolytopeStack;
MatrixStack _modelviewStack;
MatrixStack _MVPW_Stack;
PolytopeStack _modelviewPolytopeStack;
bool _windowToModelFactorDirty;
float _windowToModelFactor;
// typedef std::vector<osg::ref_ptr<osg::Viewport> > ViewportStack;
typedef osg::fast_back_stack<osg::ref_ptr<osg::Viewport> > ViewportStack;
ViewportStack _viewportStack;
// typedef std::vector<osg::Vec3> EyePointStack;
typedef osg::fast_back_stack<osg::Vec3> EyePointStack;
EyePointStack _eyePointStack;
typedef osg::fast_back_stack<CullingMode> CullingModeStack;
CullingModeStack _cullingModeStack;
CullingMode _cullingMode;
typedef osg::fast_back_stack<osg::ref_ptr<osg::CullingSet> > CullingStack;
CullingStack _clipspaceCullingStack;