Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
SimpleInterimShadowTechnique.h
1 //
2 // SimpleInterimShadowTechnique.h
3 //
4 // It's simple because it is.
5 // It's interim because it should be replaced with something better.
6 // It's a shadow technique.
7 //
8 // Copyright (c) 2008-2011 Virtual Terrain Project
9 // Free for all uses, see license.txt for details.
10 //
11 
12 #ifndef VTOSG_SIMPLEINTERIMSHADOWTECHNIQUEH
13 #define VTOSG_SIMPLEINTERIMSHADOWTECHNIQUEH
14 
15 #include <osg/Camera>
16 #include <osg/Material>
17 #include <osgShadow/ShadowTechnique>
18 
19 #if VTDEBUGSHADOWS
20 #include "vtlib/core/GeomUtil.h"
21 #endif
22 
23 class vtHeightField3d;
24 class vtLodGrid;
25 
27 class CSimpleInterimShadowTechnique : public osgShadow::ShadowTechnique
28 {
29 public:
31  CSimpleInterimShadowTechnique(const CSimpleInterimShadowTechnique& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
32  META_Object(osgShadow, CSimpleInterimShadowTechnique);
33  void SetLightNumber(const uint Light);
34  void SetShadowTextureUnit(const uint Unit);
35  void SetShadowTextureResolution(const uint ShadowTextureResolution) { m_ShadowTextureResolution = ShadowTextureResolution; }
36  uint GetShadowTextureResolution() { return m_ShadowTextureResolution; }
37  void SetRecalculateEveryFrame(const bool RecalculateEveryFrame) { m_RecalculateEveryFrame = RecalculateEveryFrame; }
38  bool GetRecalculateEveryFrame() const { return m_RecalculateEveryFrame; }
39  void SetShadowDarkness(const float Darkness);
40  float GetShadowDarkness() { return m_ShadowDarkness; }
41  void SetShadowSphereRadius(const float ShadowSphereRadius) { m_ShadowSphereRadius = ShadowSphereRadius; }
42  float GetShadowSphereRadius() { return m_ShadowSphereRadius; }
43  void SetHeightField3d(vtHeightField3d *pHeightField3d) { m_pHeightField3d = pHeightField3d; }
44  void AddMainSceneTextureUnit(const uint Unit, const uint Mode);
45  void RemoveMainSceneTextureUnit(const uint Unit);
46  void ForceShadowUpdate();
47  void AddLodGridToIgnore(vtLodGrid* pLodGrid) { m_LodGridsToIgnore.push_back(pLodGrid); }
48 
49  virtual void init();
50  virtual void update(osg::NodeVisitor& nv);
51  virtual void cull(osgUtil::CullVisitor& cv);
52  virtual void cleanSceneGraph();
53 
54  osg::ref_ptr<osg::Camera> makeDebugHUD();
55 
56 #if VTDEBUGSHADOWS
57  // instrumentation
58  osg::Group *m_pParent;
59  vtDynBoundBox *Box1, *Box2, *Box3;
60 #endif
61 
62 protected :
63 
64  virtual ~CSimpleInterimShadowTechnique() {}
65 
66  std::string GenerateFragmentShaderSource();
67 
68  osg::ref_ptr<osg::Camera> m_pCamera;
69  osg::ref_ptr<osg::TexGen> m_pTexgen;
70  osg::ref_ptr<osg::Texture2D> m_pTexture;
71  osg::ref_ptr<osg::StateSet> m_pStateset;
72  osg::ref_ptr<osg::Material> m_pMaterial;
73  uint m_LightNumber;// Must be set before init is called
74  uint m_ShadowTextureUnit;// Must be set before init is called
75  uint m_ShadowTextureResolution; // Must be set before init is called
76  bool m_RecalculateEveryFrame; // Can be set any time
77  float m_PolygonOffsetFactor; // Must be set before init is called
78  float m_PolygonOffsetUnits; // Must be set before init is called
79  float m_ShadowDarkness; // Must be set before init is called
80  float m_ShadowSphereRadius; // Must be set before init is called
81  std::vector<vtLodGrid*> m_LodGridsToIgnore; // Can be set any time
82  std::map<uint, uint> m_MainSceneTextureUnits;
83  vtHeightField3d *m_pHeightField3d;
84  osg::Vec3 m_OldBoundingSphereCentre;
85  osg::Vec3 m_OldSunPos;
86  bool m_UsingFrameBuffer;
87 };
88 
89 #endif // VTOSG_SIMPLEINTERIMSHADOWTECHNIQUEH
90