Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
StructureShadowsOSG.h
1 //
2 // StructureShadowsOSG.h
3 //
4 // Copyright (c) 2005-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef STRUCTURESHADOWSOSG_H
9 #define STRUCTURESHADOWSOSG_H
10 
11 #include <osg/Vec3>
12 #include <osg/TexGenNode>
13 #include <osg/PolygonOffset>
14 #include <osg/CameraNode>
15 
16 
17 class CStructureShadowsOSG : public osg::Referenced
18 {
19 public:
20  CStructureShadowsOSG(bool bDepthShadow = false, bool bStructureOnStructureShadows = false);
22 
23  void SetSunDirection(osg::Vec3 SunPosition);
24  void ComputeShadows();
25  bool Initialise(osgUtil::SceneView *pSceneView, osg::Node *pStructures,
26  osg::Node *pShadowed, const int iResolution, float fDarkness,
27  int iTextureUnit, const FSphere &ShadowSphere);
28  void SetShadowDarkness(float fDarkness);
29  void SetShadowSphere(const FSphere &ShadowSphere, bool bForceRedraw);
30  void SetPolygonOffset(float fFactor, float fUnits);
31  void ExcludeFromShadower(osg::Node *pNode, bool bExclude);
32  bool IsExcludedFromShadower(osg::Node *pNode);
33 
34  // Strip out any modelling transforms from the model view matrix
35  class EyeLinearTexGen : public osg::TexGen
36  {
37  public:
38  void setMatrix(const osg::Matrix& Matrix)
39  {
40  m_Matrix = Matrix;
41  }
42 
43  virtual void apply(osg::State& state) const
44  {
45  glPushMatrix();
46  glLoadMatrix(m_Matrix.ptr());
47  TexGen::apply(state);
48  glPopMatrix();
49  }
50  protected:
51  osg::Matrix m_Matrix;
52  };
53 
54 protected:
55  osg::ref_ptr<osg::CameraNode> m_pCameraNode;
56  osg::ref_ptr<osg::Texture2D> m_pTexture;
57  osg::ref_ptr<osg::Material> m_pMaterial;
58  osg::ref_ptr<osgUtil::SceneView> m_pSceneView;
59  osg::ref_ptr<osg::Node> m_pShadowed;
60  osg::ref_ptr<osg::TexGenNode> m_pTerrainTexGenNode;
61  osg::ref_ptr<osg::Group> m_pTop;
62  osg::ref_ptr<osg::Uniform> m_pAmbientBias;
63  osg::ref_ptr<osg::PolygonOffset> m_pPolygonOffset;
64  float m_fShadowDarkness;
65  bool m_bDepthShadow;
66  bool m_bStructureOnStructureShadows;
67  osg::Vec3 m_SunDirection;
68  static osg::TexGenNode *m_pStructureTexGenNode;
69  int m_iTargetResolution;
70  int m_iCurrentResolution;
71  bool m_bUsingLiveFrameBuffer;
72  std::list<osg::Node*> m_ExcludeFromShadower;
73  float m_fPolygonOffsetFactor;
74  float m_fPolygonOffsetUnits;
75  FSphere m_ShadowSphere;
76 };
77 
78 #endif // STRUCTURESHADOWSOSG_H