update uniform from one place

pull/317/head
Miloslav Číž 7 years ago
parent 797e407269
commit 8a1e0e74fd

@ -502,9 +502,6 @@ namespace MWRender
mWater->update(dt); mWater->update(dt);
} }
if (!mSky->isEnabled() || !mSky->hasRain())
clearRainRipples();
mCamera->update(dt, paused); mCamera->update(dt, paused);
osg::Vec3f focal, cameraPos; osg::Vec3f focal, cameraPos;
@ -803,12 +800,6 @@ namespace MWRender
void RenderingManager::notifyWorldSpaceChanged() void RenderingManager::notifyWorldSpaceChanged()
{ {
mEffectManager->clear(); mEffectManager->clear();
mWater->clearRipples();
}
void RenderingManager::clearRainRipples()
{
mWater->getRainIntensityUniform()->set((float) 0.0);
} }
void RenderingManager::clear() void RenderingManager::clear()

@ -159,8 +159,6 @@ namespace MWRender
/// Clear all worldspace-specific data /// Clear all worldspace-specific data
void notifyWorldSpaceChanged(); void notifyWorldSpaceChanged();
void clearRainRipples();
void update(float dt, bool paused); void update(float dt, bool paused);
Animation* getAnimation(const MWWorld::Ptr& ptr); Animation* getAnimation(const MWWorld::Ptr& ptr);

@ -1245,11 +1245,11 @@ private:
class AlphaFader : public SceneUtil::StateSetUpdater class AlphaFader : public SceneUtil::StateSetUpdater
{ {
public: public:
/// @param rainIntensityUniform rain uniform to update along with alpha, can be NULL /// @param alphaUpdate variable which to update with alpha value
AlphaFader(osg::Uniform *rainIntensityUniform=NULL) AlphaFader(float *alphaUpdate)
: mAlpha(1.f) : mAlpha(1.f)
{ {
mRainIntensityUniform = rainIntensityUniform; mAlphaUpdate = alphaUpdate;
} }
void setAlpha(float alpha) void setAlpha(float alpha)
@ -1269,18 +1269,18 @@ public:
osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL)); osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,mAlpha)); mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,mAlpha));
if (mRainIntensityUniform) if (mAlphaUpdate)
mRainIntensityUniform->set((float) mAlpha); *mAlphaUpdate = mAlpha;
} }
// Helper for adding AlphaFaders to a subgraph // Helper for adding AlphaFaders to a subgraph
class SetupVisitor : public osg::NodeVisitor class SetupVisitor : public osg::NodeVisitor
{ {
public: public:
SetupVisitor(osg::Uniform *rainIntensityUniform) SetupVisitor(float *alphaUpdate)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
{ {
mRainIntensityUniform = rainIntensityUniform; mAlphaUpdate = alphaUpdate;
} }
virtual void apply(osg::Node &node) virtual void apply(osg::Node &node)
@ -1300,7 +1300,7 @@ public:
callback = callback->getNestedCallback(); callback = callback->getNestedCallback();
} }
osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader(mRainIntensityUniform)); osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader(mAlphaUpdate));
if (composite) if (composite)
composite->addController(alphaFader); composite->addController(alphaFader);
@ -1310,6 +1310,7 @@ public:
mAlphaFaders.push_back(alphaFader); mAlphaFaders.push_back(alphaFader);
} }
} }
traverse(node); traverse(node);
} }
@ -1320,20 +1321,19 @@ public:
private: private:
std::vector<osg::ref_ptr<AlphaFader> > mAlphaFaders; std::vector<osg::ref_ptr<AlphaFader> > mAlphaFaders;
osg::Uniform *mRainIntensityUniform; float *mAlphaUpdate;
}; };
protected: protected:
float mAlpha; float mAlpha;
osg::Uniform *mRainIntensityUniform; float *mAlphaUpdate;
}; };
class RainFader : public AlphaFader class RainFader : public AlphaFader
{ {
public: public:
RainFader(osg::Uniform *rainIntensityUniform): AlphaFader() RainFader(float *alphaUpdate): AlphaFader(alphaUpdate)
{ {
mRainIntensityUniform = rainIntensityUniform;
} }
virtual void setDefaults(osg::StateSet* stateset) virtual void setDefaults(osg::StateSet* stateset)
@ -1348,11 +1348,8 @@ public:
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv) virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv)
{ {
AlphaFader::apply(stateset,nv); AlphaFader::apply(stateset,nv);
mRainIntensityUniform->set((float) (mAlpha * 2.0)); // mAlpha is limited to 0.6 so multiply by 2 to reach full intensity *mAlphaUpdate = mAlpha * 2.0; // mAlpha is limited to 0.6 so multiply by 2 to reach full intensity
} }
protected:
osg::Uniform* mRainIntensityUniform;
}; };
void SkyManager::setCamera(osg::Camera *camera) void SkyManager::setCamera(osg::Camera *camera)
@ -1496,7 +1493,7 @@ void SkyManager::createRain()
mRainNode->addChild(mRainParticleSystem); mRainNode->addChild(mRainParticleSystem);
mRainNode->addChild(updater); mRainNode->addChild(updater);
mRainFader = new RainFader(mRainIntensityUniform); mRainFader = new RainFader(&mWeatherAlpha);
mRainNode->addUpdateCallback(mRainFader); mRainNode->addUpdateCallback(mRainFader);
mRainNode->addCullCallback(mUnderwaterSwitch); mRainNode->addCullCallback(mUnderwaterSwitch);
mRainNode->setNodeMask(Mask_WeatherParticles); mRainNode->setNodeMask(Mask_WeatherParticles);
@ -1549,7 +1546,16 @@ bool SkyManager::hasRain()
void SkyManager::update(float duration) void SkyManager::update(float duration)
{ {
if (!mEnabled) return; if (!mEnabled)
{
mRainIntensityUniform->set((float) 0.0);
return;
}
if (mIsStorm || (!hasRain() && !mParticleNode))
mRainIntensityUniform->set((float) 0.0);
else
mRainIntensityUniform->set((float) mWeatherAlpha);
if (mIsStorm) if (mIsStorm)
{ {
@ -1661,9 +1667,7 @@ void SkyManager::setWeather(const WeatherResult& weather)
SceneUtil::AssignControllerSourcesVisitor assignVisitor(std::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource)); SceneUtil::AssignControllerSourcesVisitor assignVisitor(std::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource));
mParticleEffect->accept(assignVisitor); mParticleEffect->accept(assignVisitor);
osg::Uniform *rainUniform = weather.mIsStorm ? NULL : mRainIntensityUniform; AlphaFader::SetupVisitor alphaFaderSetupVisitor(&mWeatherAlpha);
AlphaFader::SetupVisitor alphaFaderSetupVisitor(rainUniform);
mParticleEffect->accept(alphaFaderSetupVisitor); mParticleEffect->accept(alphaFaderSetupVisitor);
mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders(); mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders();

@ -252,6 +252,8 @@ namespace MWRender
bool mEnabled; bool mEnabled;
bool mSunEnabled; bool mSunEnabled;
float mWeatherAlpha;
osg::Vec4f mMoonScriptColor; osg::Vec4f mMoonScriptColor;
}; };
} }

Loading…
Cancel
Save