Merge remote branch 'scrawl/weather'

actorid
Marc Zinnschlag 13 years ago
commit de41e1118a

@ -12,7 +12,8 @@ using namespace Ogre;
OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNode* sunNode) : OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNode* sunNode) :
mSunTotalAreaQuery(0), mSunVisibleAreaQuery(0), mSingleObjectQuery(0), mActiveQuery(0), mSunTotalAreaQuery(0), mSunVisibleAreaQuery(0), mSingleObjectQuery(0), mActiveQuery(0),
mDoQuery(0), mSunVisibility(0), mQuerySingleObjectStarted(false), mTestResult(false), mDoQuery(0), mSunVisibility(0), mQuerySingleObjectStarted(false), mTestResult(false),
mQuerySingleObjectRequested(false), mWasVisible(false), mObjectWasVisible(false), mDoQuery2(false) mQuerySingleObjectRequested(false), mWasVisible(false), mObjectWasVisible(false), mDoQuery2(false),
mBBNode(0)
{ {
mRendering = renderer; mRendering = renderer;
mSunNode = sunNode; mSunNode = sunNode;
@ -52,7 +53,8 @@ OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNod
matQueryVisible->setCullingMode(CULL_NONE); matQueryVisible->setCullingMode(CULL_NONE);
matQueryVisible->setManualCullingMode(MANUAL_CULL_NONE); matQueryVisible->setManualCullingMode(MANUAL_CULL_NONE);
mBBNode = mSunNode->getParentSceneNode()->createChildSceneNode(); if (sunNode)
mBBNode = mSunNode->getParentSceneNode()->createChildSceneNode();
mObjectNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); mObjectNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode();
mBBNodeReal = mRendering->getScene()->getRootSceneNode()->createChildSceneNode(); mBBNodeReal = mRendering->getScene()->getRootSceneNode()->createChildSceneNode();
@ -182,10 +184,13 @@ void OcclusionQuery::update(float duration)
if (dist==0) dist = 10000000; if (dist==0) dist = 10000000;
dist -= 1000; // bias dist -= 1000; // bias
dist /= 1000.f; dist /= 1000.f;
mBBNode->setPosition(mSunNode->getPosition() * dist); if (mBBNode)
mBBNode->setScale(dist, dist, dist); {
mBBNodeReal->setPosition(mBBNode->_getDerivedPosition()); mBBNode->setPosition(mSunNode->getPosition() * dist);
mBBNodeReal->setScale(mBBNode->getScale()); mBBNode->setScale(dist, dist, dist);
mBBNodeReal->setPosition(mBBNode->_getDerivedPosition());
mBBNodeReal->setScale(mBBNode->getScale());
}
// Stop occlusion queries until we get their information // Stop occlusion queries until we get their information
// (may not happen on the same frame they are requested in) // (may not happen on the same frame they are requested in)
@ -245,6 +250,13 @@ bool OcclusionQuery::occlusionTestPending()
return (mQuerySingleObjectRequested || mQuerySingleObjectStarted); return (mQuerySingleObjectRequested || mQuerySingleObjectStarted);
} }
void OcclusionQuery::setSunNode(Ogre::SceneNode* node)
{
mSunNode = node;
if (!mBBNode)
mBBNode = node->getParentSceneNode()->createChildSceneNode();
}
bool OcclusionQuery::getTestResult() bool OcclusionQuery::getTestResult()
{ {
assert( !occlusionTestPending() assert( !occlusionTestPending()

@ -53,6 +53,8 @@ namespace MWRender
float getSunVisibility() const {return mSunVisibility;}; float getSunVisibility() const {return mSunVisibility;};
void setSunNode(Ogre::SceneNode* node);
private: private:
Ogre::HardwareOcclusionQuery* mSunTotalAreaQuery; Ogre::HardwareOcclusionQuery* mSunTotalAreaQuery;
Ogre::HardwareOcclusionQuery* mSunVisibleAreaQuery; Ogre::HardwareOcclusionQuery* mSunVisibleAreaQuery;

@ -201,6 +201,8 @@ void RenderingManager::skyEnable ()
{ {
if(mSkyManager) if(mSkyManager)
mSkyManager->enable(); mSkyManager->enable();
mOcclusionQuery->setSunNode(mSkyManager->getSunNode());
} }
void RenderingManager::skyDisable () void RenderingManager::skyDisable ()

@ -325,14 +325,17 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera, MWWorld::Environmen
, mSunEnabled(true) , mSunEnabled(true)
, mMasserEnabled(true) , mMasserEnabled(true)
, mSecundaEnabled(true) , mSecundaEnabled(true)
, mCreated(false)
{ {
mViewport = pCamera->getViewport(); mViewport = pCamera->getViewport();
mSceneMgr = pMwRoot->getCreator(); mSceneMgr = pMwRoot->getCreator();
mRootNode = pCamera->getParentSceneNode()->createChildSceneNode(); mRootNode = pCamera->getParentSceneNode()->createChildSceneNode();
mRootNode->pitch(Degree(-90)); // convert MW to ogre coordinates mRootNode->pitch(Degree(-90)); // convert MW to ogre coordinates
mRootNode->setInheritOrientation(false); mRootNode->setInheritOrientation(false);
}
void SkyManager::create()
{
/// \todo preload all the textures and meshes that are used for sky rendering /// \todo preload all the textures and meshes that are used for sky rendering
// Create overlay used for thunderstorm // Create overlay used for thunderstorm
@ -533,7 +536,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera, MWWorld::Environmen
" uniform float4 emissive \n" " uniform float4 emissive \n"
") \n" ") \n"
"{ \n" "{ \n"
" uv += float2(1,0) * time * speed * 0.003; \n" // Scroll in x direction " uv += float2(0,1) * time * speed * 0.003; \n" // Scroll in y direction
" float4 tex = lerp(tex2D(texture, uv), tex2D(secondTexture, uv), transitionFactor); \n" " float4 tex = lerp(tex2D(texture, uv), tex2D(secondTexture, uv), transitionFactor); \n"
" oColor = color * float4(emissive.xyz,1) * tex * float4(1,1,1,opacity); \n" " oColor = color * float4(emissive.xyz,1) * tex * float4(1,1,1,opacity); \n"
"}"; "}";
@ -562,6 +565,8 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera, MWWorld::Environmen
mCloudMaterial->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA); mCloudMaterial->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
mCloudMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(""); mCloudMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("");
mCreated = true;
} }
SkyManager::~SkyManager() SkyManager::~SkyManager()
@ -574,11 +579,13 @@ SkyManager::~SkyManager()
int SkyManager::getMasserPhase() const int SkyManager::getMasserPhase() const
{ {
if (!mCreated) return 0;
return mMasser->getPhaseInt(); return mMasser->getPhaseInt();
} }
int SkyManager::getSecundaPhase() const int SkyManager::getSecundaPhase() const
{ {
if (!mCreated) return 0;
return mSecunda->getPhaseInt(); return mSecunda->getPhaseInt();
} }
@ -631,6 +638,9 @@ void SkyManager::update(float duration)
void SkyManager::enable() void SkyManager::enable()
{ {
if (!mCreated)
create();
mRootNode->setVisible(true); mRootNode->setVisible(true);
mEnabled = true; mEnabled = true;
} }
@ -654,6 +664,7 @@ void SkyManager::setCloudsOpacity(float opacity)
void SkyManager::setWeather(const MWWorld::WeatherResult& weather) void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
{ {
if (!mCreated) return;
if (mClouds != weather.mCloudTexture) if (mClouds != weather.mCloudTexture)
{ {
mCloudMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("textures\\"+weather.mCloudTexture); mCloudMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("textures\\"+weather.mCloudTexture);
@ -750,17 +761,20 @@ void SkyManager::sunDisable()
void SkyManager::setSunDirection(const Vector3& direction) void SkyManager::setSunDirection(const Vector3& direction)
{ {
if (!mCreated) return;
mSun->setPosition(direction); mSun->setPosition(direction);
mSunGlare->setPosition(direction); mSunGlare->setPosition(direction);
} }
void SkyManager::setMasserDirection(const Vector3& direction) void SkyManager::setMasserDirection(const Vector3& direction)
{ {
if (!mCreated) return;
mMasser->setPosition(direction); mMasser->setPosition(direction);
} }
void SkyManager::setSecundaDirection(const Vector3& direction) void SkyManager::setSecundaDirection(const Vector3& direction)
{ {
if (!mCreated) return;
mSecunda->setPosition(direction); mSecunda->setPosition(direction);
} }
@ -786,6 +800,7 @@ void SkyManager::secundaDisable()
void SkyManager::setThunder(const float factor) void SkyManager::setThunder(const float factor)
{ {
if (!mCreated) return;
if (factor > 0.f) if (factor > 0.f)
{ {
mThunderOverlay->show(); mThunderOverlay->show();
@ -818,5 +833,6 @@ void SkyManager::setDate(int day, int month)
Ogre::SceneNode* SkyManager::getSunNode() Ogre::SceneNode* SkyManager::getSunNode()
{ {
if (!mCreated) return 0;
return mSun->getNode(); return mSun->getNode();
} }

@ -112,6 +112,9 @@ namespace MWRender
void update(float duration); void update(float duration);
void create();
///< no need to call this, automatically done on first enable()
void enable(); void enable();
void disable(); void disable();
@ -164,8 +167,10 @@ namespace MWRender
void setGlare(const float glare); void setGlare(const float glare);
Ogre::Vector3 getRealSunPos(); Ogre::Vector3 getRealSunPos();
private: private:
bool mCreated;
MWWorld::Environment* mEnvironment; MWWorld::Environment* mEnvironment;
float mHour; float mHour;
int mDay; int mDay;

@ -146,10 +146,10 @@ namespace MWWorld
mRendering->skySetDate (mGlobalVariables->getInt ("day"), mRendering->skySetDate (mGlobalVariables->getInt ("day"),
mGlobalVariables->getInt ("month")); mGlobalVariables->getInt ("month"));
mRendering->getSkyManager()->enable(); mRendering->skyEnable();
} }
else else
mRendering->getSkyManager()->disable(); mRendering->skyDisable();
} }
World::World (OEngine::Render::OgreRenderer& renderer, World::World (OEngine::Render::OgreRenderer& renderer,

Loading…
Cancel
Save