2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
#ifndef OSG_COLLECTOCCLUDERSVISITOR
|
|
|
|
#define OSG_COLLECTOCCLUDERSVISITOR 1
|
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/CullStack>
|
|
|
|
|
2002-06-19 06:35:48 +08:00
|
|
|
#include <set>
|
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
namespace osg {
|
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::CullStack
|
2002-06-10 21:50:25 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2002-06-19 06:35:48 +08:00
|
|
|
typedef std::set<ShadowVolumeOccluder> ShadowVolumeOccluderSet;
|
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
CollectOccludersVisitor();
|
|
|
|
virtual ~CollectOccludersVisitor();
|
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual CollectOccludersVisitor* cloneType() const { return new CollectOccludersVisitor(); }
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
2002-11-12 18:22:38 +08:00
|
|
|
virtual float getDistanceToEyePoint(const Vec3& pos, bool withLODScale) const;
|
|
|
|
virtual float getDistanceFromEyePoint(const Vec3& pos, bool withLODScale) const;
|
2002-10-07 04:33:13 +08:00
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
virtual void apply(osg::Node&);
|
|
|
|
virtual void apply(osg::Transform& node);
|
|
|
|
virtual void apply(osg::Projection& node);
|
|
|
|
|
|
|
|
virtual void apply(osg::Switch& node);
|
|
|
|
virtual void apply(osg::LOD& node);
|
|
|
|
virtual void apply(osg::OccluderNode& node);
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** Sets the minimum shadow occluder volume that an active occluder
|
2005-11-18 01:44:48 +08:00
|
|
|
* must have. vol is units relative the clip space volume where 1.0
|
|
|
|
* is the whole clip space. */
|
2002-06-15 20:14:42 +08:00
|
|
|
void setMinimumShadowOccluderVolume(float vol) { _minimumShadowOccluderVolume = vol; }
|
|
|
|
float getMinimumShadowOccluderVolume() const { return _minimumShadowOccluderVolume; }
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** Sets the maximum number of occluders to have active for culling
|
2005-11-18 01:44:48 +08:00
|
|
|
* purposes. */
|
2003-12-12 00:46:45 +08:00
|
|
|
void setMaximumNumberOfActiveOccluders(unsigned int num) { _maximumNumberOfActiveOccluders = num; }
|
|
|
|
unsigned int getMaximumNumberOfActiveOccluders() const { return _maximumNumberOfActiveOccluders; }
|
|
|
|
|
2002-06-14 07:46:02 +08:00
|
|
|
void setCreateDrawablesOnOccludeNodes(bool flag) { _createDrawables=flag; }
|
|
|
|
bool getCreateDrawablesOnOccludeNodes() const { return _createDrawables; }
|
|
|
|
|
2004-12-13 09:07:24 +08:00
|
|
|
void setCollectedOcculderSet(const ShadowVolumeOccluderSet& svol) { _occluderSet = svol; }
|
2002-06-19 06:35:48 +08:00
|
|
|
ShadowVolumeOccluderSet& getCollectedOccluderSet() { return _occluderSet; }
|
|
|
|
const ShadowVolumeOccluderSet& getCollectedOccluderSet() const { return _occluderSet; }
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** Removes occluded occluders for the collected occluders list, then
|
2005-11-18 01:44:48 +08:00
|
|
|
* discards all but MaximumNumberOfActiveOccluders of occluders,
|
2004-09-07 18:07:11 +08:00
|
|
|
* discarding the occluders with the lowests shadow occluder volume. */
|
2002-06-19 06:35:48 +08:00
|
|
|
void removeOccludedOccluders();
|
2002-06-10 21:50:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** Prevents unwanted copy construction. */
|
2003-06-24 23:40:09 +08:00
|
|
|
//CollectOccludersVisitor(const CollectOccludersVisitor&):osg::NodeVisitor(),osg::CullStack() {}
|
2002-06-10 21:50:25 +08:00
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** Prevents unwanted copy operator. */
|
2002-06-10 21:50:25 +08:00
|
|
|
CollectOccludersVisitor& operator = (const CollectOccludersVisitor&) { return *this; }
|
|
|
|
|
2002-06-14 21:49:59 +08:00
|
|
|
inline void handle_cull_callbacks_and_traverse(osg::Node& node)
|
|
|
|
{
|
|
|
|
/*osg::NodeCallback* callback = node.getCullCallback();
|
|
|
|
if (callback) (*callback)(&node,this);
|
|
|
|
else*/ if (node.getNumChildrenWithOccluderNodes()>0) traverse(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
|
|
|
|
{
|
|
|
|
/*osg::NodeCallback* callback = node.getCullCallback();
|
|
|
|
if (callback) (*callback)(&node,this);
|
|
|
|
else*/ if (node.getNumChildrenWithOccluderNodes()>0) acceptNode->accept(*this);
|
|
|
|
}
|
2002-06-15 20:14:42 +08:00
|
|
|
|
|
|
|
float _minimumShadowOccluderVolume;
|
2003-12-12 00:46:45 +08:00
|
|
|
unsigned _maximumNumberOfActiveOccluders;
|
2002-06-15 20:14:42 +08:00
|
|
|
bool _createDrawables;
|
2002-06-19 06:35:48 +08:00
|
|
|
ShadowVolumeOccluderSet _occluderSet;
|
2002-06-15 20:14:42 +08:00
|
|
|
|
2002-06-10 21:50:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|