diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 5d5377669..c15cc540f 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -608,7 +608,7 @@ void CharacterController::updateIdleStormState() { Ogre::Vector3 stormDirection = MWBase::Environment::get().getWorld()->getStormDirection(); Ogre::Vector3 characterDirection = mPtr.getRefData().getBaseNode()->getOrientation().yAxis(); - inStormDirection = stormDirection.angleBetween(characterDirection) < Ogre::Degree(40); + inStormDirection = stormDirection.angleBetween(characterDirection) > Ogre::Degree(120); } if (inStormDirection && mUpperBodyState == UpperCharState_Nothing && mAnimation->hasAnimation("idlestorm")) { diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 67e301fdc..8354cca5d 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -219,6 +219,7 @@ SkyManager::SkyManager(Ogre::SceneNode *root, Ogre::Camera *pCamera) , mSceneMgr(NULL) , mAtmosphereDay(NULL) , mAtmosphereNight(NULL) + , mCloudNode(NULL) , mClouds() , mNextClouds() , mCloudBlendFactor(0.0f) @@ -240,10 +241,11 @@ SkyManager::SkyManager(Ogre::SceneNode *root, Ogre::Camera *pCamera) , mRainTimer(0) , mRainSpeed(0) , mRainFrequency(1) + , mStormDirection(0,-1,0) + , mIsStorm(false) { mSceneMgr = root->getCreator(); mRootNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); - mRootNode->setInheritOrientation(false); } void SkyManager::create() @@ -335,8 +337,8 @@ void SkyManager::create() mObjects.push_back(objects); // Clouds - SceneNode* clouds_node = mRootNode->createChildSceneNode(); - objects = NifOgre::Loader::createObjects(clouds_node, "meshes\\sky_clouds_01.nif"); + mCloudNode = mRootNode->createChildSceneNode(); + objects = NifOgre::Loader::createObjects(mCloudNode, "meshes\\sky_clouds_01.nif"); for(size_t i = 0;i < objects->mEntities.size();i++) { Entity* clouds_ent = objects->mEntities[i]; @@ -453,8 +455,16 @@ void SkyManager::update(float duration) { for (unsigned int i=0; imControllers.size(); ++i) mParticle->mControllers[i].update(); + + if (mIsStorm) + mParticleNode->setOrientation(Ogre::Vector3::UNIT_Y.getRotationTo(mStormDirection)); } + if (mIsStorm) + mCloudNode->setOrientation(Ogre::Vector3::UNIT_Y.getRotationTo(mStormDirection)); + else + mCloudNode->setOrientation(Ogre::Quaternion::IDENTITY); + updateRain(duration); // UV Scroll the clouds @@ -539,6 +549,7 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) mRainEnabled = !mRainEffect.empty(); mRainFrequency = weather.mRainFrequency; mRainSpeed = weather.mRainSpeed; + mIsStorm = weather.mIsStorm; if (mCurrentParticleEffect != weather.mParticleEffect) { @@ -676,6 +687,11 @@ void SkyManager::sunDisable() mSunEnabled = false; } +void SkyManager::setStormDirection(const Vector3 &direction) +{ + mStormDirection = direction; +} + void SkyManager::setSunDirection(const Vector3& direction, bool is_moon) { if (!mCreated) return; diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index f752011c0..7c31150f3 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -150,6 +150,8 @@ namespace MWRender void setRainSpeed(float speed); + void setStormDirection(const Ogre::Vector3& direction); + void setSunDirection(const Ogre::Vector3& direction, bool is_moon); void setMasserDirection(const Ogre::Vector3& direction); @@ -185,6 +187,8 @@ namespace MWRender bool mMoonRed; + bool mIsStorm; + float mHour; int mDay; int mMonth; @@ -203,6 +207,8 @@ namespace MWRender Ogre::SceneNode* mAtmosphereDay; Ogre::SceneNode* mAtmosphereNight; + Ogre::SceneNode* mCloudNode; + std::vector mObjects; Ogre::SceneNode* mParticleNode; @@ -211,6 +217,8 @@ namespace MWRender std::map mRainModels; float mRainTimer; + Ogre::Vector3 mStormDirection; + // remember some settings so we don't have to apply them again if they didnt change Ogre::String mClouds; Ogre::String mNextClouds; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index e2862eb87..fb45cb034 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -115,7 +115,8 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fa mHour(14), mCurrentWeather("clear"), mNextWeather(""), mFirstUpdate(true), mWeatherUpdateTime(0), mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0), mRemainingTransitionTime(0), - mTimePassed(0), mFallback(fallback), mWindSpeed(0.f), mRendering(rendering), mIsStorm(false) + mTimePassed(0), mFallback(fallback), mWindSpeed(0.f), mRendering(rendering), mIsStorm(false), + mStormDirection(0,1,0) { //Globals mThunderSoundID0 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_0"); @@ -389,6 +390,17 @@ void WeatherManager::update(float duration) mWindSpeed = mResult.mWindSpeed; mIsStorm = mResult.mIsStorm; + if (mIsStorm) + { + MWWorld::Ptr player = world->getPlayerPtr(); + Ogre::Vector3 playerPos (player.getRefData().getPosition().pos); + Ogre::Vector3 redMountainPos (19950, 72032, 27831); + + mStormDirection = (playerPos - redMountainPos); + mStormDirection.z = 0; + mRendering->getSkyManager()->setStormDirection(mStormDirection); + } + mRendering->configureFog(mResult.mFogDepth, mResult.mFogColor); // disable sun during night @@ -812,5 +824,5 @@ bool WeatherManager::isInStorm() const Ogre::Vector3 WeatherManager::getStormDirection() const { - return Ogre::Vector3(0,-1,0); + return mStormDirection; } diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 9693014a9..3cc58aa4c 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace ESM { @@ -202,6 +203,8 @@ namespace MWWorld float mHour; float mWindSpeed; bool mIsStorm; + Ogre::Vector3 mStormDirection; + MWWorld::Fallback* mFallback; void setFallbackWeather(Weather& weather,const std::string& name); MWRender::RenderingManager* mRendering; diff --git a/files/materials/clouds.shader b/files/materials/clouds.shader index b76f2ded7..d3e5f083c 100644 --- a/files/materials/clouds.shader +++ b/files/materials/clouds.shader @@ -3,25 +3,27 @@ #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM - shUniform(float4x4, view) @shAutoConstant(view, view_matrix) -shUniform(float4x4, projection) @shAutoConstant(projection, projection_matrix) + shUniform(float4x4, worldview) @shAutoConstant(worldview, worldview_matrix) + shUniform(float4x4, proj) @shAutoConstant(proj, projection_matrix) shVertexInput(float2, uv0) shOutput(float2, UV) shOutput(float, alphaFade) SH_START_PROGRAM { - float4x4 viewFixed = view; + float4x4 worldviewFixed = worldview; + #if !SH_GLSL - viewFixed[0][3] = 0; - viewFixed[1][3] = 0; - viewFixed[2][3] = 0; + worldviewFixed[0][3] = 0; + worldviewFixed[1][3] = 0; + worldviewFixed[2][3] = 0; #else - viewFixed[3][0] = 0; - viewFixed[3][1] = 0; - viewFixed[3][2] = 0; + worldviewFixed[3][0] = 0; + worldviewFixed[3][1] = 0; + worldviewFixed[3][2] = 0; #endif - shOutputPosition = shMatrixMult(projection, shMatrixMult(viewFixed, shInputPosition)); + + shOutputPosition = shMatrixMult(proj, shMatrixMult(worldviewFixed, shInputPosition)); UV = uv0; alphaFade = (shInputPosition.z <= 200.f) ? ((shInputPosition.z <= 100.f) ? 0.0 : 0.25) : 1.0; } diff --git a/files/materials/stars.shader b/files/materials/stars.shader index 33f22bd14..b84d37135 100644 --- a/files/materials/stars.shader +++ b/files/materials/stars.shader @@ -3,8 +3,8 @@ #ifdef SH_VERTEX_SHADER SH_BEGIN_PROGRAM - shUniform(float4x4, view) @shAutoConstant(view, view_matrix) -shUniform(float4x4, projection) @shAutoConstant(projection, projection_matrix) + shUniform(float4x4, worldview) @shAutoConstant(worldview, worldview_matrix) + shUniform(float4x4, proj) @shAutoConstant(proj, projection_matrix) shVertexInput(float2, uv0) shOutput(float2, UV) @@ -12,17 +12,18 @@ shUniform(float4x4, projection) @shAutoConstant(projection, projection_matrix) SH_START_PROGRAM { - float4x4 viewFixed = view; + float4x4 worldviewFixed = worldview; #if !SH_GLSL - viewFixed[0][3] = 0; - viewFixed[1][3] = 0; - viewFixed[2][3] = 0; + worldviewFixed[0][3] = 0; + worldviewFixed[1][3] = 0; + worldviewFixed[2][3] = 0; #else - viewFixed[3][0] = 0; - viewFixed[3][1] = 0; - viewFixed[3][2] = 0; + worldviewFixed[3][0] = 0; + worldviewFixed[3][1] = 0; + worldviewFixed[3][2] = 0; #endif - shOutputPosition = shMatrixMult(projection, shMatrixMult(viewFixed, shInputPosition)); + + shOutputPosition = shMatrixMult(proj, shMatrixMult(worldviewFixed, shInputPosition)); UV = uv0; fade = (shInputPosition.z > 50) ? 1 : 0;