|
|
@ -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);
|
|
|
@ -1239,9 +1245,11 @@ private:
|
|
|
|
class AlphaFader : public SceneUtil::StateSetUpdater
|
|
|
|
class AlphaFader : public SceneUtil::StateSetUpdater
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
AlphaFader()
|
|
|
|
/// @param alphaUpdate variable which to update with alpha value
|
|
|
|
|
|
|
|
AlphaFader(float *alphaUpdate)
|
|
|
|
: mAlpha(1.f)
|
|
|
|
: mAlpha(1.f)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
mAlphaUpdate = alphaUpdate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setAlpha(float alpha)
|
|
|
|
void setAlpha(float alpha)
|
|
|
@ -1260,15 +1268,19 @@ 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 (mAlphaUpdate)
|
|
|
|
|
|
|
|
*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()
|
|
|
|
SetupVisitor(float *alphaUpdate)
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
mAlphaUpdate = alphaUpdate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void apply(osg::Node &node)
|
|
|
|
virtual void apply(osg::Node &node)
|
|
|
@ -1279,14 +1291,16 @@ public:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SceneUtil::CompositeStateSetUpdater* composite = NULL;
|
|
|
|
SceneUtil::CompositeStateSetUpdater* composite = NULL;
|
|
|
|
osg::Callback* callback = node.getUpdateCallback();
|
|
|
|
osg::Callback* callback = node.getUpdateCallback();
|
|
|
|
|
|
|
|
|
|
|
|
while (callback)
|
|
|
|
while (callback)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((composite = dynamic_cast<SceneUtil::CompositeStateSetUpdater*>(callback)))
|
|
|
|
if ((composite = dynamic_cast<SceneUtil::CompositeStateSetUpdater*>(callback)))
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
callback = callback->getNestedCallback();
|
|
|
|
callback = callback->getNestedCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader);
|
|
|
|
osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader(mAlphaUpdate));
|
|
|
|
|
|
|
|
|
|
|
|
if (composite)
|
|
|
|
if (composite)
|
|
|
|
composite->addController(alphaFader);
|
|
|
|
composite->addController(alphaFader);
|
|
|
@ -1296,6 +1310,7 @@ public:
|
|
|
|
mAlphaFaders.push_back(alphaFader);
|
|
|
|
mAlphaFaders.push_back(alphaFader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
traverse(node);
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1306,19 +1321,19 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
std::vector<osg::ref_ptr<AlphaFader> > mAlphaFaders;
|
|
|
|
std::vector<osg::ref_ptr<AlphaFader> > mAlphaFaders;
|
|
|
|
|
|
|
|
float *mAlphaUpdate;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
float mAlpha;
|
|
|
|
float mAlpha;
|
|
|
|
|
|
|
|
float *mAlphaUpdate;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RainFader : public AlphaFader
|
|
|
|
class RainFader : public AlphaFader
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
|
|
|
|
RainFader(float *alphaUpdate): AlphaFader(alphaUpdate)
|
|
|
|
RainFader(osg::Uniform *rainIntensityUniform): AlphaFader()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRainIntensityUniform = rainIntensityUniform;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void setDefaults(osg::StateSet* stateset)
|
|
|
|
virtual void setDefaults(osg::StateSet* stateset)
|
|
|
@ -1333,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)
|
|
|
@ -1481,7 +1493,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(&mWeatherAlpha);
|
|
|
|
mRainNode->addUpdateCallback(mRainFader);
|
|
|
|
mRainNode->addUpdateCallback(mRainFader);
|
|
|
|
mRainNode->addCullCallback(mUnderwaterSwitch);
|
|
|
|
mRainNode->addCullCallback(mUnderwaterSwitch);
|
|
|
|
mRainNode->setNodeMask(Mask_WeatherParticles);
|
|
|
|
mRainNode->setNodeMask(Mask_WeatherParticles);
|
|
|
@ -1534,7 +1546,21 @@ bool SkyManager::hasRain()
|
|
|
|
|
|
|
|
|
|
|
|
void SkyManager::update(float duration)
|
|
|
|
void SkyManager::update(float duration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!mEnabled) return;
|
|
|
|
if (!mEnabled)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mRainIntensityUniform)
|
|
|
|
|
|
|
|
mRainIntensityUniform->set((float) 0.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mRainIntensityUniform)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mIsStorm || (!hasRain() && !mParticleNode))
|
|
|
|
|
|
|
|
mRainIntensityUniform->set((float) 0.0);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
mRainIntensityUniform->set((float) mWeatherAlpha);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsStorm)
|
|
|
|
if (mIsStorm)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1640,12 +1666,14 @@ void SkyManager::setWeather(const WeatherResult& weather)
|
|
|
|
mParticleNode->setNodeMask(Mask_WeatherParticles);
|
|
|
|
mParticleNode->setNodeMask(Mask_WeatherParticles);
|
|
|
|
mRootNode->addChild(mParticleNode);
|
|
|
|
mRootNode->addChild(mParticleNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mParticleEffect = mSceneManager->getInstance(mCurrentParticleEffect, mParticleNode);
|
|
|
|
mParticleEffect = mSceneManager->getInstance(mCurrentParticleEffect, mParticleNode);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
AlphaFader::SetupVisitor alphaFaderSetupVisitor;
|
|
|
|
AlphaFader::SetupVisitor alphaFaderSetupVisitor(&mWeatherAlpha);
|
|
|
|
|
|
|
|
|
|
|
|
mParticleEffect->accept(alphaFaderSetupVisitor);
|
|
|
|
mParticleEffect->accept(alphaFaderSetupVisitor);
|
|
|
|
mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders();
|
|
|
|
mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders();
|
|
|
|
|
|
|
|
|
|
|
@ -1742,6 +1770,7 @@ 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 +1782,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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|