CloudyDay
 All Classes Functions Variables Enumerations
LightShaft2.h
1 #pragma once
2 #include "Scene.h"
3 
4 #include <osg/Geode>
5 #include <osg/Geometry>
6 #include <osg/Array>
7 #include <osg/CullFace>
8 #include <osg/Depth>
9 
10 namespace osgCloudyDay
11 {
15  class LightShaft2Callback : public osg::NodeCallback
16  {
17  public:
19  {
20 
21  }
22 
23  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
24  {
25  osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
26  osg::ref_ptr<osg::Geode> geometry = dynamic_cast<osg::Geode*> (node);
27 
28  if(geometry && cv)
29  {
30  osg::Matrixd view(cv->getCurrentCamera()->getViewMatrix());
31  osg::Matrixd invViewMatrix = osg::Matrixd::inverse(view);
32  osg::Matrixd modelview(*cv->getModelViewMatrix());
33  osg::Matrixd model = modelview*invViewMatrix;
34  osg::Matrixd proj(cv->getCurrentCamera()->getProjectionMatrix());
35 
36  geometry->getOrCreateStateSet()->getUniform("ModelMatrix")->set(model);
37  geometry->getOrCreateStateSet()->getUniform("ViewMatrix")->set(view);
38  geometry->getOrCreateStateSet()->getUniform("ProjectionMatrix")->set(proj);
39 
40  geometry->getOrCreateStateSet()->getUniform("light_mv_matrix")->set(osgCloudyDay::Scene::GetLightCamera()->getViewMatrix());
41  geometry->getOrCreateStateSet()->getUniform("light_proj_matrix")->set(osgCloudyDay::Scene::GetProjectionMatrix_Light());
42  geometry->getOrCreateStateSet()->getUniform("light_mv_matrix")->set(osgCloudyDay::Scene::GetLightCamera()->getViewMatrix());
43  }
44  traverse(node, nv);
45  }
46  };
47 
49  {
50  public:
51  LightShaft2();
52  ~LightShaft2();
53 
54  void Initialize();
55  osg::Geode* GetGeode();
56  void SetUniforms(osg::ref_ptr<osg::StateSet> nodess4);
57 
58  protected:
59  osg::ref_ptr<osg::Geode> geode;
60  osg::ref_ptr<osg::Geometry> geometry;
61  osg::ref_ptr<osg::Vec3Array> m_vertices;
62  osg::ref_ptr<osg::UIntArray> m_indices;
63  osg::ref_ptr<osg::Program> m_forestProg;
64  };
65 }