5 #include <osg/Texture2D>
45 osg::ref_ptr<osg::Geode> m_geode;
47 static osg::ref_ptr<osg::Program> m_rain_shader;
48 static osg::ref_ptr<osg::Texture3D> m_rain_texture;
50 std::vector<unsigned int> m_index;
51 osg::ref_ptr<osg::Vec3Array> m_vertices;
52 osg::ref_ptr<osg::Vec4Array> m_velocity;
53 osg::ref_ptr<osg::Vec4Array> m_information;
73 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
75 osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*
>(nv);
76 osg::ref_ptr<osg::Geode> geometry =
dynamic_cast<osg::Geode*
> (node);
78 float fspeed = 2500.f;
82 osg::ref_ptr<osg::Geometry> g =
static_cast<osg::Geometry*
> (geometry->getDrawable(0));
83 osg::ref_ptr<osg::Vec3Array> pos =
static_cast<osg::Vec3Array*
>(g->getVertexAttribArray(0));
84 osg::ref_ptr<osg::Vec4Array> vel =
static_cast<osg::Vec4Array*
>(g->getVertexAttribArray(1));
85 for(
unsigned int i = 0; i < pos->size(); i++)
87 pos->at(i).x() = pos->at(i).x() + 0.05f * vel->at(i).x() * fspeed;
88 pos->at(i).y() = pos->at(i).y() + 0.05f * vel->at(i).y() * fspeed;
89 pos->at(i).z() = pos->at(i).z() + 0.05f * vel->at(i).z() * fspeed;
90 vel->at(i).w() -= 0.05f;
92 if(vel->at(i).w() < 0.f)
94 pos->at(i).z() = fspeed;
98 g->getVertexAttribArray(0)->dirty();
99 g->getVertexAttribArray(1)->dirty();
101 osg::Matrixd view(cv->getCurrentCamera()->getViewMatrix());
102 osg::Matrixd invViewMatrix = osg::Matrixd::inverse(view);
103 osg::Matrixd modelview(*cv->getModelViewMatrix());
104 osg::Matrixd model = modelview*invViewMatrix;
105 osg::Matrixd proj(cv->getCurrentCamera()->getProjectionMatrix());
107 geometry->getOrCreateStateSet()->getUniform(
"ModelMatrix")->set(model);
108 geometry->getOrCreateStateSet()->getUniform(
"ViewMatrix")->set(view);
109 geometry->getOrCreateStateSet()->getUniform(
"ProjectionMatrix")->set(proj);
111 #ifdef SHADOW_MAPPING
113 geometry->getOrCreateStateSet()->getUniform(
"light_mv_matrix")->set(
Scene::GetLightCamera()->getViewMatrix());