ShadowVolumeOccluder
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SHADOWVOLUMEOCCLUDER
#define OSG_SHADOWVOLUMEOCCLUDER 1
#include <osg/Polytope>
#include <osg/ConvexPlanarOccluder>
#include <osg/Node>
namespace osg {
class CullStack;
class OSG_EXPORT ShadowVolumeOccluder
{
public:
typedef std::vector<Polytope> HoleList;
ShadowVolumeOccluder(const ShadowVolumeOccluder& svo):
_volume(svo._volume),
_nodePath(svo._nodePath),
_projectionMatrix(svo._projectionMatrix),
_occluderVolume(svo._occluderVolume),
_holeList(svo._holeList) {}
ShadowVolumeOccluder():
_volume(0.0f) {}
bool operator < (const ShadowVolumeOccluder& svo) const { return getVolume()>svo.getVolume(); } // not greater volume first.
bool computeOccluder(const NodePath& nodePath,const ConvexPlanarOccluder& occluder,CullStack& cullStack,bool createDrawables=false);
inline void disableResultMasks();
inline void pushCurrentMask();
inline void popCurrentMask();
bool matchProjectionMatrix(const osg::Matrix& matrix) const
{
if (_projectionMatrix.valid()) return matrix==*_projectionMatrix;
else return false;
}
inline void setNodePath(NodePath& nodePath) { _nodePath = nodePath; }
inline NodePath& getNodePath() { return _nodePath; }
inline const NodePath& getNodePath() const { return _nodePath; }
float getVolume() const { return _volume; }
Polytope& getOccluder() { return _occluderVolume; }
const Polytope& getOccluder() const { return _occluderVolume; }
HoleList& getHoleList() { return _holeList; }
const HoleList& getHoleList() const { return _holeList; }
bool contains(const std::vector<Vec3>& vertices);
bool contains(const BoundingSphere& bound);
bool contains(const BoundingBox& bound);
inline void transformProvidingInverse(const osg::Matrix& matrix)
{
_occluderVolume.transformProvidingInverse(matrix);
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->transformProvidingInverse(matrix);
}
}
protected:
float _volume;
NodePath _nodePath;
ref_ptr<const RefMatrix> _projectionMatrix;
Polytope _occluderVolume;
HoleList _holeList;
};
typedef std::vector<ShadowVolumeOccluder> ShadowVolumeOccluderList;
inline void ShadowVolumeOccluder::disableResultMasks()
{
//std::cout<<"ShadowVolumeOccluder::disableResultMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
_occluderVolume.setResultMask(0);
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->setResultMask(0);
}
}
inline void ShadowVolumeOccluder::pushCurrentMask()
{
//std::cout<<"ShadowVolumeOccluder::pushCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
_occluderVolume.pushCurrentMask();
if (!_holeList.empty())
{
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->pushCurrentMask();
}
}
}
inline void ShadowVolumeOccluder::popCurrentMask()
{
_occluderVolume.popCurrentMask();
if (!_holeList.empty())
{
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->popCurrentMask();
}
}
//std::cout<<"ShadowVolumeOccluder::popCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
}
} // end of namespace
#endif
ConvexPlanarOccluder
Node
Polytope
osg::ConvexPlanarOccluder
Definition ConvexPlanarOccluder:26
osg::CullStack
Definition CullStack:28
osg::Polytope
Definition Polytope:26
osg::ShadowVolumeOccluder::getOccluder
const Polytope & getOccluder() const
Definition ShadowVolumeOccluder:81
osg::ShadowVolumeOccluder::_nodePath
NodePath _nodePath
Definition ShadowVolumeOccluder:117
osg::ShadowVolumeOccluder::computeOccluder
bool computeOccluder(const NodePath &nodePath, const ConvexPlanarOccluder &occluder, CullStack &cullStack, bool createDrawables=false)
osg::ShadowVolumeOccluder::popCurrentMask
void popCurrentMask()
Definition ShadowVolumeOccluder:155
osg::ShadowVolumeOccluder::_volume
float _volume
Definition ShadowVolumeOccluder:116
osg::ShadowVolumeOccluder::_occluderVolume
Polytope _occluderVolume
Definition ShadowVolumeOccluder:119
osg::ShadowVolumeOccluder::getHoleList
const HoleList & getHoleList() const
Definition ShadowVolumeOccluder:87
osg::ShadowVolumeOccluder::getNodePath
const NodePath & getNodePath() const
Definition ShadowVolumeOccluder:70
osg::ShadowVolumeOccluder::getOccluder
Polytope & getOccluder()
Definition ShadowVolumeOccluder:78
osg::ShadowVolumeOccluder::HoleList
std::vector< Polytope > HoleList
Definition ShadowVolumeOccluder:32
osg::ShadowVolumeOccluder::pushCurrentMask
void pushCurrentMask()
Definition ShadowVolumeOccluder:140
osg::ShadowVolumeOccluder::setNodePath
void setNodePath(NodePath &nodePath)
Definition ShadowVolumeOccluder:68
osg::ShadowVolumeOccluder::matchProjectionMatrix
bool matchProjectionMatrix(const osg::Matrix &matrix) const
Definition ShadowVolumeOccluder:59
osg::ShadowVolumeOccluder::disableResultMasks
void disableResultMasks()
Definition ShadowVolumeOccluder:128
osg::ShadowVolumeOccluder::transformProvidingInverse
void transformProvidingInverse(const osg::Matrix &matrix)
Definition ShadowVolumeOccluder:102
osg::ShadowVolumeOccluder::_projectionMatrix
ref_ptr< const RefMatrix > _projectionMatrix
Definition ShadowVolumeOccluder:118
osg::ShadowVolumeOccluder::getHoleList
HoleList & getHoleList()
Definition ShadowVolumeOccluder:84
osg::ShadowVolumeOccluder::ShadowVolumeOccluder
ShadowVolumeOccluder()
Definition ShadowVolumeOccluder:41
osg::ShadowVolumeOccluder::_holeList
HoleList _holeList
Definition ShadowVolumeOccluder:120
osg::ShadowVolumeOccluder::ShadowVolumeOccluder
ShadowVolumeOccluder(const ShadowVolumeOccluder &svo)
Definition ShadowVolumeOccluder:34
osg::ShadowVolumeOccluder::contains
bool contains(const std::vector< Vec3 > &vertices)
osg::ShadowVolumeOccluder::getVolume
float getVolume() const
Definition ShadowVolumeOccluder:75
osg::ShadowVolumeOccluder::contains
bool contains(const BoundingSphere &bound)
osg::ShadowVolumeOccluder::contains
bool contains(const BoundingBox &bound)
osg::ShadowVolumeOccluder::getNodePath
NodePath & getNodePath()
Definition ShadowVolumeOccluder:69
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::NodePath
std::vector< Node * > NodePath
Definition Node:47
osg::ShadowVolumeOccluderList
std::vector< ShadowVolumeOccluder > ShadowVolumeOccluderList
Definition ShadowVolumeOccluder:125
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39