Further work on Occlusion Culling. Most of work is complete, just debugging

required now.
This commit is contained in:
Robert Osfield
2002-06-13 16:21:00 +00:00
parent 8dcb26967c
commit 0ebe473eb5
13 changed files with 335 additions and 55 deletions

View File

@@ -30,10 +30,9 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
virtual void apply(osg::LOD& node);
virtual void apply(osg::OccluderNode& node);
typedef std::vector<ShadowVolumeOccluder> OccluderList;
OccluderList& getOccluderList() { return _occluderList; }
const OccluderList& getOccluderList() const { return _occluderList; }
void setCollectedOcculderList(const ShadowVolumeOccluderList& svol) { _occluderList = svol; }
ShadowVolumeOccluderList& getCollectedOccluderList() { return _occluderList; }
const ShadowVolumeOccluderList& getCollectedOccluderList() const { return _occluderList; }
protected:
@@ -44,7 +43,7 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
/** prevent unwanted copy operator.*/
CollectOccludersVisitor& operator = (const CollectOccludersVisitor&) { return *this; }
OccluderList _occluderList;
ShadowVolumeOccluderList _collectedOccluderList;
};

View File

@@ -44,6 +44,10 @@ class SG_EXPORT CullStack
CullingMode getCullingMode() const { return _cullingMode; }
void reset();
void setOccluderList(const ShadowVolumeOccluderList& svol) { _occluderList = svol; }
ShadowVolumeOccluderList& getOccluderList() { return _occluderList; }
const ShadowVolumeOccluderList& getOccluderList() const { return _occluderList; }
void pushViewport(osg::Viewport* viewport);
void popViewport();
@@ -110,6 +114,17 @@ class SG_EXPORT CullStack
}
typedef fast_back_stack<ref_ptr<CullingSet> > CullingStack;
CullingStack& getClipSpaceCullingStack() { return _clipspaceCullingStack; }
CullingStack& getProjectionCullingStack() { return _projectionCullingStack; }
CullingStack& getModelViewCullingStack() { return _modelviewCullingStack; }
CullingSet& getCurrentCullingSet() { return *_modelviewCullingStack.back(); }
inline osg::Viewport* getViewport();
inline osg::Matrix& getModelViewMatrix();
inline osg::Matrix& getProjectionMatrix();
@@ -139,6 +154,9 @@ class SG_EXPORT CullStack
float _LODBias;
float _smallFeatureCullingPixelSize;
// base set of shadow volume occluder to use in culling.
ShadowVolumeOccluderList _occluderList;
typedef fast_back_stack< ref_ptr<Matrix> > MatrixStack;
MatrixStack _projectionStack;
@@ -152,7 +170,6 @@ class SG_EXPORT CullStack
typedef fast_back_stack<Vec3> EyePointStack;
EyePointStack _eyePointStack;
typedef fast_back_stack<ref_ptr<CullingSet> > CullingStack;
CullingStack _clipspaceCullingStack;
CullingStack _projectionCullingStack;
CullingStack _modelviewCullingStack;

View File

@@ -77,22 +77,7 @@ class SG_EXPORT CullingSet : public Referenced
/** Compute the pixel of an bounding sphere.*/
float pixelSize(const BoundingSphere& bs) const { return bs.radius()/(bs.center()*_pixelSizeVector); }
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();
}
}
}
void disableOccluder(NodePath& nodePath);
inline bool isCulled(const std::vector<Vec3>& vertices)
{

View File

@@ -50,6 +50,13 @@ class SG_EXPORT Plane
_fv.set(norm[0],norm[1],norm[2],-(v1*norm));
calculateUpperLowerBBCorners();
}
/** flip/reverse the orientation of the plane.*/
inline void flip()
{
_fv = -_fv;
calculateUpperLowerBBCorners();
}
inline void makeUnitLength()

View File

@@ -70,6 +70,18 @@ class SG_EXPORT Polytope
inline void add(const osg::Plane& pl) { _planeList.push_back(pl); setupMask(); }
/** flip/reverse the orientation of all the planes.*/
inline void flip()
{
for(PlaneList::iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
itr->flip();
}
}
inline PlaneList& getPlaneList() { return _planeList; }
inline const PlaneList& getPlaneList() const { return _planeList; }

View File

@@ -12,6 +12,8 @@
namespace osg {
class CullStack;
/** ShadowVolumeOccluder is a helper class for implementating shadow occlusion culling. */
class SG_EXPORT ShadowVolumeOccluder
{
@@ -21,25 +23,35 @@ class SG_EXPORT ShadowVolumeOccluder
typedef std::vector<Polytope> HoleList;
ShadowVolumeOccluder(const ShadowVolumeOccluder& soc):
_quality(soc._quality),
_nodePath(soc._nodePath),
_occluderVolume(soc._occluderVolume),
_holeList(soc._holeList) {}
ShadowVolumeOccluder(const ShadowVolumeOccluder& svo):
_volume(svo._volume),
_nodePath(svo._nodePath),
_projectionMatrix(svo._projectionMatrix),
_occluderVolume(svo._occluderVolume),
_holeList(svo._holeList) {}
ShadowVolumeOccluder():
_volume(0.0f) {}
ShadowVolumeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,const Matrix& MV,const Matrix& P)
{
computeOccluder(nodePath,occluder,MV,P);
}
/** compute the shadow volume occluder. */
void computeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,const Matrix& MV,const Matrix& P);
bool computeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,CullStack& cullStack);
inline void disableResultMasks();
inline void pushCurrentMask();
inline void popCurrentMask();
/** return true if the matrix passed in matches the projection matrix that this ShaowVolumeOccluder is
* associated with.*/
bool matchProjectionMatrix(const osg::Matrix& matrix) const
{
if (_projectionMatrix.valid()) return matrix==*_projectionMatrix;
else return false;
}
/** Set the NodePath which describes the which node in the scene graph
* that this occluder was attached to.*/
@@ -47,7 +59,9 @@ class SG_EXPORT ShadowVolumeOccluder
inline NodePath& getNodePath() { return _nodePath; }
inline const NodePath& getNodePath() const { return _nodePath; }
float quality() { return _quality; }
float volume() { return _volume; }
/** return true if the specified vertex list is contaned entirely
* within this shadow occluder volume.*/
@@ -75,12 +89,18 @@ class SG_EXPORT ShadowVolumeOccluder
protected:
float _quality;
NodePath _nodePath;
Polytope _occluderVolume;
HoleList _holeList;
float _volume;
NodePath _nodePath;
ref_ptr<const Matrix> _projectionMatrix;
Polytope _occluderVolume;
HoleList _holeList;
};
/** A list of ShadowVolumeOccluder, used by CollectOccluderVisitor and CullVistor's.*/
typedef std::vector<ShadowVolumeOccluder> ShadowVolumeOccluderList;
inline void ShadowVolumeOccluder::disableResultMasks()
{
_occluderVolume.setResultMask(0);