|
|
|
@ -208,6 +208,37 @@ public:
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RainIntensityUpdater : public SceneUtil::StateSetUpdater
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RainIntensityUpdater()
|
|
|
|
|
: mRainIntensity(0.f)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setRainIntensity(float rainIntensity)
|
|
|
|
|
{
|
|
|
|
|
mRainIntensity = rainIntensity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void setDefaults(osg::StateSet* stateset) override
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Uniform> rainIntensityUniform = new osg::Uniform("rainIntensity", 0.0f);
|
|
|
|
|
stateset->addUniform(rainIntensityUniform.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply(osg::StateSet* stateset, osg::NodeVisitor* /*nv*/) override
|
|
|
|
|
{
|
|
|
|
|
osg::ref_ptr<osg::Uniform> rainIntensityUniform = stateset->getUniform("rainIntensity");
|
|
|
|
|
if (rainIntensityUniform != nullptr)
|
|
|
|
|
rainIntensityUniform->set(mRainIntensity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
float mRainIntensity;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> readPngImage (const std::string& file)
|
|
|
|
|
{
|
|
|
|
|
// use boost in favor of osgDB::readImage, to handle utf-8 path issues on Windows
|
|
|
|
@ -431,7 +462,8 @@ public:
|
|
|
|
|
|
|
|
|
|
Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem *resourceSystem,
|
|
|
|
|
osgUtil::IncrementalCompileOperation *ico, const std::string& resourcePath)
|
|
|
|
|
: mParent(parent)
|
|
|
|
|
: mRainIntensityUpdater(nullptr)
|
|
|
|
|
, mParent(parent)
|
|
|
|
|
, mSceneRoot(sceneRoot)
|
|
|
|
|
, mResourceSystem(resourceSystem)
|
|
|
|
|
, mResourcePath(resourcePath)
|
|
|
|
@ -463,8 +495,6 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
|
|
|
|
|
|
|
|
|
|
setHeight(mTop);
|
|
|
|
|
|
|
|
|
|
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
|
|
|
|
|
|
|
|
|
|
updateWaterMaterial();
|
|
|
|
|
|
|
|
|
|
if (ico)
|
|
|
|
@ -494,11 +524,6 @@ void Water::setCullCallback(osg::Callback* callback)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::Uniform *Water::getRainIntensityUniform()
|
|
|
|
|
{
|
|
|
|
|
return mRainIntensityUniform.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::updateWaterMaterial()
|
|
|
|
|
{
|
|
|
|
|
if (mReflection)
|
|
|
|
@ -556,6 +581,8 @@ void Water::createSimpleWaterStateSet(osg::Node* node, float alpha)
|
|
|
|
|
osg::ref_ptr<osg::StateSet> stateset = SceneUtil::createSimpleWaterStateSet(alpha, MWRender::RenderBin_Water);
|
|
|
|
|
|
|
|
|
|
node->setStateSet(stateset);
|
|
|
|
|
node->setUpdateCallback(nullptr);
|
|
|
|
|
mRainIntensityUpdater = nullptr;
|
|
|
|
|
|
|
|
|
|
// Add animated textures
|
|
|
|
|
std::vector<osg::ref_ptr<osg::Texture2D> > textures;
|
|
|
|
@ -639,15 +666,15 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
|
|
|
|
|
|
|
|
|
|
shaderStateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
|
|
shaderStateset->addUniform(mRainIntensityUniform.get());
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Program> program (new osg::Program);
|
|
|
|
|
program->addShader(vertexShader);
|
|
|
|
|
program->addShader(fragmentShader);
|
|
|
|
|
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
|
|
node->setStateSet(shaderStateset);
|
|
|
|
|
node->setUpdateCallback(nullptr);
|
|
|
|
|
|
|
|
|
|
mRainIntensityUpdater = new RainIntensityUpdater();
|
|
|
|
|
node->setUpdateCallback(mRainIntensityUpdater);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::processChangedSettings(const Settings::CategorySettingVector& settings)
|
|
|
|
@ -730,6 +757,12 @@ void Water::setHeight(const float height)
|
|
|
|
|
mRefraction->setWaterLevel(mTop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::setRainIntensity(float rainIntensity)
|
|
|
|
|
{
|
|
|
|
|
if (mRainIntensityUpdater)
|
|
|
|
|
mRainIntensityUpdater->setRainIntensity(rainIntensity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::update(float dt)
|
|
|
|
|
{
|
|
|
|
|
mSimulation->update(dt);
|
|
|
|
|