Merge pull request #318 from TES3MP/master

Add master commits up to 18 Oct 2017
new-script-api
David Cernat 7 years ago committed by GitHub
commit 6e7c033a5d

@ -127,7 +127,11 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
}
std::string local = variables["data-local"].as<Files::EscapeHashString>().toStdString();
if (!local.empty()) {
if (!local.empty())
{
if (local.front() == '\"')
local = local.substr(1, local.length() - 2);
dataLocal.push_back(Files::PathContainer::value_type(local));
}

@ -245,6 +245,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
std::string local(variables["data-local"].as<Files::EscapeHashString>().toStdString());
if (!local.empty())
{
if (local.front() == '\"')
local = local.substr(1, local.length() - 2);
dataDirs.push_back(Files::PathContainer::value_type(local));
}

@ -1992,7 +1992,7 @@ void CharacterController::update(float duration)
: (sneak ? CharState_SneakBack
: (isrunning ? CharState_RunBack : CharState_WalkBack)));
}
else if(rot.z() != 0.0f && !inwater && !sneak && !(mPtr == getPlayer() && MWBase::Environment::get().getWorld()->isFirstPerson()))
else if(rot.z() != 0.0f && !sneak && !(mPtr == getPlayer() && MWBase::Environment::get().getWorld()->isFirstPerson()))
{
if(rot.z() > 0.0f)
movestate = inwater ? CharState_SwimTurnRight : CharState_TurnRight;

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

@ -85,7 +85,6 @@ namespace MWRender
osg::Uniform* mUniformNear;
osg::Uniform* mUniformFar;
osg::Uniform* mUniformRainIntensity;
void preloadCommonAssets();
@ -160,8 +159,6 @@ namespace MWRender
/// Clear all worldspace-specific data
void notifyWorldSpaceChanged();
void clearRainRipples();
void update(float dt, bool paused);
Animation* getAnimation(const MWWorld::Ptr& ptr);

@ -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);
@ -1239,9 +1245,11 @@ private:
class AlphaFader : public SceneUtil::StateSetUpdater
{
public:
AlphaFader()
/// @param alphaUpdate variable which to update with alpha value
AlphaFader(float *alphaUpdate)
: mAlpha(1.f)
{
mAlphaUpdate = alphaUpdate;
}
void setAlpha(float alpha)
@ -1260,15 +1268,19 @@ public:
{
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));
if (mAlphaUpdate)
*mAlphaUpdate = mAlpha;
}
// Helper for adding AlphaFaders to a subgraph
class SetupVisitor : public osg::NodeVisitor
{
public:
SetupVisitor()
SetupVisitor(float *alphaUpdate)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
{
mAlphaUpdate = alphaUpdate;
}
virtual void apply(osg::Node &node)
@ -1279,14 +1291,16 @@ public:
{
SceneUtil::CompositeStateSetUpdater* composite = NULL;
osg::Callback* callback = node.getUpdateCallback();
while (callback)
{
if ((composite = dynamic_cast<SceneUtil::CompositeStateSetUpdater*>(callback)))
break;
callback = callback->getNestedCallback();
}
osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader);
osg::ref_ptr<AlphaFader> alphaFader (new AlphaFader(mAlphaUpdate));
if (composite)
composite->addController(alphaFader);
@ -1296,6 +1310,7 @@ public:
mAlphaFaders.push_back(alphaFader);
}
}
traverse(node);
}
@ -1306,19 +1321,19 @@ public:
private:
std::vector<osg::ref_ptr<AlphaFader> > mAlphaFaders;
float *mAlphaUpdate;
};
protected:
float mAlpha;
float *mAlphaUpdate;
};
class RainFader : public AlphaFader
{
public:
RainFader(osg::Uniform *rainIntensityUniform): AlphaFader()
RainFader(float *alphaUpdate): AlphaFader(alphaUpdate)
{
mRainIntensityUniform = rainIntensityUniform;
}
virtual void setDefaults(osg::StateSet* stateset)
@ -1333,11 +1348,8 @@ public:
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *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)
@ -1481,7 +1493,7 @@ void SkyManager::createRain()
mRainNode->addChild(mRainParticleSystem);
mRainNode->addChild(updater);
mRainFader = new RainFader(mRootNode->getParent(0)->getParent(0)->getStateSet()->getUniform("rainIntensity"));
mRainFader = new RainFader(&mWeatherAlpha);
mRainNode->addUpdateCallback(mRainFader);
mRainNode->addCullCallback(mUnderwaterSwitch);
mRainNode->setNodeMask(Mask_WeatherParticles);
@ -1534,7 +1546,21 @@ bool SkyManager::hasRain()
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)
{
@ -1640,12 +1666,14 @@ void SkyManager::setWeather(const WeatherResult& weather)
mParticleNode->setNodeMask(Mask_WeatherParticles);
mRootNode->addChild(mParticleNode);
}
mParticleEffect = mSceneManager->getInstance(mCurrentParticleEffect, mParticleNode);
SceneUtil::AssignControllerSourcesVisitor assignVisitor(std::shared_ptr<SceneUtil::ControllerSource>(new SceneUtil::FrameTimeSource));
mParticleEffect->accept(assignVisitor);
AlphaFader::SetupVisitor alphaFaderSetupVisitor;
AlphaFader::SetupVisitor alphaFaderSetupVisitor(&mWeatherAlpha);
mParticleEffect->accept(alphaFaderSetupVisitor);
mParticleFaders = alphaFaderSetupVisitor.getAlphaFaders();
@ -1742,7 +1770,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 +1782,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;
@ -248,6 +252,8 @@ namespace MWRender
bool mEnabled;
bool mSunEnabled;
float mWeatherAlpha;
osg::Vec4f mMoonScriptColor;
};
}

@ -411,12 +411,19 @@ 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);
updateWaterMaterial();
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
}
osg::Uniform *Water::getRainIntensityUniform()
{
return mRainIntensityUniform.get();
}
void Water::updateWaterMaterial()
@ -550,6 +557,8 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
program->addShader(fragmentShader);
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
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::ref_ptr<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