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(); 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)); 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()); 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);
dataDirs.push_back(Files::PathContainer::value_type(local)); dataDirs.push_back(Files::PathContainer::value_type(local));
} }

@ -1992,7 +1992,7 @@ void CharacterController::update(float duration)
: (sneak ? CharState_SneakBack : (sneak ? CharState_SneakBack
: (isrunning ? CharState_RunBack : CharState_WalkBack))); : (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) if(rot.z() > 0.0f)
movestate = inwater ? CharState_SwimTurnRight : CharState_TurnRight; movestate = inwater ? CharState_SwimTurnRight : CharState_TurnRight;

@ -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);
@ -505,9 +502,6 @@ namespace MWRender
mWater->update(dt); mWater->update(dt);
} }
if (!mSky->isEnabled() || !mSky->hasRain())
clearRainRipples();
mCamera->update(dt, paused); mCamera->update(dt, paused);
osg::Vec3f focal, cameraPos; osg::Vec3f focal, cameraPos;
@ -806,12 +800,6 @@ namespace MWRender
void RenderingManager::notifyWorldSpaceChanged() void RenderingManager::notifyWorldSpaceChanged()
{ {
mEffectManager->clear(); mEffectManager->clear();
mWater->clearRipples();
}
void RenderingManager::clearRainRipples()
{
mUniformRainIntensity->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();
@ -160,8 +159,6 @@ namespace MWRender
/// Clear all worldspace-specific data /// Clear all worldspace-specific data
void notifyWorldSpaceChanged(); void notifyWorldSpaceChanged();
void clearRainRipples();
void update(float dt, bool paused); void update(float dt, bool paused);
Animation* getAnimation(const MWWorld::Ptr& ptr); Animation* getAnimation(const MWWorld::Ptr& ptr);

@ -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,7 +1770,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 +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);
} }

@ -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;
@ -248,6 +252,8 @@ namespace MWRender
bool mEnabled; bool mEnabled;
bool mSunEnabled; bool mSunEnabled;
float mWeatherAlpha;
osg::Vec4f mMoonScriptColor; osg::Vec4f mMoonScriptColor;
}; };
} }

@ -411,12 +411,19 @@ 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);
updateWaterMaterial(); updateWaterMaterial();
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
}
osg::Uniform *Water::getRainIntensityUniform()
{
return mRainIntensityUniform.get();
} }
void Water::updateWaterMaterial() void Water::updateWaterMaterial()
@ -550,6 +557,8 @@ 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);
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::ref_ptr<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