summaryrefslogtreecommitdiff
path: root/indra/newview/llenvironment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llenvironment.cpp')
-rw-r--r--indra/newview/llenvironment.cpp225
1 files changed, 164 insertions, 61 deletions
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index 228a396c0d..3b0bc4cd55 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -56,6 +56,8 @@
#include <boost/make_shared.hpp>
+#include "llatmosphere.h"
+
//define EXPORT_PRESETS 1
//=========================================================================
namespace
@@ -123,8 +125,8 @@ namespace
class LLTrackBlenderLoopingTime : public LLSettingsBlenderTimeDelta
{
public:
- LLTrackBlenderLoopingTime(const LLSettingsBase::ptr_t &target, const LLSettingsDay::ptr_t &day, S32 trackno, F64Seconds cyclelength, F64Seconds cycleoffset) :
- LLSettingsBlenderTimeDelta(target, LLSettingsBase::ptr_t(), LLSettingsBase::ptr_t(), F64Seconds(1.0)),
+ LLTrackBlenderLoopingTime(const LLSettingsBase::ptr_t &target, const LLSettingsDay::ptr_t &day, S32 trackno, LLSettingsBase::Seconds cyclelength, LLSettingsBase::Seconds cycleoffset) :
+ LLSettingsBlenderTimeDelta(target, LLSettingsBase::ptr_t(), LLSettingsBase::ptr_t(), LLSettingsBase::Seconds(1.0)),
mDay(day),
mTrackNo(0),
mCycleLength(cyclelength),
@@ -154,7 +156,7 @@ namespace
mTrackTransitionStart = mTarget->buildDerivedClone();
mTrackNo = use_trackno;
- F64Seconds now = getAdjustedNow() + LLEnvironment::TRANSITION_ALTITUDE;
+ LLSettingsBase::Seconds now = getAdjustedNow() + LLEnvironment::TRANSITION_ALTITUDE;
LLSettingsDay::TrackBound_t bounds = getBoundingEntries(now);
LLSettingsBase::ptr_t pendsetting = (*bounds.first).second->buildDerivedClone();
@@ -187,7 +189,7 @@ namespace
return 1;
}
- LLSettingsDay::TrackBound_t getBoundingEntries(F64Seconds time)
+ LLSettingsDay::TrackBound_t getBoundingEntries(LLSettingsBase::Seconds time)
{
LLSettingsDay::CycleTrack_t &wtrack = mDay->getCycleTrack(mTrackNo);
F64 position = convertTimeToPosition(time);
@@ -196,19 +198,19 @@ namespace
return bounds;
}
- F64Seconds getAdjustedNow() const
+ LLSettingsBase::Seconds getAdjustedNow() const
{
- F64Seconds now(LLDate::now().secondsSinceEpoch());
+ LLSettingsBase::Seconds now(LLDate::now().secondsSinceEpoch());
return (now + mCycleOffset);
}
- F64Seconds getSpanTime(const LLSettingsDay::TrackBound_t &bounds) const
+ LLSettingsBase::Seconds getSpanTime(const LLSettingsDay::TrackBound_t &bounds) const
{
return mCycleLength * get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
}
- F64 convertTimeToPosition(F64Seconds time)
+ F64 convertTimeToPosition(LLSettingsBase::Seconds time)
{
F64 position = static_cast<F64>(fmod(time.value(), mCycleLength.value())) / static_cast<F64>(mCycleLength.value());
return llclamp(position, 0.0, 1.0);
@@ -217,14 +219,14 @@ namespace
private:
LLSettingsDay::ptr_t mDay;
S32 mTrackNo;
- F64Seconds mCycleLength;
- F64Seconds mCycleOffset;
+ LLSettingsBase::Seconds mCycleLength;
+ LLSettingsBase::Seconds mCycleOffset;
LLSettingsBase::ptr_t mTrackTransitionStart;
void onFinishedSpan()
{
LLSettingsDay::TrackBound_t next = getBoundingEntries(getAdjustedNow());
- F64Seconds nextspan = getSpanTime(next);
+ LLSettingsBase::Seconds nextspan = getSpanTime(next);
reset((*next.first).second, (*next.second).second, nextspan.value());
}
};
@@ -249,7 +251,6 @@ const LLUUID LLEnvironment::KNOWN_SKY_SUNSET("06420773-757b-4b7c-a1f9-85fceb2f7b
const LLUUID LLEnvironment::KNOWN_SKY_MIDNIGHT("c13658f3-91b8-d559-3a12-b11ce3940c4c");
const F32 LLEnvironment::SUN_DELTA_YAW(F_PI); // 180deg
-const F32 LLEnvironment::NIGHTTIME_ELEVATION_COS(LLSky::NIGHTTIME_ELEVATION_COS);
//-------------------------------------------------------------------------
LLEnvironment::LLEnvironment():
@@ -318,6 +319,56 @@ bool LLEnvironment::canEdit() const
return true;
}
+void LLEnvironment::getAtmosphericModelSettings(AtmosphericModelSettings& settingsOut, const LLSettingsSky::ptr_t &psky)
+{
+ settingsOut.m_skyBottomRadius = psky->getSkyBottomRadius();
+ settingsOut.m_skyTopRadius = psky->getSkyTopRadius();
+ settingsOut.m_sunArcRadians = psky->getSunArcRadians();
+ settingsOut.m_mieAnisotropy = psky->getMieAnisotropy();
+
+ LLSD rayleigh = psky->getRayleighConfigs();
+ settingsOut.m_rayleighProfile.clear();
+ for (LLSD::array_iterator itf = rayleigh.beginArray(); itf != rayleigh.endArray(); ++itf)
+ {
+ atmosphere::DensityProfileLayer layer;
+ LLSD& layerConfig = (*itf);
+ layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal();
+ layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal();
+ layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal();
+ layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal();
+ layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal();
+ settingsOut.m_rayleighProfile.push_back(layer);
+ }
+
+ LLSD mie = psky->getMieConfigs();
+ settingsOut.m_mieProfile.clear();
+ for (LLSD::array_iterator itf = mie.beginArray(); itf != mie.endArray(); ++itf)
+ {
+ atmosphere::DensityProfileLayer layer;
+ LLSD& layerConfig = (*itf);
+ layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal();
+ layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal();
+ layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal();
+ layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal();
+ layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal();
+ settingsOut.m_mieProfile.push_back(layer);
+ }
+
+ LLSD absorption = psky->getAbsorptionConfigs();
+ settingsOut.m_absorptionProfile.clear();
+ for (LLSD::array_iterator itf = absorption.beginArray(); itf != absorption.endArray(); ++itf)
+ {
+ atmosphere::DensityProfileLayer layer;
+ LLSD& layerConfig = (*itf);
+ layer.constant_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM].asReal();
+ layer.exp_scale = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR].asReal();
+ layer.exp_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM].asReal();
+ layer.linear_term = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM].asReal();
+ layer.width = layerConfig[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH].asReal();
+ settingsOut.m_absorptionProfile.push_back(layer);
+ }
+}
+
bool LLEnvironment::isExtendedEnvironmentEnabled() const
{
return !gAgent.getRegionCapability("ExtEnvironment").empty();
@@ -390,13 +441,18 @@ F32 LLEnvironment::getWaterHeight() const
return gAgent.getRegion()->getWaterHeight();
}
-bool LLEnvironment::getIsDayTime() const
+bool LLEnvironment::getIsSunUp() const
+{
+ return mCurrentEnvironment->getSky()->getIsSunUp();
+}
+
+bool LLEnvironment::getIsMoonUp() const
{
- return mCurrentEnvironment->getSky()->getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS;
+ return mCurrentEnvironment->getSky()->getIsMoonUp();
}
//-------------------------------------------------------------------------
-void LLEnvironment::setSelectedEnvironment(LLEnvironment::EnvSelection_t env, F64Seconds transition, bool forced)
+void LLEnvironment::setSelectedEnvironment(LLEnvironment::EnvSelection_t env, LLSettingsBase::Seconds transition, bool forced)
{
mSelectedEnvironment = env;
updateEnvironment(transition, forced);
@@ -426,7 +482,7 @@ LLEnvironment::DayInstance::ptr_t LLEnvironment::getEnvironmentInstance(LLEnviro
}
-void LLEnvironment::setEnvironment(LLEnvironment::EnvSelection_t env, const LLSettingsDay::ptr_t &pday, S64Seconds daylength, S64Seconds dayoffset)
+void LLEnvironment::setEnvironment(LLEnvironment::EnvSelection_t env, const LLSettingsDay::ptr_t &pday, LLSettingsDay::Seconds daylength, LLSettingsDay::Seconds dayoffset)
{
if ((env < ENV_EDIT) || (env >= ENV_DEFAULT))
{
@@ -479,8 +535,8 @@ void LLEnvironment::setEnvironment(LLEnvironment::EnvSelection_t env, const LLSe
if (settings->getSettingType() == "daycycle")
{
- S64Seconds daylength(LLSettingsDay::DEFAULT_DAYLENGTH);
- S64Seconds dayoffset(LLSettingsDay::DEFAULT_DAYOFFSET);
+ LLSettingsDay::Seconds daylength(LLSettingsDay::DEFAULT_DAYLENGTH);
+ LLSettingsDay::Seconds dayoffset(LLSettingsDay::DEFAULT_DAYOFFSET);
if (environment)
{
daylength = environment->getDayLength();
@@ -556,12 +612,12 @@ LLSettingsDay::ptr_t LLEnvironment::getEnvironmentDay(LLEnvironment::EnvSelectio
return LLSettingsDay::ptr_t();
}
-S64Seconds LLEnvironment::getEnvironmentDayLength(EnvSelection_t env)
+LLSettingsDay::Seconds LLEnvironment::getEnvironmentDayLength(EnvSelection_t env)
{
if ((env < ENV_EDIT) || (env > ENV_DEFAULT))
{
LL_WARNS("ENVIRONMENT") << "Attempt to retrieve invalid environment selection." << LL_ENDL;
- return S64Seconds(0);
+ return LLSettingsDay::Seconds(0);
}
DayInstance::ptr_t environment = getEnvironmentInstance(env);
@@ -569,22 +625,22 @@ S64Seconds LLEnvironment::getEnvironmentDayLength(EnvSelection_t env)
if (environment)
return environment->getDayLength();
- return S64Seconds(0);
+ return LLSettingsDay::Seconds(0);
}
-S64Seconds LLEnvironment::getEnvironmentDayOffset(EnvSelection_t env)
+LLSettingsDay::Seconds LLEnvironment::getEnvironmentDayOffset(EnvSelection_t env)
{
if ((env < ENV_EDIT) || (env > ENV_DEFAULT))
{
LL_WARNS("ENVIRONMENT") << "Attempt to retrieve invalid environment selection." << LL_ENDL;
- return S64Seconds(0);
+ return LLSettingsDay::Seconds(0);
}
DayInstance::ptr_t environment = getEnvironmentInstance(env);
if (environment)
return environment->getDayOffset();
- return S64Seconds(0);
+ return LLSettingsDay::Seconds(0);
}
@@ -643,7 +699,7 @@ LLEnvironment::DayInstance::ptr_t LLEnvironment::getSelectedEnvironmentInstance(
}
-void LLEnvironment::updateEnvironment(F64Seconds transition, bool forced)
+void LLEnvironment::updateEnvironment(LLSettingsBase::Seconds transition, bool forced)
{
DayInstance::ptr_t pinstance = getSelectedEnvironmentInstance();
@@ -658,6 +714,52 @@ void LLEnvironment::updateEnvironment(F64Seconds transition, bool forced)
}
}
+LLVector3 LLEnvironment::getLightDirection() const
+{
+ LLSettingsSky::ptr_t psky = mCurrentEnvironment->getSky();
+ if (!psky)
+ {
+ return LLVector3(0, 0, 1);
+ }
+ return psky->getLightDirection();
+}
+
+LLVector4 LLEnvironment::toCFR(const LLVector3 vec) const
+{
+ LLVector4 vec_cfr(vec.mV[1], vec.mV[0], vec.mV[2], 0.0f);
+ return vec_cfr;
+}
+
+LLVector4 LLEnvironment::toLightNorm(const LLVector3 vec) const
+{
+ LLVector4 vec_ogl(vec.mV[1], vec.mV[2], vec.mV[0], 0.0f);
+ return vec_ogl;
+}
+
+LLVector4 LLEnvironment::getLightDirectionCFR() const
+{
+ LLVector3 light_direction = getLightDirection();
+ LLVector4 light_direction_cfr = toCFR(light_direction);
+ return light_direction_cfr;
+}
+
+LLVector4 LLEnvironment::getClampedLightNorm() const
+{
+ LLVector3 light_direction = getLightDirection();
+ if (light_direction.mV[2] < -0.1f)
+ {
+ light_direction.mV[2] = -0.1f;
+ }
+ return toLightNorm(light_direction);
+}
+
+LLVector4 LLEnvironment::getRotatedLightNorm() const
+{
+ LLVector3 light_direction = getLightDirection();
+ light_direction *= LLQuaternion(-mLastCamYaw, LLVector3(0.f, 1.f, 0.f));
+ return toLightNorm(light_direction);
+}
+
//-------------------------------------------------------------------------
void LLEnvironment::update(const LLViewerCamera * cam)
{
@@ -672,18 +774,14 @@ void LLEnvironment::update(const LLViewerCamera * cam)
// update clouds, sun, and general
updateCloudScroll();
- F32 camYaw = cam->getYaw();
+ // cache this for use in rotating the rotated light vec for shader param updates later...
+ mLastCamYaw = cam->getYaw() + SUN_DELTA_YAW;
stop_glerror();
// *TODO: potential optimization - this block may only need to be
// executed some of the time. For example for water shaders only.
{
- LLVector3 lightNorm3( getLightDirection() );
-
- lightNorm3 *= LLQuaternion(-(camYaw + SUN_DELTA_YAW), LLVector3(0.f, 1.f, 0.f));
- mRotatedLight = LLVector4(lightNorm3, 0.f);
-
LLViewerShaderMgr::shader_iter shaders_iter, end_shaders;
end_shaders = LLViewerShaderMgr::instance()->endShaders();
for (shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter)
@@ -722,12 +820,24 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
LLSettingsBase::parammapping_t params = psetting->getParameterMap();
for (auto &it: params)
{
- if (!psetting->mSettings.has(it.first))
+ LLSD value;
+
+ bool found_in_settings = psetting->mSettings.has(it.first);
+ bool found_in_legacy_settings = !found_in_settings && psetting->mSettings.has(LLSettingsSky::SETTING_LEGACY_HAZE) && psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE].has(it.first);
+
+ if (!found_in_settings && !found_in_legacy_settings)
continue;
- LLSD value = psetting->mSettings[it.first];
- LLSD::Type setting_type = value.type();
+ if (found_in_settings)
+ {
+ value = psetting->mSettings[it.first];
+ }
+ else if (found_in_legacy_settings)
+ {
+ value = psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE][it.first];
+ }
+ LLSD::Type setting_type = value.type();
stop_glerror();
switch (setting_type)
{
@@ -783,26 +893,10 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
void LLEnvironment::updateShaderUniforms(LLGLSLShader *shader)
{
if (gPipeline.canUseWindLightShaders())
- {
- updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
+ {
updateGLVariablesForSettings(shader, mCurrentEnvironment->getWater());
- }
-
- if (shader->mShaderGroup == LLGLSLShader::SG_DEFAULT)
- {
- stop_glerror();
- shader->uniform4fv(LLShaderMgr::LIGHTNORM, 1, mRotatedLight.mV);
- shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, 1, LLViewerCamera::getInstance()->getOrigin().mV);
- stop_glerror();
- }
- else if (shader->mShaderGroup == LLGLSLShader::SG_SKY)
- {
- stop_glerror();
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, getClampedLightDirection().mV);
- stop_glerror();
- }
-
- shader->uniform1f(LLShaderMgr::SCENE_LIGHT_STRENGTH, getSceneLightStrength());
+ updateGLVariablesForSettings(shader, mCurrentEnvironment->getSky());
+ }
}
LLEnvironment::list_name_id_t LLEnvironment::getSkyList() const
@@ -1300,9 +1394,9 @@ LLEnvironment::EnvironmentInfo::ptr_t LLEnvironment::EnvironmentInfo::extract(LL
if (environment.has("region_id"))
pinfo->mRegionId = environment["region_id"].asUUID();
if (environment.has("day_length"))
- pinfo->mDayLength = S64Seconds(environment["day_length"].asInteger());
+ pinfo->mDayLength = LLSettingsDay::Seconds(environment["day_length"].asInteger());
if (environment.has("day_offset"))
- pinfo->mDayOffset = S64Seconds(environment["day_offset"].asInteger());
+ pinfo->mDayOffset = LLSettingsDay::Seconds(environment["day_offset"].asInteger());
if (environment.has("day_hash"))
pinfo->mDayHash = environment["day_hash"].asInteger();
if (environment.has("day_cycle"))
@@ -1551,7 +1645,7 @@ LLEnvironment::DayInstance::DayInstance() :
mSkyTrack(1)
{ }
-void LLEnvironment::DayInstance::update(F64Seconds delta)
+void LLEnvironment::DayInstance::update(LLSettingsBase::Seconds delta)
{
if (!mInitialized)
initialize();
@@ -1567,7 +1661,7 @@ void LLEnvironment::DayInstance::update(F64Seconds delta)
// mWater->update();
}
-void LLEnvironment::DayInstance::setDay(const LLSettingsDay::ptr_t &pday, S64Seconds daylength, S64Seconds dayoffset)
+void LLEnvironment::DayInstance::setDay(const LLSettingsDay::ptr_t &pday, LLSettingsDay::Seconds daylength, LLSettingsDay::Seconds dayoffset)
{
if (mType == TYPE_FIXED)
LL_WARNS("ENVIRONMENT") << "Fixed day instance changed to Cycled" << LL_ENDL;
@@ -1596,7 +1690,15 @@ void LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
mInitialized = false;
mSky = psky;
+ mSky->update();
mBlenderSky.reset();
+
+ if (gAtmosphere)
+ {
+ AtmosphericModelSettings settings;
+ LLEnvironment::getAtmosphericModelSettings(settings, psky);
+ gAtmosphere->configureAtmosphericModel(settings);
+ }
}
void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater)
@@ -1607,6 +1709,7 @@ void LLEnvironment::DayInstance::setWater(const LLSettingsWater::ptr_t &pwater)
mInitialized = false;
mWater = pwater;
+ mWater->update();
mBlenderWater.reset();
}
@@ -1649,7 +1752,7 @@ void LLEnvironment::DayInstance::setBlenders(const LLSettingsBlender::ptr_t &sky
mBlenderWater = waterblend;
}
-F64 LLEnvironment::DayInstance::secondsToKeyframe(S64Seconds seconds)
+F64 LLEnvironment::DayInstance::secondsToKeyframe(LLSettingsDay::Seconds seconds)
{
F64 frame = static_cast<F64>(seconds.value() % mDayLength.value()) / static_cast<F64>(mDayLength.value());
@@ -1658,7 +1761,7 @@ F64 LLEnvironment::DayInstance::secondsToKeyframe(S64Seconds seconds)
void LLEnvironment::DayInstance::animate()
{
- F64Seconds now(LLDate::now().secondsSinceEpoch());
+ LLSettingsBase::Seconds now(LLDate::now().secondsSinceEpoch());
now += mDayOffset;
@@ -1706,7 +1809,7 @@ void LLEnvironment::DayInstance::animate()
//-------------------------------------------------------------------------
LLEnvironment::DayTransition::DayTransition(const LLSettingsSky::ptr_t &skystart,
- const LLSettingsWater::ptr_t &waterstart, LLEnvironment::DayInstance::ptr_t &end, S64Seconds time) :
+ const LLSettingsWater::ptr_t &waterstart, LLEnvironment::DayInstance::ptr_t &end, LLSettingsDay::Seconds time) :
DayInstance(),
mStartSky(skystart),
mStartWater(waterstart),
@@ -1716,7 +1819,7 @@ LLEnvironment::DayTransition::DayTransition(const LLSettingsSky::ptr_t &skystart
}
-void LLEnvironment::DayTransition::update(F64Seconds delta)
+void LLEnvironment::DayTransition::update(LLSettingsBase::Seconds delta)
{
mNextInstance->update(delta);
DayInstance::update(delta);