From 8a3889a81eef72e9113b4c9cb5b8090b933b0bcb Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Jun 2015 17:38:08 +0200 Subject: [PATCH] Rain fading --- apps/openmw/mwrender/sky.cpp | 46 ++++++++++++++++++++++++++++++++---- apps/openmw/mwrender/sky.hpp | 2 ++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 96771eaa3..e5563409d 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -687,6 +687,37 @@ private: float mAngle; }; +class RainFader : public SceneUtil::StateSetUpdater +{ +public: + RainFader() + : mAlpha(1.f) + { + } + + void setAlpha(float alpha) + { + mAlpha = alpha; + } + + virtual void setDefaults(osg::StateSet* stateset) + { + osg::ref_ptr mat (new osg::Material); + mat->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1)); + mat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,1)); + stateset->setAttributeAndModes(mat, osg::StateAttribute::ON); + } + + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv) + { + osg::Material* mat = static_cast(stateset->getAttribute(osg::StateAttribute::MATERIAL)); + mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0,0,0,mAlpha)); + } + +private: + float mAlpha; +}; + void SkyManager::createRain() { if (mRainNode) @@ -704,7 +735,6 @@ void SkyManager::createRain() osg::Texture::CLAMP, osg::Texture::CLAMP), osg::StateAttribute::ON); stateset->setNestRenderBins(false); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); osgParticle::Particle& particleTemplate = mRainParticleSystem->getDefaultParticleTemplate(); @@ -739,6 +769,9 @@ void SkyManager::createRain() mRainNode->addChild(geode); mRainNode->addChild(updater); + mRainFader = new RainFader; + mRainNode->addUpdateCallback(mRainFader); + mRootNode->addChild(mRainNode); } @@ -751,6 +784,7 @@ void SkyManager::destroyRain() mRainNode = NULL; mRainParticleSystem = NULL; mRainShooter = NULL; + mRainFader = NULL; } SkyManager::~SkyManager() @@ -851,8 +885,9 @@ void SkyManager::updateRainParameters() { if (mRainShooter) { - float angle = mWindSpeed/2.f * osg::PI/4; - mRainShooter->setVelocity(osg::Vec3f(0, mRainSpeed * mWindSpeed / 2.f, -mRainSpeed)); + float windFactor = mWindSpeed/3.f; + float angle = windFactor * osg::PI/4; + mRainShooter->setVelocity(osg::Vec3f(0, mRainSpeed * windFactor, -mRainSpeed)); mRainShooter->setAngle(angle); } } @@ -991,9 +1026,10 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) if (mParticle.get()) setAlpha(mParticle, weather.mEffectFade); - for (std::map::iterator it = mRainModels.begin(); it != mRainModels.end(); ++it) - setAlpha(it->second, weather.mEffectFade); */ + + if (mRainFader) + mRainFader->setAlpha(weather.mEffectFade * 0.6); // * Rain_Threshold? } void SkyManager::setGlare(const float glare) diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index f9b9407ec..85174896b 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -30,6 +30,7 @@ namespace MWRender class Sun; class Moon; class RainShooter; + class RainFader; class SkyManager { @@ -126,6 +127,7 @@ namespace MWRender osg::ref_ptr mRainNode; osg::ref_ptr mRainParticleSystem; osg::ref_ptr mRainShooter; + osg::ref_ptr mRainFader; bool mCreated;