2002-06-04 01:49:28 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
#ifndef OSG_CullingSet
|
|
|
|
#define OSG_CullingSet 1
|
|
|
|
|
|
|
|
#include <osg/Polytope>
|
|
|
|
#include <osg/ShadowOccluderVolume>
|
|
|
|
#include <osg/Referenced>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** A CullingSet class which contains a frustum and a list of occluder. */
|
|
|
|
class SG_EXPORT CullingSet : public Referenced
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
CullingSet();
|
2002-06-04 23:21:24 +08:00
|
|
|
CullingSet(const CullingSet& cs,const Matrix& matrix, const Vec4& pixelSizeVector):
|
2002-06-04 01:49:28 +08:00
|
|
|
_mask(cs._mask),
|
2002-06-10 19:21:21 +08:00
|
|
|
_frustum(cs._frustum),
|
2002-06-04 01:49:28 +08:00
|
|
|
_occluderList(cs._occluderList),
|
2002-06-04 23:21:24 +08:00
|
|
|
_pixelSizeVector(pixelSizeVector),
|
|
|
|
_smallFeatureCullingPixelSize(cs._smallFeatureCullingPixelSize)
|
2002-06-04 01:49:28 +08:00
|
|
|
{
|
2002-06-10 19:21:21 +08:00
|
|
|
_frustum.transformProvidingInverse(matrix);
|
2002-06-04 01:49:28 +08:00
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->transformProvidingInverse(matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~CullingSet();
|
|
|
|
|
2002-06-10 19:21:21 +08:00
|
|
|
typedef std::vector<ShadowVolumeOccluder> OccluderList;
|
2002-06-04 01:49:28 +08:00
|
|
|
|
|
|
|
typedef unsigned int Mask;
|
|
|
|
|
|
|
|
enum MaskValues
|
|
|
|
{
|
|
|
|
VIEW_FRUSTUM_CULLING = 0x1,
|
|
|
|
SMALL_FEATURE_CULLING = 0x2,
|
|
|
|
SHADOW_OCCLUSION_CULLING = 0x4,
|
|
|
|
ALL_CULLING = 0xffffffff
|
|
|
|
};
|
|
|
|
|
|
|
|
void setCullingMask(Mask mask) { _mask = mask; }
|
|
|
|
|
2002-06-10 19:21:21 +08:00
|
|
|
void setFrustum(Polytope& cv) { _frustum = cv; }
|
2002-06-04 01:49:28 +08:00
|
|
|
|
2002-06-10 19:21:21 +08:00
|
|
|
Polytope& getFrustum() { return _frustum; }
|
|
|
|
const Polytope& getFrustum() const { return _frustum; }
|
2002-06-04 01:49:28 +08:00
|
|
|
|
2002-06-10 19:21:21 +08:00
|
|
|
void addOccluder(ShadowVolumeOccluder& cv) { _occluderList.push_back(cv); }
|
2002-06-04 01:49:28 +08:00
|
|
|
|
2002-06-04 23:21:24 +08:00
|
|
|
|
|
|
|
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); }
|
|
|
|
|
2002-06-09 03:58:05 +08:00
|
|
|
inline void disableOccluder(NodePath& nodePath)
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->getNodePath()==nodePath)
|
|
|
|
{
|
|
|
|
// we have trapped for the case an occlude potentially occluding itself,
|
|
|
|
// to prevent this we disable the results mask so that no subsequnt
|
|
|
|
// when the next pushCurrentMask calls happens this occluder is switched off.
|
|
|
|
itr->disableResultMasks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-12 17:22:30 +08:00
|
|
|
inline bool isCulled(const std::vector<Vec3>& vertices)
|
|
|
|
{
|
|
|
|
if (_mask&VIEW_FRUSTUM_CULLING)
|
|
|
|
{
|
|
|
|
// is it outside the view frustum...
|
|
|
|
if (!_frustum.contains(vertices)) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SMALL_FEATURE_CULLING)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SHADOW_OCCLUSION_CULLING)
|
|
|
|
{
|
|
|
|
// is it in one of the shadow occluder volumes.
|
|
|
|
if (!_occluderList.empty())
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->contains(vertices)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-04 01:49:28 +08:00
|
|
|
inline bool isCulled(const BoundingBox& bb)
|
|
|
|
{
|
|
|
|
if (_mask&VIEW_FRUSTUM_CULLING)
|
|
|
|
{
|
|
|
|
// is it outside the view frustum...
|
2002-06-10 19:21:21 +08:00
|
|
|
if (!_frustum.contains(bb)) return true;
|
2002-06-04 01:49:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SMALL_FEATURE_CULLING)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SHADOW_OCCLUSION_CULLING)
|
|
|
|
{
|
|
|
|
// is it in one of the shadow occluder volumes.
|
|
|
|
if (!_occluderList.empty())
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->contains(bb)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isCulled(const BoundingSphere& bs)
|
|
|
|
{
|
|
|
|
if (_mask&VIEW_FRUSTUM_CULLING)
|
|
|
|
{
|
|
|
|
// is it outside the view frustum...
|
2002-06-10 19:21:21 +08:00
|
|
|
if (!_frustum.contains(bs)) return true;
|
2002-06-04 01:49:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SMALL_FEATURE_CULLING)
|
|
|
|
{
|
2002-06-04 23:21:24 +08:00
|
|
|
if (((bs.center()*_pixelSizeVector)*_smallFeatureCullingPixelSize)>bs.radius()) return true;
|
2002-06-04 01:49:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_mask&SHADOW_OCCLUSION_CULLING)
|
|
|
|
{
|
|
|
|
// is it in one of the shadow occluder volumes.
|
|
|
|
if (!_occluderList.empty())
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->contains(bs)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void pushCurrentMask()
|
|
|
|
{
|
2002-06-10 19:21:21 +08:00
|
|
|
_frustum.pushCurrentMask();
|
2002-06-04 01:49:28 +08:00
|
|
|
|
|
|
|
if (!_occluderList.empty())
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->pushCurrentMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void popCurrentMask()
|
|
|
|
{
|
2002-06-10 19:21:21 +08:00
|
|
|
_frustum.popCurrentMask();
|
2002-06-04 01:49:28 +08:00
|
|
|
|
|
|
|
if (!_occluderList.empty())
|
|
|
|
{
|
|
|
|
for(OccluderList::iterator itr=_occluderList.begin();
|
|
|
|
itr!=_occluderList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->popCurrentMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2002-06-04 23:21:24 +08:00
|
|
|
Mask _mask;
|
2002-06-10 19:21:21 +08:00
|
|
|
Polytope _frustum;
|
2002-06-04 23:21:24 +08:00
|
|
|
OccluderList _occluderList;
|
|
|
|
Vec4 _pixelSizeVector;
|
|
|
|
float _smallFeatureCullingPixelSize;
|
2002-06-04 01:49:28 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace
|
|
|
|
|
|
|
|
#endif
|