mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 07:36:46 +00:00
- added night sky rendering with stars, nebulas, and fading in/out to sunset / sunrise
- changed WeatherGlobals members to static
This commit is contained in:
parent
9560904d8a
commit
0ebdce543a
5 changed files with 137 additions and 46 deletions
|
@ -302,7 +302,7 @@ void RenderingManager::sunDisable()
|
||||||
|
|
||||||
void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
|
void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
|
||||||
{
|
{
|
||||||
if (mSun) mSun->setPosition(direction);
|
if (mSun) mSun->setDirection(Vector3(direction.x, -direction.z, direction.y));
|
||||||
mSkyManager->setSunDirection(direction);
|
mSkyManager->setSunDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ void BillboardObject::init(const String& textureName,
|
||||||
/// \todo These billboards are not 100% correct, might want to revisit them later
|
/// \todo These billboards are not 100% correct, might want to revisit them later
|
||||||
mBBSet = sceneMgr->createBillboardSet("SkyBillboardSet"+StringConverter::toString(bodyCount), 1);
|
mBBSet = sceneMgr->createBillboardSet("SkyBillboardSet"+StringConverter::toString(bodyCount), 1);
|
||||||
mBBSet->setDefaultDimensions(scale, scale);
|
mBBSet->setDefaultDimensions(scale, scale);
|
||||||
mBBSet->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY+1);
|
mBBSet->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY+2);
|
||||||
mBBSet->setBillboardType(BBT_PERPENDICULAR_COMMON);
|
mBBSet->setBillboardType(BBT_PERPENDICULAR_COMMON);
|
||||||
mBBSet->setCommonDirection( -position.normalisedCopy() );
|
mBBSet->setCommonDirection( -position.normalisedCopy() );
|
||||||
mNode = rootNode->createChildSceneNode();
|
mNode = rootNode->createChildSceneNode();
|
||||||
|
@ -220,7 +220,7 @@ void Moon::setVisibility(const float pVisibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType)
|
void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType)
|
||||||
{
|
{
|
||||||
// Get the vertex colour buffer of this mesh
|
// Get the vertex colour buffer of this mesh
|
||||||
const Ogre::VertexElement* ves_diffuse = ent->getMesh()->getSubMesh(0)->vertexData->vertexDeclaration->findElementBySemantic( Ogre::VES_DIFFUSE );
|
const Ogre::VertexElement* ves_diffuse = ent->getMesh()->getSubMesh(0)->vertexData->vertexDeclaration->findElementBySemantic( Ogre::VES_DIFFUSE );
|
||||||
HardwareVertexBufferSharedPtr colourBuffer = ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource());
|
HardwareVertexBufferSharedPtr colourBuffer = ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource());
|
||||||
|
@ -282,6 +282,8 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) :
|
||||||
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);
|
||||||
|
|
||||||
|
/// \todo preload all the textures and meshes that are used for sky rendering
|
||||||
|
|
||||||
mViewport->setBackgroundColour(ColourValue(0.87, 0.87, 0.87));
|
mViewport->setBackgroundColour(ColourValue(0.87, 0.87, 0.87));
|
||||||
|
|
||||||
|
@ -299,15 +301,90 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) :
|
||||||
|
|
||||||
HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton();
|
HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton();
|
||||||
|
|
||||||
// Atmosphere
|
// Stars
|
||||||
MeshPtr mesh = NifOgre::NIFLoader::load("meshes\\sky_atmosphere.nif");
|
/// \todo sky_night_02.nif (available in Bloodmoon)
|
||||||
|
/// \todo how to make a transition between day and night sky?
|
||||||
|
MeshPtr mesh = NifOgre::NIFLoader::load("meshes\\sky_night_01.nif");
|
||||||
|
Entity* night1_ent = mSceneMgr->createEntity("meshes\\sky_night_01.nif");
|
||||||
|
night1_ent->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY+1);
|
||||||
|
|
||||||
|
ModVertexAlpha(night1_ent, 2);
|
||||||
|
|
||||||
|
mAtmosphereNight = mRootNode->createChildSceneNode();
|
||||||
|
mAtmosphereNight->attachObject(night1_ent);
|
||||||
|
|
||||||
|
for (unsigned int i=0; i<night1_ent->getNumSubEntities(); ++i)
|
||||||
|
{
|
||||||
|
MaterialPtr mp = night1_ent->getSubEntity(i)->getMaterial();
|
||||||
|
mp->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0);
|
||||||
|
mp->getTechnique(0)->getPass(0)->setAmbient(0.0, 0.0, 0.0);
|
||||||
|
mp->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, 1.0);
|
||||||
|
mp->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
|
||||||
|
mp->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
|
||||||
|
mp->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
|
||||||
|
|
||||||
|
mStarsMaterials[i] = mp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stars vertex shader
|
||||||
|
HighLevelGpuProgramPtr vshader3 = mgr.createProgram("Stars_VP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||||
|
"cg", GPT_VERTEX_PROGRAM);
|
||||||
|
vshader3->setParameter("profiles", "vs_2_x arbvp1");
|
||||||
|
vshader3->setParameter("entry_point", "main_vp");
|
||||||
|
StringUtil::StrStreamType outStream4;
|
||||||
|
outStream4 <<
|
||||||
|
"void main_vp( \n"
|
||||||
|
" float4 position : POSITION, \n"
|
||||||
|
" in float2 uv : TEXCOORD0, \n"
|
||||||
|
" out float2 oUV : TEXCOORD0, \n"
|
||||||
|
" out float oFade : TEXCOORD1, \n"
|
||||||
|
" out float4 oPosition : POSITION, \n"
|
||||||
|
" uniform float4x4 worldViewProj \n"
|
||||||
|
") \n"
|
||||||
|
"{ \n"
|
||||||
|
" oUV = uv; \n"
|
||||||
|
" oFade = (position.z > 50) ? 1.f : 0.f; \n"
|
||||||
|
" oPosition = mul( worldViewProj, position ); \n"
|
||||||
|
"}";
|
||||||
|
vshader3->setSource(outStream4.str());
|
||||||
|
vshader3->load();
|
||||||
|
vshader3->getDefaultParameters()->setNamedAutoConstant("worldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
|
||||||
|
night1_ent->getSubEntity(3)->getMaterial()->getTechnique(0)->getPass(0)->setVertexProgram(vshader3->getName());
|
||||||
|
|
||||||
|
// Stars fragment shader
|
||||||
|
HighLevelGpuProgramPtr stars_fp = mgr.createProgram("Stars_FP", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||||
|
"cg", GPT_FRAGMENT_PROGRAM);
|
||||||
|
stars_fp->setParameter("profiles", "ps_2_x arbfp1");
|
||||||
|
stars_fp->setParameter("entry_point", "main_fp");
|
||||||
|
StringUtil::StrStreamType outStream5;
|
||||||
|
outStream5 <<
|
||||||
|
"void main_fp( \n"
|
||||||
|
" in float2 uv : TEXCOORD0, \n"
|
||||||
|
" out float4 oColor : COLOR, \n"
|
||||||
|
" in float fade : TEXCOORD1, \n"
|
||||||
|
" uniform sampler2D texture : TEXUNIT0, \n"
|
||||||
|
" uniform float opacity, \n"
|
||||||
|
" uniform float4 diffuse, \n"
|
||||||
|
" uniform float4 emissive \n"
|
||||||
|
") \n"
|
||||||
|
"{ \n"
|
||||||
|
" oColor = tex2D(texture, uv) * float4(emissive.xyz, 1) * float4(1,1,1,fade*diffuse.a); \n"
|
||||||
|
"}";
|
||||||
|
stars_fp->setSource(outStream5.str());
|
||||||
|
stars_fp->load();
|
||||||
|
stars_fp->getDefaultParameters()->setNamedAutoConstant("emissive", GpuProgramParameters::ACT_SURFACE_EMISSIVE_COLOUR);
|
||||||
|
stars_fp->getDefaultParameters()->setNamedAutoConstant("diffuse", GpuProgramParameters::ACT_SURFACE_DIFFUSE_COLOUR);
|
||||||
|
night1_ent->getSubEntity(3)->getMaterial()->getTechnique(0)->getPass(0)->setFragmentProgram(stars_fp->getName());
|
||||||
|
|
||||||
|
// Atmosphere (day)
|
||||||
|
mesh = NifOgre::NIFLoader::load("meshes\\sky_atmosphere.nif");
|
||||||
Entity* atmosphere_ent = mSceneMgr->createEntity("meshes\\sky_atmosphere.nif");
|
Entity* atmosphere_ent = mSceneMgr->createEntity("meshes\\sky_atmosphere.nif");
|
||||||
|
|
||||||
ModVertexAlpha(atmosphere_ent, 0);
|
ModVertexAlpha(atmosphere_ent, 0);
|
||||||
|
|
||||||
atmosphere_ent->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY);
|
atmosphere_ent->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY);
|
||||||
Ogre::SceneNode* atmosphere_node = mRootNode->createChildSceneNode();
|
mAtmosphereDay = mRootNode->createChildSceneNode();
|
||||||
atmosphere_node->attachObject(atmosphere_ent);
|
mAtmosphereDay->attachObject(atmosphere_ent);
|
||||||
mAtmosphereMaterial = atmosphere_ent->getSubEntity(0)->getMaterial();
|
mAtmosphereMaterial = atmosphere_ent->getSubEntity(0)->getMaterial();
|
||||||
|
|
||||||
// Atmosphere shader
|
// Atmosphere shader
|
||||||
|
@ -341,7 +418,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) :
|
||||||
// Clouds
|
// Clouds
|
||||||
NifOgre::NIFLoader::load("meshes\\sky_clouds_01.nif");
|
NifOgre::NIFLoader::load("meshes\\sky_clouds_01.nif");
|
||||||
Entity* clouds_ent = mSceneMgr->createEntity("meshes\\sky_clouds_01.nif");
|
Entity* clouds_ent = mSceneMgr->createEntity("meshes\\sky_clouds_01.nif");
|
||||||
clouds_ent->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY+2);
|
clouds_ent->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY+3);
|
||||||
SceneNode* clouds_node = mRootNode->createChildSceneNode();
|
SceneNode* clouds_node = mRootNode->createChildSceneNode();
|
||||||
clouds_node->attachObject(clouds_ent);
|
clouds_node->attachObject(clouds_ent);
|
||||||
mCloudMaterial = clouds_ent->getSubEntity(0)->getMaterial();
|
mCloudMaterial = clouds_ent->getSubEntity(0)->getMaterial();
|
||||||
|
@ -411,8 +488,7 @@ SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera) :
|
||||||
mAtmosphereMaterial = mAtmosphereMaterial->clone("Atmosphere");
|
mAtmosphereMaterial = mAtmosphereMaterial->clone("Atmosphere");
|
||||||
atmosphere_ent->getSubEntity(0)->setMaterial(mAtmosphereMaterial);
|
atmosphere_ent->getSubEntity(0)->setMaterial(mAtmosphereMaterial);
|
||||||
|
|
||||||
// Default atmosphere color: light blue
|
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0);
|
||||||
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0.235, 0.5, 0.73);
|
|
||||||
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, 0.0);
|
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, 0.0);
|
||||||
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setAmbient(0.0, 0.0, 0.0);
|
mAtmosphereMaterial->getTechnique(0)->getPass(0)->setAmbient(0.0, 0.0, 0.0);
|
||||||
mCloudMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0);
|
mCloudMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1.0, 1.0, 1.0);
|
||||||
|
@ -446,9 +522,6 @@ void SkyManager::update(float duration)
|
||||||
{
|
{
|
||||||
// UV Scroll the clouds
|
// UV Scroll the clouds
|
||||||
mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstantFromTime("time", 1);
|
mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstantFromTime("time", 1);
|
||||||
|
|
||||||
mSunGlare->setVisible(mGlareEnabled && mSunEnabled && mEnabled);
|
|
||||||
mSun->setVisible(mSunEnabled && mEnabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyManager::enable()
|
void SkyManager::enable()
|
||||||
|
@ -458,6 +531,10 @@ void SkyManager::enable()
|
||||||
|
|
||||||
mSunGlare->setVisible(mGlareEnabled && mSunEnabled && mEnabled);
|
mSunGlare->setVisible(mGlareEnabled && mSunEnabled && mEnabled);
|
||||||
mSun->setVisible(mSunEnabled && mEnabled);
|
mSun->setVisible(mSunEnabled && mEnabled);
|
||||||
|
|
||||||
|
/// \todo
|
||||||
|
mMasser->setVisible(false);
|
||||||
|
mSecunda->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyManager::disable()
|
void SkyManager::disable()
|
||||||
|
@ -521,6 +598,15 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
||||||
mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("speed", Real(weather.mCloudSpeed));
|
mCloudMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("speed", Real(weather.mCloudSpeed));
|
||||||
mCloudSpeed = weather.mCloudSpeed;
|
mCloudSpeed = weather.mCloudSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (weather.mNight && mStarsOpacity != weather.mNightFade)
|
||||||
|
{
|
||||||
|
for (int i=0; i<7; ++i)
|
||||||
|
mStarsMaterials[i]->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, weather.mNightFade);
|
||||||
|
mStarsOpacity = weather.mNightFade;
|
||||||
|
}
|
||||||
|
|
||||||
|
mAtmosphereNight->setVisible(weather.mNight && mEnabled);
|
||||||
|
|
||||||
mViewport->setBackgroundColour(weather.mFogColor);
|
mViewport->setBackgroundColour(weather.mFogColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,18 +149,23 @@ namespace MWRender
|
||||||
Ogre::SceneNode* mRootNode;
|
Ogre::SceneNode* mRootNode;
|
||||||
Ogre::SceneManager* mSceneMgr;
|
Ogre::SceneManager* mSceneMgr;
|
||||||
|
|
||||||
|
Ogre::SceneNode* mAtmosphereDay;
|
||||||
|
Ogre::SceneNode* mAtmosphereNight;
|
||||||
|
|
||||||
Ogre::MaterialPtr mCloudMaterial;
|
Ogre::MaterialPtr mCloudMaterial;
|
||||||
Ogre::MaterialPtr mAtmosphereMaterial;
|
Ogre::MaterialPtr mAtmosphereMaterial;
|
||||||
|
|
||||||
|
Ogre::MaterialPtr mStarsMaterials[7];
|
||||||
|
|
||||||
Ogre::HighLevelGpuProgramPtr mCloudFragmentShader;
|
Ogre::HighLevelGpuProgramPtr mCloudFragmentShader;
|
||||||
|
|
||||||
// remember the cloud texture names used right now, so we don't have to set the texture names if they didnt change
|
// remember some settings so we don't have to apply them again if they didnt change
|
||||||
Ogre::String mClouds;
|
Ogre::String mClouds;
|
||||||
Ogre::String mNextClouds;
|
Ogre::String mNextClouds;
|
||||||
float mCloudBlendFactor;
|
float mCloudBlendFactor;
|
||||||
float mCloudOpacity;
|
float mCloudOpacity;
|
||||||
float mCloudSpeed;
|
float mCloudSpeed;
|
||||||
|
float mStarsOpacity;
|
||||||
Ogre::ColourValue mCloudColour;
|
Ogre::ColourValue mCloudColour;
|
||||||
Ogre::ColourValue mSkyColour;
|
Ogre::ColourValue mSkyColour;
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,6 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering, World* wor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
setWeather("clear", true);
|
setWeather("clear", true);
|
||||||
|
|
||||||
// Test transition
|
|
||||||
//setWeather("cloudy", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeatherManager::setWeather(const String& weather, bool instant)
|
void WeatherManager::setWeather(const String& weather, bool instant)
|
||||||
|
@ -116,35 +113,40 @@ WeatherResult WeatherManager::getResult(const String& weather)
|
||||||
result.mCloudSpeed = current.mCloudSpeed;
|
result.mCloudSpeed = current.mCloudSpeed;
|
||||||
result.mGlareView = current.mGlareView;
|
result.mGlareView = current.mGlareView;
|
||||||
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
result.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
|
||||||
|
|
||||||
const float fade_duration = 0.15 /*current.mTransitionDelta*/;
|
const float fade_duration = 0.15 /*current.mTransitionDelta*/;
|
||||||
|
|
||||||
|
result.mNight = (mHour < 6.f+fade_duration || mHour > 20.f-fade_duration);
|
||||||
|
|
||||||
// night
|
// night
|
||||||
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) || mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
|
if (mHour <= (WeatherGlobals::mSunriseTime-WeatherGlobals::mSunriseDuration)
|
||||||
|
|| mHour >= (WeatherGlobals::mSunsetTime+WeatherGlobals::mSunsetDuration))
|
||||||
{
|
{
|
||||||
result.mFogColor = current.mFogNightColor;
|
result.mFogColor = current.mFogNightColor;
|
||||||
result.mAmbientColor = current.mAmbientNightColor;
|
result.mAmbientColor = current.mAmbientNightColor;
|
||||||
result.mSunColor = current.mSunNightColor;
|
result.mSunColor = current.mSunNightColor;
|
||||||
result.mSkyColor = current.mSkyNightColor;
|
result.mSkyColor = current.mSkyNightColor;
|
||||||
|
result.mNightFade = 1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sunrise
|
// sunrise
|
||||||
else if (mHour >= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration) && mHour <= mGlobals.mSunriseTime)
|
else if (mHour >= (WeatherGlobals::mSunriseTime-WeatherGlobals::mSunriseDuration) && mHour <= WeatherGlobals::mSunriseTime)
|
||||||
{
|
{
|
||||||
if (mHour <= (mGlobals.mSunriseTime-mGlobals.mSunriseDuration+fade_duration))
|
if (mHour <= (WeatherGlobals::mSunriseTime-WeatherGlobals::mSunriseDuration+fade_duration))
|
||||||
{
|
{
|
||||||
// fade in
|
// fade in
|
||||||
float advance = (mGlobals.mSunriseTime-mGlobals.mSunriseDuration+fade_duration)-mHour;
|
float advance = (WeatherGlobals::mSunriseTime-WeatherGlobals::mSunriseDuration+fade_duration)-mHour;
|
||||||
float factor = (advance / fade_duration);
|
float factor = (advance / fade_duration);
|
||||||
result.mFogColor = lerp(current.mFogSunriseColor, current.mFogNightColor);
|
result.mFogColor = lerp(current.mFogSunriseColor, current.mFogNightColor);
|
||||||
result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientNightColor);
|
result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientNightColor);
|
||||||
result.mSunColor = lerp(current.mSunSunriseColor, current.mSunNightColor);
|
result.mSunColor = lerp(current.mSunSunriseColor, current.mSunNightColor);
|
||||||
result.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyNightColor);
|
result.mSkyColor = lerp(current.mSkySunriseColor, current.mSkyNightColor);
|
||||||
|
result.mNightFade = factor;
|
||||||
}
|
}
|
||||||
else if (mHour >= (mGlobals.mSunriseTime-fade_duration))
|
else if (mHour >= (WeatherGlobals::mSunriseTime-fade_duration))
|
||||||
{
|
{
|
||||||
// fade out
|
// fade out
|
||||||
float advance = mHour-(mGlobals.mSunriseTime-fade_duration);
|
float advance = mHour-(WeatherGlobals::mSunriseTime-fade_duration);
|
||||||
float factor = advance / fade_duration;
|
float factor = advance / fade_duration;
|
||||||
result.mFogColor = lerp(current.mFogSunriseColor, current.mFogDayColor);
|
result.mFogColor = lerp(current.mFogSunriseColor, current.mFogDayColor);
|
||||||
result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientDayColor);
|
result.mAmbientColor = lerp(current.mAmbientSunriseColor, current.mAmbientDayColor);
|
||||||
|
@ -161,7 +163,7 @@ WeatherResult WeatherManager::getResult(const String& weather)
|
||||||
}
|
}
|
||||||
|
|
||||||
// day
|
// day
|
||||||
else if (mHour >= (mGlobals.mSunriseTime) && mHour <= (mGlobals.mSunsetTime))
|
else if (mHour >= (WeatherGlobals::mSunriseTime) && mHour <= (WeatherGlobals::mSunsetTime))
|
||||||
{
|
{
|
||||||
result.mFogColor = current.mFogDayColor;
|
result.mFogColor = current.mFogDayColor;
|
||||||
result.mAmbientColor = current.mAmbientDayColor;
|
result.mAmbientColor = current.mAmbientDayColor;
|
||||||
|
@ -170,27 +172,28 @@ WeatherResult WeatherManager::getResult(const String& weather)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sunset
|
// sunset
|
||||||
else if (mHour >= (mGlobals.mSunsetTime) && mHour <= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration))
|
else if (mHour >= (WeatherGlobals::mSunsetTime) && mHour <= (WeatherGlobals::mSunsetTime+WeatherGlobals::mSunsetDuration))
|
||||||
{
|
{
|
||||||
if (mHour <= (mGlobals.mSunsetTime+fade_duration))
|
if (mHour <= (WeatherGlobals::mSunsetTime+fade_duration))
|
||||||
{
|
{
|
||||||
// fade in
|
// fade in
|
||||||
float advance = (mGlobals.mSunsetTime+fade_duration)-mHour;
|
float advance = (WeatherGlobals::mSunsetTime+fade_duration)-mHour;
|
||||||
float factor = (advance / fade_duration);
|
float factor = (advance / fade_duration);
|
||||||
result.mFogColor = lerp(current.mFogSunsetColor, current.mFogDayColor);
|
result.mFogColor = lerp(current.mFogSunsetColor, current.mFogDayColor);
|
||||||
result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientDayColor);
|
result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientDayColor);
|
||||||
result.mSunColor = lerp(current.mSunSunsetColor, current.mSunDayColor);
|
result.mSunColor = lerp(current.mSunSunsetColor, current.mSunDayColor);
|
||||||
result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyDayColor);
|
result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyDayColor);
|
||||||
}
|
}
|
||||||
else if (mHour >= (mGlobals.mSunsetTime+mGlobals.mSunsetDuration-fade_duration))
|
else if (mHour >= (WeatherGlobals::mSunsetTime+WeatherGlobals::mSunsetDuration-fade_duration))
|
||||||
{
|
{
|
||||||
// fade out
|
// fade out
|
||||||
float advance = mHour-(mGlobals.mSunsetTime+mGlobals.mSunsetDuration-fade_duration);
|
float advance = mHour-(WeatherGlobals::mSunsetTime+WeatherGlobals::mSunsetDuration-fade_duration);
|
||||||
float factor = advance / fade_duration;
|
float factor = advance / fade_duration;
|
||||||
result.mFogColor = lerp(current.mFogSunsetColor, current.mFogNightColor);
|
result.mFogColor = lerp(current.mFogSunsetColor, current.mFogNightColor);
|
||||||
result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientNightColor);
|
result.mAmbientColor = lerp(current.mAmbientSunsetColor, current.mAmbientNightColor);
|
||||||
result.mSunColor = lerp(current.mSunSunsetColor, current.mSunNightColor);
|
result.mSunColor = lerp(current.mSunSunsetColor, current.mSunNightColor);
|
||||||
result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyNightColor);
|
result.mSkyColor = lerp(current.mSkySunsetColor, current.mSkyNightColor);
|
||||||
|
result.mNightFade = factor;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -227,6 +230,8 @@ WeatherResult WeatherManager::transition(float factor)
|
||||||
result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity);
|
result.mCloudOpacity = lerp(current.mCloudOpacity, other.mCloudOpacity);
|
||||||
result.mGlareView = lerp(current.mGlareView, other.mGlareView);
|
result.mGlareView = lerp(current.mGlareView, other.mGlareView);
|
||||||
|
|
||||||
|
result.mNight = current.mNight;
|
||||||
|
|
||||||
// sound change behaviour:
|
// sound change behaviour:
|
||||||
// if 'other' has a new sound, switch to it after 1/2 of the transition length
|
// if 'other' has a new sound, switch to it after 1/2 of the transition length
|
||||||
if (other.mAmbientLoopSoundID != "")
|
if (other.mAmbientLoopSoundID != "")
|
||||||
|
@ -274,7 +279,8 @@ void WeatherManager::update(float duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable sun during night
|
// disable sun during night
|
||||||
if (mHour >= mGlobals.mSunsetTime+mGlobals.mSunsetDuration || mHour <= mGlobals.mSunriseTime-mGlobals.mSunriseDuration)
|
if (mHour >= WeatherGlobals::mSunsetTime+WeatherGlobals::mSunsetDuration
|
||||||
|
|| mHour <= WeatherGlobals::mSunriseTime-WeatherGlobals::mSunriseDuration)
|
||||||
mRendering->getSkyManager()->sunDisable();
|
mRendering->getSkyManager()->sunDisable();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,17 +68,10 @@ namespace MWWorld
|
||||||
Snow Low Kill=150
|
Snow Low Kill=150
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float mSunriseTime,
|
static const float mSunriseTime = 8;
|
||||||
mSunsetTime,
|
static const float mSunsetTime = 18;
|
||||||
mSunriseDuration,
|
static const float mSunriseDuration = 2;
|
||||||
mSunsetDuration;
|
static const float mSunsetDuration = 2;
|
||||||
|
|
||||||
WeatherGlobals() :
|
|
||||||
mSunriseTime(8),
|
|
||||||
mSunsetTime(18),
|
|
||||||
mSunriseDuration(2),
|
|
||||||
mSunsetDuration(2)
|
|
||||||
{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Defines the actual weather that results from weather setting (see below), time of day and weather transition
|
/// Defines the actual weather that results from weather setting (see below), time of day and weather transition
|
||||||
|
@ -108,6 +101,9 @@ namespace MWWorld
|
||||||
|
|
||||||
float mGlareView;
|
float mGlareView;
|
||||||
|
|
||||||
|
bool mNight; // use night skybox
|
||||||
|
float mNightFade; // fading factor for night skybox
|
||||||
|
|
||||||
Ogre::String mAmbientLoopSoundID;
|
Ogre::String mAmbientLoopSoundID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -208,9 +204,7 @@ namespace MWWorld
|
||||||
MWWorld::World* mWorld;
|
MWWorld::World* mWorld;
|
||||||
|
|
||||||
std::map<Ogre::String, Weather> mWeatherSettings;
|
std::map<Ogre::String, Weather> mWeatherSettings;
|
||||||
|
|
||||||
WeatherGlobals mGlobals;
|
|
||||||
|
|
||||||
Ogre::String mCurrentWeather;
|
Ogre::String mCurrentWeather;
|
||||||
Ogre::String mNextWeather;
|
Ogre::String mNextWeather;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue