move rain intensity uniform to water node

new-script-api
Miloslav Číž 7 years ago
parent af6eeddbe5
commit da47653625

@ -251,12 +251,9 @@ namespace MWRender
sceneRoot->setNodeMask(Mask_Scene); sceneRoot->setNodeMask(Mask_Scene);
sceneRoot->setName("Scene Root"); sceneRoot->setName("Scene Root");
mUniformRainIntensity = new osg::Uniform("rainIntensity",(float) 0.0);
mRootNode->getOrCreateStateSet()->addUniform(mUniformRainIntensity);
mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager())); mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager()));
mSky->setCamera(mViewer->getCamera()); mSky->setCamera(mViewer->getCamera());
mSky->setRainIntensityUniform(mWater->getRainIntensityUniform());
source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON); source->setStateSetModes(*mRootNode->getOrCreateStateSet(), osg::StateAttribute::ON);
@ -506,7 +503,7 @@ namespace MWRender
} }
if (!mSky->isEnabled() || !mSky->hasRain()) if (!mSky->isEnabled() || !mSky->hasRain())
clearRainRipples(); clearRainRipples();
mCamera->update(dt, paused); mCamera->update(dt, paused);
@ -811,7 +808,7 @@ namespace MWRender
void RenderingManager::clearRainRipples() void RenderingManager::clearRainRipples()
{ {
mUniformRainIntensity->set((float) 0.0); mWater->getRainIntensityUniform()->set((float) 0.0);
} }
void RenderingManager::clear() void RenderingManager::clear()

@ -85,7 +85,6 @@ namespace MWRender
osg::Uniform* mUniformNear; osg::Uniform* mUniformNear;
osg::Uniform* mUniformFar; osg::Uniform* mUniformFar;
osg::Uniform* mUniformRainIntensity;
void preloadCommonAssets(); void preloadCommonAssets();

@ -1096,6 +1096,7 @@ private:
SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager) SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneManager)
: mSceneManager(sceneManager) : mSceneManager(sceneManager)
, mCamera(NULL) , mCamera(NULL)
, mRainIntensityUniform(NULL)
, mAtmosphereNightRoll(0.f) , mAtmosphereNightRoll(0.f)
, mCreated(false) , mCreated(false)
, mIsStorm(false) , mIsStorm(false)
@ -1138,6 +1139,11 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana
mUnderwaterSwitch = new UnderwaterSwitchCallback(skyroot); mUnderwaterSwitch = new UnderwaterSwitchCallback(skyroot);
} }
void SkyManager::setRainIntensityUniform(osg::Uniform *uniform)
{
mRainIntensityUniform = uniform;
}
void SkyManager::create() void SkyManager::create()
{ {
assert(!mCreated); assert(!mCreated);
@ -1315,7 +1321,6 @@ protected:
class RainFader : public AlphaFader class RainFader : public AlphaFader
{ {
public: public:
RainFader(osg::Uniform *rainIntensityUniform): AlphaFader() RainFader(osg::Uniform *rainIntensityUniform): AlphaFader()
{ {
mRainIntensityUniform = rainIntensityUniform; mRainIntensityUniform = rainIntensityUniform;
@ -1481,7 +1486,7 @@ void SkyManager::createRain()
mRainNode->addChild(mRainParticleSystem); mRainNode->addChild(mRainParticleSystem);
mRainNode->addChild(updater); mRainNode->addChild(updater);
mRainFader = new RainFader(mRootNode->getParent(0)->getParent(0)->getStateSet()->getUniform("rainIntensity")); mRainFader = new RainFader(mRainIntensityUniform);
mRainNode->addUpdateCallback(mRainFader); mRainNode->addUpdateCallback(mRainFader);
mRainNode->addCullCallback(mUnderwaterSwitch); mRainNode->addCullCallback(mUnderwaterSwitch);
mRainNode->setNodeMask(Mask_WeatherParticles); mRainNode->setNodeMask(Mask_WeatherParticles);
@ -1742,7 +1747,8 @@ void SkyManager::setWeather(const WeatherResult& weather)
mSun->adjustTransparency(weather.mGlareView * weather.mSunDiscColor.a()); mSun->adjustTransparency(weather.mGlareView * weather.mSunDiscColor.a());
float nextStarsOpacity = weather.mNightFade * weather.mGlareView; float nextStarsOpacity = weather.mNightFade * weather.mGlareView;
if(weather.mNight && mStarsOpacity != nextStarsOpacity)
if (weather.mNight && mStarsOpacity != nextStarsOpacity)
{ {
mStarsOpacity = nextStarsOpacity; mStarsOpacity = nextStarsOpacity;
@ -1753,6 +1759,7 @@ void SkyManager::setWeather(const WeatherResult& weather)
if (mRainFader) if (mRainFader)
mRainFader->setAlpha(weather.mEffectFade * 0.6); // * Rain_Threshold? mRainFader->setAlpha(weather.mEffectFade * 0.6); // * Rain_Threshold?
for (std::vector<osg::ref_ptr<AlphaFader> >::const_iterator it = mParticleFaders.begin(); it != mParticleFaders.end(); ++it) for (std::vector<osg::ref_ptr<AlphaFader> >::const_iterator it = mParticleFaders.begin(); it != mParticleFaders.end(); ++it)
(*it)->setAlpha(weather.mEffectFade); (*it)->setAlpha(weather.mEffectFade);
} }

@ -8,6 +8,7 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Vec4f> #include <osg/Vec4f>
#include <osg/Uniform>
namespace osg namespace osg
{ {
@ -168,6 +169,8 @@ namespace MWRender
void setCamera(osg::Camera *camera); void setCamera(osg::Camera *camera);
void setRainIntensityUniform(osg::Uniform *uniform);
private: private:
void create(); void create();
///< no need to call this, automatically done on first enable() ///< no need to call this, automatically done on first enable()
@ -178,7 +181,8 @@ namespace MWRender
Resource::SceneManager* mSceneManager; Resource::SceneManager* mSceneManager;
osg::Camera* mCamera; osg::Camera *mCamera;
osg::Uniform *mRainIntensityUniform;
osg::ref_ptr<osg::Group> mRootNode; osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<osg::Group> mEarlyRenderBinRoot; osg::ref_ptr<osg::Group> mEarlyRenderBinRoot;

@ -411,14 +411,20 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
createSimpleWaterStateSet(geom2, mFallback->getFallbackFloat("Water_Map_Alpha")); createSimpleWaterStateSet(geom2, mFallback->getFallbackFloat("Water_Map_Alpha"));
geom2->setNodeMask(Mask_SimpleWater); geom2->setNodeMask(Mask_SimpleWater);
mWaterNode->addChild(geom2); mWaterNode->addChild(geom2);
mSceneRoot->addChild(mWaterNode); mSceneRoot->addChild(mWaterNode);
setHeight(mTop); setHeight(mTop);
mRainIntensityUniform = NULL;
updateWaterMaterial(); updateWaterMaterial();
} }
osg::Uniform *Water::getRainIntensityUniform()
{
return mRainIntensityUniform;
}
void Water::updateWaterMaterial() void Water::updateWaterMaterial()
{ {
if (mReflection) if (mReflection)
@ -550,6 +556,9 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
program->addShader(fragmentShader); program->addShader(fragmentShader);
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON); shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
shaderStateset->addUniform(mRainIntensityUniform);
node->setStateSet(shaderStateset); node->setStateSet(shaderStateset);
node->setUpdateCallback(NULL); node->setUpdateCallback(NULL);
} }

@ -6,6 +6,7 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <osg/Uniform>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
@ -50,6 +51,8 @@ namespace MWRender
{ {
static const int CELL_SIZE = 8192; static const int CELL_SIZE = 8192;
osg::Uniform* mRainIntensityUniform;
osg::ref_ptr<osg::Group> mParent; osg::ref_ptr<osg::Group> mParent;
osg::ref_ptr<osg::Group> mSceneRoot; osg::ref_ptr<osg::Group> mSceneRoot;
osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode; osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode;
@ -110,6 +113,8 @@ namespace MWRender
void update(float dt); void update(float dt);
void processChangedSettings(const Settings::CategorySettingVector& settings); void processChangedSettings(const Settings::CategorySettingVector& settings);
osg::Uniform *getRainIntensityUniform();
}; };
} }

Loading…
Cancel
Save