OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ViewDependentShadowMap.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2011 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 OSGSHADOW_VIEWDEPENDENTSHADOWMAP
15 #define OSGSHADOW_VIEWDEPENDENTSHADOWMAP 1
16 
17 #include <osg/Camera>
18 #include <osg/Material>
19 #include <osg/MatrixTransform>
20 #include <osg/LightSource>
21 #include <osg/PolygonOffset>
22 
23 #include <osgShadow/ShadowTechnique>
24 
25 namespace osgShadow {
26 
29 {
30  public :
32 
34 
36 
38  virtual void init();
39 
41  virtual void update(osg::NodeVisitor& nv);
42 
44  virtual void cull(osgUtil::CullVisitor& cv);
45 
47  virtual void resizeGLObjectBuffers(unsigned int maxSize);
48 
52  virtual void releaseGLObjects(osg::State* = 0) const;
53 
55  virtual void cleanSceneGraph();
56 
57 
59  {
60  Frustum(osgUtil::CullVisitor* cv, double minZNear, double maxZFar);
61 
64 
65  typedef std::vector<osg::Vec3d> Vertices;
66  Vertices corners;
67 
68  typedef std::vector<unsigned int> Indices;
69  typedef std::vector<Indices> Faces;
70  Faces faces;
71 
72  typedef std::vector<Indices> Edges;
73  Edges edges;
74 
80  };
81 
82  // forward declare
83  class ViewDependentData;
84 
86  {
88 
89  virtual void setLightData(osg::RefMatrix* lm, const osg::Light* l, const osg::Matrixd& modelViewMatrix);
90 
92 
95 
100 
101  typedef std::vector<unsigned int> ActiveTextureUnits;
102  ActiveTextureUnits textureUnits;
103  };
104 
105  typedef std::list< osg::ref_ptr<LightData> > LightDataList;
106 
108  {
110 
111  virtual void releaseGLObjects(osg::State* = 0) const;
112 
114 
115  unsigned int _textureUnit;
119  };
120 
121  typedef std::list< osg::ref_ptr<ShadowData> > ShadowDataList;
122 
123 
125  {
126  public:
128 
129  const ViewDependentShadowMap* getViewDependentShadowMap() const { return _viewDependentShadowMap; }
130 
131  LightDataList& getLightDataList() { return _lightDataList; }
132 
133  ShadowDataList& getShadowDataList() { return _shadowDataList; }
134 
135  osg::StateSet* getStateSet() { return _stateset.get(); }
136 
137  virtual void releaseGLObjects(osg::State* = 0) const;
138 
139  protected:
140  virtual ~ViewDependentData() {}
141 
143 
145 
146  LightDataList _lightDataList;
147  ShadowDataList _shadowDataList;
148  };
149 
150  virtual ViewDependentData* createViewDependentData(osgUtil::CullVisitor* cv);
151 
152  ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv);
153 
154 
155 
156  virtual void createShaders();
157 
158  virtual bool selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const;
159 
160  virtual osg::Polytope computeLightViewFrustumPolytope(Frustum& frustum, LightData& positionedLight);
161 
162  virtual bool computeShadowCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix);
163 
164  virtual bool adjustPerspectiveShadowMapCameraSettings(osgUtil::RenderStage* renderStage, Frustum& frustum, LightData& positionedLight, osg::Camera* camera);
165 
166  virtual bool assignTexGenSettings(osgUtil::CullVisitor* cv, osg::Camera* camera, unsigned int textureUnit, osg::TexGen* texgen);
167 
168  virtual void cullShadowReceivingScene(osgUtil::CullVisitor* cv) const;
169 
170  virtual void cullShadowCastingScene(osgUtil::CullVisitor* cv, osg::Camera* camera) const;
171 
172  virtual osg::StateSet* selectStateSetForRenderingShadow(ViewDependentData& vdd) const;
173 
174 
175 protected:
176  virtual ~ViewDependentShadowMap();
177 
178  typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr<ViewDependentData> > ViewDependentDataMap;
180  ViewDependentDataMap _viewDependentDataMap;
181 
183 
188 
189  typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
191  Uniforms _uniforms;
193 };
194 
195 }
196 
197 #endif
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
std::map< osgUtil::CullVisitor *, osg::ref_ptr< ViewDependentData > > ViewDependentDataMap
osg::ref_ptr< osg::Texture2D > _fallbackShadowMapTexture
std::list< osg::ref_ptr< LightData > > LightDataList
osg::ref_ptr< osg::StateSet > _shadowCastingStateSet
#define OSGSHADOW_EXPORT
Definition: Export.h:39
#define META_Object(library, name)
Definition: Object.h:42
osg::ref_ptr< osg::StateSet > _shadowRecievingPlaceholderStateSet
osg::ref_ptr< osg::Texture2D > _fallbackBaseTexture
osg::ref_ptr< osg::Program > _program
osg::ref_ptr< osg::PolygonOffset > _polygonOffset
std::vector< osg::ref_ptr< osg::Uniform > > Uniforms
const ViewDependentShadowMap * getViewDependentShadowMap() const
std::list< osg::ref_ptr< ShadowData > > ShadowDataList