openscenegraph
ShadowVolumeOccluder
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_SHADOWVOLUMEOCCLUDER
15#define OSG_SHADOWVOLUMEOCCLUDER 1
16
17#include <osg/Polytope>
19#include <osg/Node>
20
21namespace osg {
22
23class CullStack;
24
27{
28
29 public:
30
31
32 typedef std::vector<Polytope> HoleList;
33
35 _volume(svo._volume),
36 _nodePath(svo._nodePath),
37 _projectionMatrix(svo._projectionMatrix),
38 _occluderVolume(svo._occluderVolume),
39 _holeList(svo._holeList) {}
40
42 _volume(0.0f) {}
43
44
45 bool operator < (const ShadowVolumeOccluder& svo) const { return getVolume()>svo.getVolume(); } // not greater volume first.
46
48 bool computeOccluder(const NodePath& nodePath,const ConvexPlanarOccluder& occluder,CullStack& cullStack,bool createDrawables=false);
49
50
51 inline void disableResultMasks();
52
53 inline void pushCurrentMask();
54 inline void popCurrentMask();
55
56
59 bool matchProjectionMatrix(const osg::Matrix& matrix) const
60 {
61 if (_projectionMatrix.valid()) return matrix==*_projectionMatrix;
62 else return false;
63 }
64
65
68 inline void setNodePath(NodePath& nodePath) { _nodePath = nodePath; }
69 inline NodePath& getNodePath() { return _nodePath; }
70 inline const NodePath& getNodePath() const { return _nodePath; }
71
72
75 float getVolume() const { return _volume; }
76
78 Polytope& getOccluder() { return _occluderVolume; }
79
81 const Polytope& getOccluder() const { return _occluderVolume; }
82
84 HoleList& getHoleList() { return _holeList; }
85
87 const HoleList& getHoleList() const { return _holeList; }
88
89
92 bool contains(const std::vector<Vec3>& vertices);
93
96 bool contains(const BoundingSphere& bound);
97
100 bool contains(const BoundingBox& bound);
101
102 inline void transformProvidingInverse(const osg::Matrix& matrix)
103 {
104 _occluderVolume.transformProvidingInverse(matrix);
105 for(HoleList::iterator itr=_holeList.begin();
106 itr!=_holeList.end();
107 ++itr)
108 {
109 itr->transformProvidingInverse(matrix);
110 }
111 }
112
113
114 protected:
115
116 float _volume;
121};
122
123
125typedef std::vector<ShadowVolumeOccluder> ShadowVolumeOccluderList;
126
127
129{
130 //std::cout<<"ShadowVolumeOccluder::disableResultMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
132 for(HoleList::iterator itr=_holeList.begin();
133 itr!=_holeList.end();
134 ++itr)
135 {
136 itr->setResultMask(0);
137 }
138}
139
141{
142 //std::cout<<"ShadowVolumeOccluder::pushCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
144 if (!_holeList.empty())
145 {
146 for(HoleList::iterator itr=_holeList.begin();
147 itr!=_holeList.end();
148 ++itr)
149 {
150 itr->pushCurrentMask();
151 }
152 }
153}
154
156{
158 if (!_holeList.empty())
159 {
160 for(HoleList::iterator itr=_holeList.begin();
161 itr!=_holeList.end();
162 ++itr)
163 {
164 itr->popCurrentMask();
165 }
166 }
167 //std::cout<<"ShadowVolumeOccluder::popCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
168}
169
170} // end of namespace
171
172#endif
Definition BoundingBox:34
Definition BoundingSphere:35
Definition ConvexPlanarOccluder:26
Definition CullStack:28
Definition Matrixd:27
Definition Polytope:26
void pushCurrentMask()
Definition Polytope:185
void setResultMask(ClippingMask mask)
Definition Polytope:176
void popCurrentMask()
Definition Polytope:190
Definition ShadowVolumeOccluder:27
const Polytope & getOccluder() const
Definition ShadowVolumeOccluder:81
NodePath _nodePath
Definition ShadowVolumeOccluder:117
bool computeOccluder(const NodePath &nodePath, const ConvexPlanarOccluder &occluder, CullStack &cullStack, bool createDrawables=false)
void popCurrentMask()
Definition ShadowVolumeOccluder:155
float _volume
Definition ShadowVolumeOccluder:116
Polytope _occluderVolume
Definition ShadowVolumeOccluder:119
const HoleList & getHoleList() const
Definition ShadowVolumeOccluder:87
const NodePath & getNodePath() const
Definition ShadowVolumeOccluder:70
Polytope & getOccluder()
Definition ShadowVolumeOccluder:78
std::vector< Polytope > HoleList
Definition ShadowVolumeOccluder:32
void pushCurrentMask()
Definition ShadowVolumeOccluder:140
void setNodePath(NodePath &nodePath)
Definition ShadowVolumeOccluder:68
bool matchProjectionMatrix(const osg::Matrix &matrix) const
Definition ShadowVolumeOccluder:59
void disableResultMasks()
Definition ShadowVolumeOccluder:128
void transformProvidingInverse(const osg::Matrix &matrix)
Definition ShadowVolumeOccluder:102
ref_ptr< const RefMatrix > _projectionMatrix
Definition ShadowVolumeOccluder:118
HoleList & getHoleList()
Definition ShadowVolumeOccluder:84
ShadowVolumeOccluder()
Definition ShadowVolumeOccluder:41
HoleList _holeList
Definition ShadowVolumeOccluder:120
ShadowVolumeOccluder(const ShadowVolumeOccluder &svo)
Definition ShadowVolumeOccluder:34
bool contains(const std::vector< Vec3 > &vertices)
float getVolume() const
Definition ShadowVolumeOccluder:75
bool contains(const BoundingSphere &bound)
bool contains(const BoundingBox &bound)
NodePath & getNodePath()
Definition ShadowVolumeOccluder:69
Definition ref_ptr:32
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
std::vector< Node * > NodePath
Definition Node:47
std::vector< ShadowVolumeOccluder > ShadowVolumeOccluderList
Definition ShadowVolumeOccluder:125
#define OSG_EXPORT
Definition osg/Export:39