SL-1476 EEP Better shader resets and transitions

master
andreykproductengine 2018-10-29 18:18:20 +02:00
parent e9faa3cce8
commit 659d14504f
7 changed files with 196 additions and 155 deletions

View File

@ -80,7 +80,7 @@ LLSettingsBase::LLSettingsBase(const LLSD setting) :
//=========================================================================
void LLSettingsBase::lerpSettings(const LLSettingsBase &other, F64 mix)
{
mSettings = interpolateSDMap(mSettings, other.mSettings, mix);
mSettings = interpolateSDMap(mSettings, other.mSettings, other.getParameterMap(), mix);
setDirtyFlag(true);
}
@ -158,7 +158,7 @@ LLSD LLSettingsBase::combineSDMaps(const LLSD &settings, const LLSD &other) cons
return newSettings;
}
LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F64 mix) const
LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, F64 mix) const
{
LLSD newSettings;
@ -173,81 +173,33 @@ LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F
if (skip.find(key_name) != skip.end())
continue;
if (!other.has(key_name))
{ // The other does not contain this setting, keep the original value
// TODO: Should I blend this out instead?
newSettings[key_name] = value;
continue;
}
LLSD::Type setting_type = value.type();
LLSD other_value = other[key_name];
if (other_value.type() != setting_type)
{
// The data type mismatched between this and other. Hard switch when we pass the break point
// but issue a warning.
LL_WARNS("SETTINGS") << "Setting lerp between mismatched types for '" << key_name << "'." << LL_ENDL;
newSettings[key_name] = (mix > BREAK_POINT) ? other_value : value;
continue;
}
switch (setting_type)
LLSD other_value;
if (other.has(key_name))
{
case LLSD::TypeInteger:
// lerp between the two values rounding the result to the nearest integer.
newSettings[key_name] = LLSD::Integer(llroundf(lerp(value.asReal(), other_value.asReal(), mix)));
break;
case LLSD::TypeReal:
// lerp between the two values.
newSettings[key_name] = LLSD::Real(lerp(value.asReal(), other_value.asReal(), mix));
break;
case LLSD::TypeMap:
// deep copy.
newSettings[key_name] = interpolateSDMap(value, other_value, mix);
break;
case LLSD::TypeArray:
{
LLSD newvalue(LLSD::emptyArray());
if (slerps.find(key_name) != slerps.end())
{
LLQuaternion a(value);
LLQuaternion b(other_value);
LLQuaternion q = slerp(mix, a, b);
newvalue = q.getValue();
}
else
{ // TODO: We could expand this to inspect the type and do a deep lerp based on type.
// for now assume a heterogeneous array of reals.
size_t len = std::max(value.size(), other_value.size());
for (size_t i = 0; i < len; ++i)
{
newvalue[i] = lerp(value[i].asReal(), other_value[i].asReal(), mix);
}
}
newSettings[key_name] = newvalue;
}
break;
case LLSD::TypeUUID:
newSettings[key_name] = value.asUUID();
break;
// case LLSD::TypeBoolean:
// case LLSD::TypeString:
// case LLSD::TypeURI:
// case LLSD::TypeBinary:
// case LLSD::TypeDate:
default:
// atomic or unknown data types. Lerping between them does not make sense so switch at the break.
newSettings[key_name] = (mix > BREAK_POINT) ? other_value : value;
break;
other_value = other[key_name];
}
else
{
parammapping_t::const_iterator def_iter = defaults.find(key_name);
if (def_iter != defaults.end())
{
other_value = def_iter->second.getDefaultValue();
}
else if (value.type() == LLSD::TypeMap)
{
// interpolate in case there are defaults inside (part of legacy)
other_value = LLSDMap();
}
else
{
// The other or defaults does not contain this setting, keep the original value
// TODO: Should I blend this out instead?
newSettings[key_name] = value;
continue;
}
}
newSettings[key_name] = interpolateSDValue(key_name, value, other_value, defaults, mix, slerps);
}
// Special handling cases
@ -263,6 +215,27 @@ LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F
// Now add anything that is in other but not in the settings
for (LLSD::map_const_iterator it = other.beginMap(); it != other.endMap(); ++it)
{
std::string key_name = (*it).first;
if (skip.find(key_name) != skip.end())
continue;
if (settings.has(key_name))
continue;
parammapping_t::const_iterator def_iter = defaults.find(key_name);
if (def_iter != defaults.end())
{
// Blend against default value
newSettings[key_name] = interpolateSDValue(key_name, def_iter->second.getDefaultValue(), (*it).second, defaults, mix, slerps);
}
// else do nothing when no known defaults
// TODO: Should I blend this out instead?
}
// Note: writes variables from skip list, bug?
for (LLSD::map_const_iterator it = other.beginMap(); it != other.endMap(); ++it)
{
// TODO: Should I blend this in instead?
if (skip.find((*it).first) == skip.end())
@ -277,6 +250,81 @@ LLSD LLSettingsBase::interpolateSDMap(const LLSD &settings, const LLSD &other, F
return newSettings;
}
LLSD LLSettingsBase::interpolateSDValue(const std::string& key_name, const LLSD &value, const LLSD &other_value, const parammapping_t& defaults, BlendFactor mix, const stringset_t& slerps) const
{
LLSD new_value;
LLSD::Type setting_type = value.type();
if (other_value.type() != setting_type)
{
// The data type mismatched between this and other. Hard switch when we pass the break point
// but issue a warning.
LL_WARNS("SETTINGS") << "Setting lerp between mismatched types for '" << key_name << "'." << LL_ENDL;
new_value = (mix > BREAK_POINT) ? other_value : value;
}
switch (setting_type)
{
case LLSD::TypeInteger:
// lerp between the two values rounding the result to the nearest integer.
new_value = LLSD::Integer(llroundf(lerp(value.asReal(), other_value.asReal(), mix)));
break;
case LLSD::TypeReal:
// lerp between the two values.
new_value = LLSD::Real(lerp(value.asReal(), other_value.asReal(), mix));
break;
case LLSD::TypeMap:
// deep copy.
new_value = interpolateSDMap(value, other_value, defaults, mix);
break;
case LLSD::TypeArray:
{
LLSD new_array(LLSD::emptyArray());
if (slerps.find(key_name) != slerps.end())
{
LLQuaternion a(value);
LLQuaternion b(other_value);
LLQuaternion q = slerp(mix, a, b);
new_array = q.getValue();
}
else
{ // TODO: We could expand this to inspect the type and do a deep lerp based on type.
// for now assume a heterogeneous array of reals.
size_t len = std::max(value.size(), other_value.size());
for (size_t i = 0; i < len; ++i)
{
new_array[i] = lerp(value[i].asReal(), other_value[i].asReal(), mix);
}
}
new_value = new_array;
}
break;
case LLSD::TypeUUID:
new_value = value.asUUID();
break;
// case LLSD::TypeBoolean:
// case LLSD::TypeString:
// case LLSD::TypeURI:
// case LLSD::TypeBinary:
// case LLSD::TypeDate:
default:
// atomic or unknown data types. Lerping between them does not make sense so switch at the break.
new_value = (mix > BREAK_POINT) ? other_value : value;
break;
}
return new_value;
}
LLSettingsBase::stringset_t LLSettingsBase::getSkipInterpolateKeys() const
{
static stringset_t skipSet;

View File

@ -76,7 +76,21 @@ public:
static const U32 FLAG_NOMOD;
static const U32 FLAG_NOTRANS;
typedef std::map<std::string, S32> parammapping_t;
class DefaultParam
{
public:
DefaultParam(S32 key, const LLSD& value) : mShaderKey(key), mDefaultValue(value) {}
DefaultParam() : mShaderKey(-1) {}
S32 getShaderKey() const { return mShaderKey; }
const LLSD getDefaultValue() const { return mDefaultValue; }
private:
S32 mShaderKey;
LLSD mDefaultValue;
};
// Contains settings' names (map key), related shader id-key and default
// value for revert in case we need to reset shader (no need to search each time)
typedef std::map<std::string, DefaultParam> parammapping_t;
typedef PTR_NAMESPACE::shared_ptr<LLSettingsBase> ptr_t;
@ -312,7 +326,15 @@ protected:
// combining settings objects. Customize for specific setting types
virtual void lerpSettings(const LLSettingsBase &other, BlendFactor mix);
LLSD interpolateSDMap(const LLSD &settings, const LLSD &other, BlendFactor mix) const;
// combining settings maps where it can based on mix rate
// @settings initial value (mix==0)
// @other target value (mix==1)
// @defaults list of default values for legacy fields and (re)setting shaders
// @mix from 0 to 1, ratio or rate of transition from initial 'settings' to 'other'
// return interpolated and combined LLSD map
LLSD interpolateSDMap(const LLSD &settings, const LLSD &other, const parammapping_t& defaults, BlendFactor mix) const;
LLSD interpolateSDValue(const std::string& name, const LLSD &value, const LLSD &other, const parammapping_t& defaults, BlendFactor mix, const stringset_t& slerps) const;
/// when lerping between settings, some may require special handling.
/// Get a list of these key to be skipped by the default settings lerp.

View File

@ -434,7 +434,14 @@ void LLSettingsSky::blend(const LLSettingsBase::ptr_t &end, F64 blendf)
LLSettingsSky::ptr_t other = PTR_NAMESPACE::dynamic_pointer_cast<LLSettingsSky>(end);
if (other)
{
LLSD blenddata = interpolateSDMap(mSettings, other->mSettings, blendf);
if (!mSettings.has(SETTING_LEGACY_HAZE) && !mSettings[SETTING_LEGACY_HAZE].has(SETTING_AMBIENT))
{
// Special case since SETTING_AMBIENT is both in outer and legacy maps, we prioritize legacy one
// see getAmbientColor()
setAmbientColor(getAmbientColor());
}
LLSD blenddata = interpolateSDMap(mSettings, other->mSettings, other->getParameterMap(), blendf);
replaceSettings(blenddata);
mNextSunTextureId = other->getSunTextureId();
mNextMoonTextureId = other->getMoonTextureId();
@ -945,6 +952,7 @@ LLVector3 LLSettingsSky::getLightDirection() const
LLColor3 LLSettingsSky::getAmbientColor() const
{
// Todo: this causes complications, preferably to get rid of this duality
if (mSettings.has(SETTING_LEGACY_HAZE) && mSettings[SETTING_LEGACY_HAZE].has(SETTING_AMBIENT))
{
return LLColor3(mSettings[SETTING_LEGACY_HAZE][SETTING_AMBIENT]);

View File

@ -178,7 +178,7 @@ void LLSettingsWater::blend(const LLSettingsBase::ptr_t &end, F64 blendf)
LLSettingsWater::ptr_t other = PTR_NAMESPACE::static_pointer_cast<LLSettingsWater>(end);
if (other)
{
LLSD blenddata = interpolateSDMap(mSettings, other->mSettings, blendf);
LLSD blenddata = interpolateSDMap(mSettings, other->mSettings, other->getParameterMap(), blendf);
replaceSettings(blenddata);
mNextNormalMapID = other->getNormalMapID();
mNextTransparentTextureID = other->getTransparentTextureID();

View File

@ -885,6 +885,7 @@ void LLEnvironment::updateCloudScroll()
}
// static
void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting)
{
LL_RECORD_BLOCK_TIME(FTM_SHADER_PARAM_UPDATE);
@ -894,62 +895,19 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
for (auto &it: params)
{
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)
{
value = psetting->mSettings[it.first];
}
else if (found_in_legacy_settings)
// legacy first since it contains ambient color and we prioritize value from legacy, see getAmbientColor()
if (psetting->mSettings.has(LLSettingsSky::SETTING_LEGACY_HAZE) && psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE].has(it.first))
{
value = psetting->mSettings[LLSettingsSky::SETTING_LEGACY_HAZE][it.first];
}
else if (psetting->getSettingsType() == "sky")
else if (psetting->mSettings.has(it.first))
{
// Legacy atmospherics is a special case,
// these values either have non zero defaults when they are not present
// in LLSD or need to be acounted for (reset) even if they are not present
// Todo: consider better options, for example make LLSettingsSky init these options
// Todo: we should reset shaders for all missing fields, not just these ones
LLSettingsSky::ptr_t skyp = std::static_pointer_cast<LLSettingsSky>(psetting);
if (it.first == LLSettingsSky::SETTING_BLUE_DENSITY)
{
value = skyp->getBlueDensity().getValue();
}
else if (it.first == LLSettingsSky::SETTING_BLUE_HORIZON)
{
value = skyp->getBlueHorizon().getValue();
}
else if (it.first == LLSettingsSky::SETTING_DENSITY_MULTIPLIER)
{
value = skyp->getDensityMultiplier();
}
else if (it.first == LLSettingsSky::SETTING_DISTANCE_MULTIPLIER)
{
value = skyp->getDistanceMultiplier();
}
else if (it.first == LLSettingsSky::SETTING_HAZE_DENSITY)
{
value = skyp->getHazeDensity();
}
else if (it.first == LLSettingsSky::SETTING_HAZE_HORIZON)
{
value = skyp->getHazeHorizon();
}
else if (it.first == LLSettingsSky::SETTING_AMBIENT)
{
value = skyp->getAmbientColor().getValue();
}
else
{
continue;
}
value = psetting->mSettings[it.first];
}
else
{
continue;
// We need to reset shaders, use defaults
value = it.second.getDefaultValue();
}
LLSD::Type setting_type = value.type();
@ -957,16 +915,16 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
switch (setting_type)
{
case LLSD::TypeInteger:
shader->uniform1i(it.second, value.asInteger());
shader->uniform1i(it.second.getShaderKey(), value.asInteger());
//_WARNS("RIDER") << "pushing '" << (*it).first << "' as " << value << LL_ENDL;
break;
case LLSD::TypeReal:
shader->uniform1f(it.second, value.asReal());
shader->uniform1f(it.second.getShaderKey(), value.asReal());
//_WARNS("RIDER") << "pushing '" << (*it).first << "' as " << value << LL_ENDL;
break;
case LLSD::TypeBoolean:
shader->uniform1i(it.second, value.asBoolean() ? 1 : 0);
shader->uniform1i(it.second.getShaderKey(), value.asBoolean() ? 1 : 0);
//_WARNS("RIDER") << "pushing '" << (*it).first << "' as " << value << LL_ENDL;
break;
@ -974,8 +932,7 @@ void LLEnvironment::updateGLVariablesForSettings(LLGLSLShader *shader, const LLS
{
LLVector4 vect4(value);
//_WARNS("RIDER") << "pushing '" << (*it).first << "' as " << vect4 << LL_ENDL;
shader->uniform4fv(it.second, 1, vect4.mV);
shader->uniform4fv(it.second.getShaderKey(), 1, vect4.mV);
break;
}

View File

@ -124,7 +124,7 @@ public:
void update(const LLViewerCamera * cam);
void updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting);
static void updateGLVariablesForSettings(LLGLSLShader *shader, const LLSettingsBase::ptr_t &psetting);
void updateShaderUniforms(LLGLSLShader *shader);
void setSelectedEnvironment(EnvSelection_t env, LLSettingsBase::Seconds transition = TRANSITION_DEFAULT, bool forced = false);

View File

@ -683,26 +683,31 @@ LLSettingsSky::parammapping_t LLSettingsVOSky::getParameterMap() const
if (param_map.empty())
{
// LEGACY_ATMOSPHERICS
param_map[SETTING_AMBIENT] = LLShaderMgr::AMBIENT;
param_map[SETTING_BLUE_DENSITY] = LLShaderMgr::BLUE_DENSITY;
param_map[SETTING_BLUE_HORIZON] = LLShaderMgr::BLUE_HORIZON;
param_map[SETTING_HAZE_DENSITY] = LLShaderMgr::HAZE_DENSITY;
param_map[SETTING_HAZE_HORIZON] = LLShaderMgr::HAZE_HORIZON;
param_map[SETTING_DENSITY_MULTIPLIER] = LLShaderMgr::DENSITY_MULTIPLIER;
param_map[SETTING_DISTANCE_MULTIPLIER] = LLShaderMgr::DISTANCE_MULTIPLIER;
param_map[SETTING_CLOUD_COLOR] = LLShaderMgr::CLOUD_COLOR;
param_map[SETTING_CLOUD_POS_DENSITY2] = LLShaderMgr::CLOUD_POS_DENSITY2;
param_map[SETTING_CLOUD_SCALE] = LLShaderMgr::CLOUD_SCALE;
param_map[SETTING_CLOUD_SHADOW] = LLShaderMgr::CLOUD_SHADOW;
param_map[SETTING_CLOUD_VARIANCE] = LLShaderMgr::CLOUD_VARIANCE;
param_map[SETTING_GLOW] = LLShaderMgr::GLOW;
param_map[SETTING_MAX_Y] = LLShaderMgr::MAX_Y;
param_map[SETTING_SUNLIGHT_COLOR] = LLShaderMgr::SUNLIGHT_COLOR;
param_map[SETTING_MOON_BRIGHTNESS] = LLShaderMgr::MOON_BRIGHTNESS;
param_map[SETTING_SKY_MOISTURE_LEVEL] = LLShaderMgr::MOISTURE_LEVEL;
param_map[SETTING_SKY_DROPLET_RADIUS] = LLShaderMgr::DROPLET_RADIUS;
param_map[SETTING_SKY_ICE_LEVEL] = LLShaderMgr::ICE_LEVEL;
// Todo: default 'legacy' values duplicate the ones from functions like getBlueDensity() find a better home for them
// There is LLSettingsSky::defaults(), but it doesn't contain everything since it is geared towards creating new settings.
param_map[SETTING_AMBIENT] = DefaultParam(LLShaderMgr::AMBIENT, LLColor3(0.25f, 0.25f, 0.25f).getValue());
param_map[SETTING_BLUE_DENSITY] = DefaultParam(LLShaderMgr::BLUE_DENSITY, LLColor3(0.2447f, 0.4487f, 0.7599f).getValue());
param_map[SETTING_BLUE_HORIZON] = DefaultParam(LLShaderMgr::BLUE_HORIZON, LLColor3(0.4954f, 0.4954f, 0.6399f).getValue());
param_map[SETTING_HAZE_DENSITY] = DefaultParam(LLShaderMgr::HAZE_DENSITY, LLSD(0.7f));
param_map[SETTING_HAZE_HORIZON] = DefaultParam(LLShaderMgr::HAZE_HORIZON, LLSD(0.19f));
param_map[SETTING_DENSITY_MULTIPLIER] = DefaultParam(LLShaderMgr::DENSITY_MULTIPLIER, LLSD(0.0001f));
param_map[SETTING_DISTANCE_MULTIPLIER] = DefaultParam(LLShaderMgr::DISTANCE_MULTIPLIER, LLSD(0.8f));
// Following values are always present, so we can just zero these ones, but used values from defaults()
LLSD& sky_defaults = LLSettingsSky::defaults();
param_map[SETTING_CLOUD_COLOR] = DefaultParam(LLShaderMgr::CLOUD_COLOR, sky_defaults[SETTING_CLOUD_COLOR]);
param_map[SETTING_CLOUD_POS_DENSITY2] = DefaultParam(LLShaderMgr::CLOUD_POS_DENSITY2, sky_defaults[SETTING_CLOUD_POS_DENSITY2]);
param_map[SETTING_CLOUD_SCALE] = DefaultParam(LLShaderMgr::CLOUD_SCALE, sky_defaults[SETTING_CLOUD_SCALE]);
param_map[SETTING_CLOUD_SHADOW] = DefaultParam(LLShaderMgr::CLOUD_SHADOW, sky_defaults[SETTING_CLOUD_SHADOW]);
param_map[SETTING_CLOUD_VARIANCE] = DefaultParam(LLShaderMgr::CLOUD_VARIANCE, sky_defaults[SETTING_CLOUD_VARIANCE]);
param_map[SETTING_GLOW] = DefaultParam(LLShaderMgr::GLOW, sky_defaults[SETTING_GLOW]);
param_map[SETTING_MAX_Y] = DefaultParam(LLShaderMgr::MAX_Y, sky_defaults[SETTING_MAX_Y]);
param_map[SETTING_SUNLIGHT_COLOR] = DefaultParam(LLShaderMgr::SUNLIGHT_COLOR, sky_defaults[SETTING_SUNLIGHT_COLOR]);
param_map[SETTING_MOON_BRIGHTNESS] = DefaultParam(LLShaderMgr::MOON_BRIGHTNESS, sky_defaults[SETTING_MOON_BRIGHTNESS]);
param_map[SETTING_SKY_MOISTURE_LEVEL] = DefaultParam(LLShaderMgr::MOISTURE_LEVEL, sky_defaults[SETTING_SKY_MOISTURE_LEVEL]);
param_map[SETTING_SKY_DROPLET_RADIUS] = DefaultParam(LLShaderMgr::DROPLET_RADIUS, sky_defaults[SETTING_SKY_DROPLET_RADIUS]);
param_map[SETTING_SKY_ICE_LEVEL] = DefaultParam(LLShaderMgr::ICE_LEVEL, sky_defaults[SETTING_SKY_ICE_LEVEL]);
// AdvancedAtmospherics TODO
// Provide mappings for new shader params here
@ -911,8 +916,9 @@ LLSettingsWater::parammapping_t LLSettingsVOWater::getParameterMap() const
if (param_map.empty())
{
param_map[SETTING_FOG_COLOR] = LLShaderMgr::WATER_FOGCOLOR;
param_map[SETTING_FOG_DENSITY] = LLShaderMgr::WATER_FOGDENSITY;
LLSD &water_defaults = LLSettingsWater::defaults();
param_map[SETTING_FOG_COLOR] = DefaultParam(LLShaderMgr::WATER_FOGCOLOR, water_defaults[SETTING_FOG_COLOR]);
param_map[SETTING_FOG_DENSITY] = DefaultParam(LLShaderMgr::WATER_FOGDENSITY, water_defaults[SETTING_FOG_DENSITY]);
}
return param_map;
}