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

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

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

@ -8,6 +8,7 @@
#include <osg/ref_ptr>
#include <osg/Vec4f>
#include <osg/Uniform>
namespace osg
{
@ -168,6 +169,8 @@ namespace MWRender
void setCamera(osg::Camera *camera);
void setRainIntensityUniform(osg::Uniform *uniform);
private:
void create();
///< no need to call this, automatically done on first enable()
@ -178,7 +181,8 @@ namespace MWRender
Resource::SceneManager* mSceneManager;
osg::Camera* mCamera;
osg::Camera *mCamera;
osg::Uniform *mRainIntensityUniform;
osg::ref_ptr<osg::Group> mRootNode;
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"));
geom2->setNodeMask(Mask_SimpleWater);
mWaterNode->addChild(geom2);
mSceneRoot->addChild(mWaterNode);
setHeight(mTop);
mRainIntensityUniform = NULL;
updateWaterMaterial();
}
osg::Uniform *Water::getRainIntensityUniform()
{
return mRainIntensityUniform;
}
void Water::updateWaterMaterial()
{
if (mReflection)
@ -550,6 +556,9 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
program->addShader(fragmentShader);
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
shaderStateset->addUniform(mRainIntensityUniform);
node->setStateSet(shaderStateset);
node->setUpdateCallback(NULL);
}

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

Loading…
Cancel
Save