1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwrender/fogmanager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
3.3 KiB
C++
Raw Normal View History

2020-06-07 10:35:33 +04:00
#include "fogmanager.hpp"
#include <algorithm>
2023-01-27 18:40:15 +01:00
#include <components/esm/esmbridge.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm4/loadcell.hpp>
2020-06-07 10:35:33 +04:00
#include <components/fallback/fallback.hpp>
#include <components/sceneutil/util.hpp>
2023-06-15 21:59:06 +02:00
#include <components/settings/values.hpp>
2020-06-07 10:35:33 +04:00
#include "apps/openmw/mwworld/cell.hpp"
2020-06-07 10:35:33 +04:00
namespace MWRender
{
FogManager::FogManager()
: mLandFogStart(0.f)
, mLandFogEnd(std::numeric_limits<float>::max())
, mUnderwaterFogStart(0.f)
, mUnderwaterFogEnd(std::numeric_limits<float>::max())
, mFogColor(osg::Vec4f())
, mUnderwaterColor(Fallback::Map::getColour("Water_UnderwaterColor"))
, mUnderwaterWeight(Fallback::Map::getFloat("Water_UnderwaterColorWeight"))
, mUnderwaterIndoorFog(Fallback::Map::getFloat("Water_UnderwaterIndoorFog"))
{
}
void FogManager::configure(float viewDistance, const MWWorld::Cell& cell)
2020-06-07 10:35:33 +04:00
{
osg::Vec4f color = SceneUtil::colourFromRGB(cell.getMood().mFogColor);
const float fogDensity = cell.getMood().mFogDensity;
2023-06-15 21:59:06 +02:00
if (Settings::fog().mUseDistantFog)
2020-06-07 10:35:33 +04:00
{
float density = std::max(0.2f, fogDensity);
2023-06-15 21:59:06 +02:00
mLandFogStart = Settings::fog().mDistantInteriorFogEnd * (1.0f - density)
+ Settings::fog().mDistantInteriorFogStart * density;
mLandFogEnd = Settings::fog().mDistantInteriorFogEnd;
mUnderwaterFogStart = Settings::fog().mDistantUnderwaterFogStart;
mUnderwaterFogEnd = Settings::fog().mDistantUnderwaterFogEnd;
2020-06-07 10:35:33 +04:00
mFogColor = color;
}
else
configure(viewDistance, fogDensity, mUnderwaterIndoorFog, 1.0f, 0.0f, color);
2020-06-07 10:35:33 +04:00
}
void FogManager::configure(float viewDistance, float fogDepth, float underwaterFog, float dlFactor, float dlOffset,
const osg::Vec4f& color)
{
2023-06-15 21:59:06 +02:00
if (Settings::fog().mUseDistantFog)
2020-06-07 10:35:33 +04:00
{
2023-06-15 21:59:06 +02:00
mLandFogStart
= dlFactor * (Settings::fog().mDistantLandFogStart - dlOffset * Settings::fog().mDistantLandFogEnd);
mLandFogEnd = dlFactor * (1.0f - dlOffset) * Settings::fog().mDistantLandFogEnd;
mUnderwaterFogStart = Settings::fog().mDistantUnderwaterFogStart;
mUnderwaterFogEnd = Settings::fog().mDistantUnderwaterFogEnd;
2020-06-07 10:35:33 +04:00
}
else
{
if (fogDepth == 0.0)
{
mLandFogStart = 0.0f;
mLandFogEnd = std::numeric_limits<float>::max();
}
else
{
mLandFogStart = viewDistance * (1 - fogDepth);
mLandFogEnd = viewDistance;
}
mUnderwaterFogStart = std::min(viewDistance, 7168.f) * (1 - underwaterFog);
mUnderwaterFogEnd = std::min(viewDistance, 7168.f);
2020-06-07 10:35:33 +04:00
}
mFogColor = color;
}
float FogManager::getFogStart(bool isUnderwater) const
{
return isUnderwater ? mUnderwaterFogStart : mLandFogStart;
}
float FogManager::getFogEnd(bool isUnderwater) const
{
return isUnderwater ? mUnderwaterFogEnd : mLandFogEnd;
}
osg::Vec4f FogManager::getFogColor(bool isUnderwater) const
{
if (isUnderwater)
{
return mUnderwaterColor * mUnderwaterWeight + mFogColor * (1.f - mUnderwaterWeight);
}
return mFogColor;
}
}