2002-05-29 07:43:22 +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_SHADOWOCCLUDERVOLUME
|
|
|
|
#define OSG_SHADOWOCCLUDERVOLUME 1
|
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
2002-06-03 23:39:41 +08:00
|
|
|
#include <osg/Polytope>
|
2002-05-29 07:43:22 +08:00
|
|
|
#include <osg/ConvexPlanerOccluder>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** ShadowOccluderVolume is a helper class for implementating shadow occlusion culling. */
|
2002-06-03 23:39:41 +08:00
|
|
|
class SG_EXPORT ShadowOccluderVolume
|
2002-05-29 07:43:22 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
typedef std::vector<Polytope> HoleList;
|
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
ShadowOccluderVolume(const ShadowOccluderVolume& soc,Matrix& MVP);
|
|
|
|
|
|
|
|
ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP);
|
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
inline void pushCurrentMask();
|
|
|
|
inline void popCurrentMask();
|
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
/** Convert shadow occluder into local coords by multiplying the
|
|
|
|
* clip space occluder by the ModelViewProjectionMatrix.*/
|
|
|
|
void set(const ShadowOccluderVolume& soc,Matrix& MVP);
|
|
|
|
|
|
|
|
/** Initialize a ShadowOccluderVolume to a ConvexPlanerOccluder
|
|
|
|
* transformed into clipspace.*/
|
|
|
|
void set(const ConvexPlanerOccluder& occluder,Matrix& MVP);
|
|
|
|
|
|
|
|
/** return true if the specified bounding sphere is contaned entirely
|
|
|
|
* within this shadow occluder volume.*/
|
2002-06-03 23:39:41 +08:00
|
|
|
bool contains(const BoundingSphere& bound);
|
2002-05-29 07:43:22 +08:00
|
|
|
|
|
|
|
/** return true if the specified bounding box is contained entirely
|
|
|
|
* within this shadow occluder volume.*/
|
2002-06-03 23:39:41 +08:00
|
|
|
bool contains(const BoundingBox& bound);
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2002-06-04 01:49:28 +08:00
|
|
|
inline void transformProvidingInverse(const osg::Matrix& matrix)
|
|
|
|
{
|
|
|
|
_occluderVolume.transformProvidingInverse(matrix);
|
|
|
|
for(HoleList::iterator itr=_holeList.begin();
|
|
|
|
itr!=_holeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->transformProvidingInverse(matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
protected:
|
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
Polytope _occluderVolume;
|
|
|
|
HoleList _holeList;
|
2002-05-29 07:43:22 +08:00
|
|
|
};
|
|
|
|
|
2002-06-03 23:39:41 +08:00
|
|
|
inline void ShadowOccluderVolume::pushCurrentMask()
|
|
|
|
{
|
|
|
|
_occluderVolume.pushCurrentMask();
|
|
|
|
if (!_holeList.empty())
|
|
|
|
{
|
|
|
|
for(HoleList::iterator itr=_holeList.begin();
|
|
|
|
itr!=_holeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->pushCurrentMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ShadowOccluderVolume::popCurrentMask()
|
|
|
|
{
|
|
|
|
_occluderVolume.popCurrentMask();
|
|
|
|
if (!_holeList.empty())
|
|
|
|
{
|
|
|
|
for(HoleList::iterator itr=_holeList.begin();
|
|
|
|
itr!=_holeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->popCurrentMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-29 07:43:22 +08:00
|
|
|
} // end of namespace
|
|
|
|
|
|
|
|
#endif
|