CloudyDay
 All Classes Functions Variables Enumerations
LightShaft.h
1 #pragma once
2 #include "Scene.h"
3 #include "LightShaftGeometry.h"
4 
5 namespace osgCloudyDay
6 {
10  class ViewerLightCallback2 : public osg::NodeCallback
11  {
12  public:
17  {
18 
19  }
20 
24  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
25  {
26  osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
27  osg::ref_ptr<osg::Geode> geometry = dynamic_cast<osg::Geode*> (node);
28 
29  if(geometry && cv)
30  {
31  osg::Matrixd view(cv->getCurrentCamera()->getViewMatrix());
32  osg::Matrixd invViewMatrix = osg::Matrixd::inverse(view);
33  osg::Matrixd model(*cv->getModelViewMatrix());
34  model = model*invViewMatrix;
35  osg::Matrixd proj(cv->getCurrentCamera()->getProjectionMatrix());
36 
37  geometry->getOrCreateStateSet()->getUniform("ModelMatrix")->set(model);
38  geometry->getOrCreateStateSet()->getUniform("ViewMatrix")->set(Scene::GetViewMatrix_View());
39  geometry->getOrCreateStateSet()->getUniform("ProjectionMatrix")->set(Scene::GetProjectionMatrix_View());
40 
41  geometry->getOrCreateStateSet()->addUniform(new osg::Uniform("v3LightPos", Scene::m_skydome->GetLightPosition()));
42  Scene::m_skydome->SetupUniform(geometry.get()->getOrCreateStateSet());
43  geometry->getOrCreateStateSet()->addUniform(new osg::Uniform("color_tex", 0));
44 
45  std::cout << std::endl << std::endl << "ath callback" << std::endl << std::endl ;
46 
47  #ifdef SHADOW_MAPPING
48  geometry->getOrCreateStateSet()->getUniform("light_proj_matrix")->set(Scene::GetProjectionMatrix_Light());
49  geometry->getOrCreateStateSet()->getUniform("light_mv_matrix")->set(Scene::GetLightCamera()->getViewMatrix());
50  #endif
51  }
52  traverse(node, nv);
53  }
54  };
55 
59  class LightShaft
60  {
61  public:
65  LightShaft(void);
69  ~LightShaft(void);
70 
74  void Initialize();
79  osg::ref_ptr<osg::Camera> GetCamera();
80 
85  osg::ref_ptr<osg::Texture2D> GetLightshaft1();
90  osg::ref_ptr<osg::Texture2D> GetLightshaft2();
91 
92  protected:
93  osg::ref_ptr<osg::Texture2D> fbo_lightshaft1;
94  osg::ref_ptr<osg::Texture2D> fbo_lightshaft2;
95 
96  osg::ref_ptr<osg::Texture2D> fbo_lightshaft_d;
97  osg::Camera* camera_lightshaft;
98  };
99 }