A clever bunny noticed that other commands use dist[min|max] rather than [min|max]dist

master
Kitty Barnett 2021-01-06 04:36:56 +01:00
parent db89a4646c
commit 22a5734051
7 changed files with 92 additions and 62 deletions

View File

@ -1258,6 +1258,7 @@ void LLShaderMgr::initAttribsAndUniforms()
mReservedUniforms.push_back("rlvEffectParam2");
mReservedUniforms.push_back("rlvEffectParam3");
mReservedUniforms.push_back("rlvEffectParam4");
mReservedUniforms.push_back("rlvEffectParam5");
// [/RLV:KB]
mReservedUniforms.push_back("gWindDir");

View File

@ -209,6 +209,7 @@ public:
RLV_EFFECT_PARAM2,
RLV_EFFECT_PARAM3,
RLV_EFFECT_PARAM4,
RLV_EFFECT_PARAM5,
// [/RLVa:KB]
AVATAR_WIND,

View File

@ -32,8 +32,18 @@ uniform vec2 screen_res;
uniform int rlvEffectMode; // ESphereMode
uniform vec4 rlvEffectParam1; // Sphere origin (in local coordinates)
uniform vec4 rlvEffectParam2; // Min/max dist + min/max value
uniform vec4 rlvEffectParam3; // Sphere color (not used for blur)
uniform vec2 rlvEffectParam4; // Blur direction (not used for blend)
uniform bvec2 rlvEffectParam3; // Min/max dist extend
uniform vec4 rlvEffectParam4; // Sphere color (not used for blur)
uniform vec2 rlvEffectParam5; // Blur direction (not used for blend)
#define SPHERE_ORIGIN rlvEffectParam1.xyz
#define SPHERE_DISTMIN rlvEffectParam2.y
#define SPHERE_DISTMAX rlvEffectParam2.w
#define SPHERE_DISTEXTEND rlvEffectParam3
#define SPHERE_VALUEMIN rlvEffectParam2.x
#define SPHERE_VALUEMAX rlvEffectParam2.z
#define SPHERE_COLOUR rlvEffectParam4.rgb
#define BLUR_DIRECTION rlvEffectParam5.xy
vec4 getPosition_d(vec2 pos_screen, float depth)
{
@ -70,29 +80,24 @@ vec3 blur13(sampler2DRect image, vec2 uv, vec2 direction)
void main()
{
vec3 avPosLocal = rlvEffectParam1.xyz;
vec2 fragTC = vary_fragcoord.st;
float fragDepth = texture2DRect(depthMap, fragTC).x;
vec3 fragPosLocal = getPosition_d(fragTC, fragDepth).xyz;
vec3 fragColor = texture2DRect(diffuseRect, fragTC).rgb;
float distance = length(fragPosLocal.xyz - avPosLocal);
vec2 sphereMinMaxDist = rlvEffectParam2.yw;
vec2 sphereMinMaxValue = rlvEffectParam2.xz;
vec3 sphereColour = rlvEffectParam3.rgb;
float distance = length(fragPosLocal.xyz - SPHERE_ORIGIN);
// Linear non-branching interpolation of the strength of the sphere effect (replaces if/elseif/else for x < min, min <= x <= max and x > max)
float effectStrength = mix(sphereMinMaxValue.x, 0, distance < sphereMinMaxDist.x) +
mix(0, sphereMinMaxValue.y - sphereMinMaxValue.x, clamp((distance - sphereMinMaxDist.x) / (sphereMinMaxDist.y - sphereMinMaxDist.x), 0.0, 1.0));
float effectStrength = SPHERE_VALUEMIN + mix(0, SPHERE_VALUEMAX - SPHERE_VALUEMIN, (distance - SPHERE_DISTMIN) / (SPHERE_DISTMAX - SPHERE_DISTMIN));
effectStrength = mix(effectStrength, mix(0, SPHERE_VALUEMIN, SPHERE_DISTEXTEND.x), distance < SPHERE_DISTMIN);
effectStrength = mix(effectStrength, mix(0, SPHERE_VALUEMAX, SPHERE_DISTEXTEND.y), distance > SPHERE_DISTMAX);
// *TODO: It should be fine to branch on a uniform?
switch (rlvEffectMode)
{
case 0: // Blend
fragColor = mix(fragColor, sphereColour, effectStrength);
fragColor = mix(fragColor, SPHERE_COLOUR, effectStrength);
break;
case 1: // Blur
fragColor = blur13(diffuseRect, fragTC, effectStrength * rlvEffectParam4.xy);
fragColor = blur13(diffuseRect, fragTC, effectStrength * BLUR_DIRECTION);
break;
}

View File

@ -286,10 +286,11 @@ enum class ERlvLocalBhvrModifier
SphereMode, // The type of effect that will apply to any pixel that intersects with the sphere (e.g. blend, blur, ...)
SphereOrigin, // The origin of the sphere can either be the avatar or the camera position
SphereColor, // [Blend only] Colour to mix with the actual pixel colour
SphereMinDist, // Distance at which the effect starts and has weight minValue; e.g. for blend this would be colour = mix(colour, sphere_colour, min_alpha)
SphereMaxDist, // Distance at which the effect starts and has weight maxValue; e.g. for blend this would be colour = mix(colour, sphere_colour, max_alpha)
SphereMinValue, // Value of the effect at minimum distance
SphereMaxValue, // Value of the effect at maximum distance
SphereDistMin, // Distance at which the effect starts and has weight minValue; e.g. for blend this would be colour = mix(colour, sphere_colour, min_alpha)
SphereDistMax, // Distance at which the effect starts and has weight maxValue; e.g. for blend this would be colour = mix(colour, sphere_colour, max_alpha)
SphereDistExtend, // Specifies the value beyond min dist or max dist (by default the sphere extends beyond max distance at max vlaue)
SphereValueMin, // Value of the effect at minimum distance
SphereValueMax, // Value of the effect at maximum distance
Unknown,
};

View File

@ -184,38 +184,42 @@ const int c_SphereDefaultMode = 0;
const int c_SphereDefaultOrigin = 0;
const float c_SphereDefaultColor[3] = { 0.0f, 0.0f, 0.0f };
const float c_SphereDefaultDistance = 0.0f;
const int c_SphereDefaultDistanceExtend = 0;
const float c_SphereDefaultAlpha = 1.0f;
RlvSphereEffect::RlvSphereEffect(const LLUUID& idRlvObj)
: LLVisualEffect(idRlvObj, EVisualEffect::RlvSphere, EVisualEffectType::PostProcessShader)
, m_nMode((ESphereMode)c_SphereDefaultMode)
, m_nOrigin((ESphereOrigin)c_SphereDefaultOrigin)
, m_eMode((ESphereMode)c_SphereDefaultMode)
, m_eOrigin((ESphereOrigin)c_SphereDefaultOrigin)
, m_Color(LLColor3(c_SphereDefaultColor))
, m_nMinDistance(c_SphereDefaultDistance), m_nMaxDistance(c_SphereDefaultDistance)
, m_nMinValue(c_SphereDefaultAlpha), m_nMaxValue(c_SphereDefaultAlpha)
, m_nDistanceMin(c_SphereDefaultDistance), m_nDistanceMax(c_SphereDefaultDistance)
, m_eDistExtend((ESphereDistExtend)0)
, m_nValueMin(c_SphereDefaultAlpha), m_nValueMax(c_SphereDefaultAlpha)
{
if (RlvObject* pRlvObj = gRlvHandler.getObject(idRlvObj))
{
int nNumber;
if (pRlvObj->getModifierValue<int>(ERlvLocalBhvrModifier::SphereMode, nNumber))
m_nMode = (ESphereMode)nNumber;
m_eMode = (ESphereMode)nNumber;
if (pRlvObj->getModifierValue<int>(ERlvLocalBhvrModifier::SphereOrigin, nNumber))
m_nOrigin = (ESphereOrigin)nNumber;
m_eOrigin = (ESphereOrigin)nNumber;
LLVector3 vecColor;
if (pRlvObj->getModifierValue<LLVector3>(ERlvLocalBhvrModifier::SphereColor, vecColor))
m_Color = LLColor3(vecColor.mV);
float nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereMinDist, nFloat))
m_nMinDistance = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereMaxDist, nFloat))
m_nMaxDistance = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereDistMin, nFloat))
m_nDistanceMin = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereDistMax, nFloat))
m_nDistanceMax = nFloat;
if (pRlvObj->getModifierValue<int>(ERlvLocalBhvrModifier::SphereDistExtend, nNumber))
m_eDistExtend = (ESphereDistExtend)nNumber;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereMinValue, nFloat))
m_nMinValue = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereMaxValue, nFloat))
m_nMaxValue = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereValueMin, nFloat))
m_nValueMin = nFloat;
if (pRlvObj->getModifierValue<float>(ERlvLocalBhvrModifier::SphereValueMax, nFloat))
m_nValueMax = nFloat;
}
}
@ -228,7 +232,7 @@ ERlvCmdRet RlvSphereEffect::onModeChanged(const LLUUID& idRlvObj, const boost::o
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nMode = (ESphereMode)((newValue) ? boost::get<int>(newValue.value()) : c_SphereDefaultMode);
pEffect->m_eMode = (ESphereMode)((newValue) ? boost::get<int>(newValue.value()) : c_SphereDefaultMode);
}
return RLV_RET_SUCCESS;
}
@ -238,7 +242,7 @@ ERlvCmdRet RlvSphereEffect::onOriginChanged(const LLUUID& idRlvObj, const boost:
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nOrigin = (ESphereOrigin)((newValue) ? boost::get<int>(newValue.value()) : c_SphereDefaultOrigin);
pEffect->m_eOrigin = (ESphereOrigin)((newValue) ? boost::get<int>(newValue.value()) : c_SphereDefaultOrigin);
}
return RLV_RET_SUCCESS;
}
@ -254,41 +258,51 @@ ERlvCmdRet RlvSphereEffect::onColorChanged(const LLUUID& idRlvObj, const boost::
}
// static
ERlvCmdRet RlvSphereEffect::onMinDistChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
ERlvCmdRet RlvSphereEffect::onDistMinChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nMinDistance = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultDistance;
pEffect->m_nDistanceMin = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultDistance;
}
return RLV_RET_SUCCESS;
}
// static
ERlvCmdRet RlvSphereEffect::onMaxDistChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
ERlvCmdRet RlvSphereEffect::onDistMaxChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nMaxDistance = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultDistance;
pEffect->m_nDistanceMax = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultDistance;
}
return RLV_RET_SUCCESS;
}
// static
ERlvCmdRet RlvSphereEffect::onMinValueChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
ERlvCmdRet RlvSphereEffect::onDistExtendChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nMinValue = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultAlpha;
pEffect->m_eDistExtend = (ESphereDistExtend)((newValue) ? boost::get<int>(newValue.value()) : c_SphereDefaultDistanceExtend);
}
return RLV_RET_SUCCESS;
}
// static
ERlvCmdRet RlvSphereEffect::onMaxValueChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
ERlvCmdRet RlvSphereEffect::onValueMinChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nMaxValue = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultAlpha;
pEffect->m_nValueMin = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultAlpha;
}
return RLV_RET_SUCCESS;
}
// static
ERlvCmdRet RlvSphereEffect::onValueMaxChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue)
{
if (RlvSphereEffect* pEffect = dynamic_cast<RlvSphereEffect*>(LLVfxManager::instance().getEffect(idRlvObj)))
{
pEffect->m_nValueMax = (newValue) ? boost::get<float>(newValue.value()) : c_SphereDefaultAlpha;
}
return RLV_RET_SUCCESS;
}
@ -297,11 +311,11 @@ void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader, LLRenderTarget* p
{
pShader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, glh_get_current_projection().inverse().m);
pShader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, pRenderTarget->getWidth(), pRenderTarget->getHeight());
pShader->uniform1i(LLShaderMgr::RLV_EFFECT_MODE, llclamp((int)m_nMode, 0, (int)ESphereMode::Count));
pShader->uniform1i(LLShaderMgr::RLV_EFFECT_MODE, llclamp((int)m_eMode, 0, (int)ESphereMode::Count));
// Pass the sphere origin to the shader
LLVector4 posSphereOrigin;
switch (m_nOrigin)
switch (m_eOrigin)
{
case ESphereOrigin::Camera:
posSphereOrigin.setVec(LLViewerCamera::instance().getOrigin(), 1.0f);
@ -317,12 +331,16 @@ void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader, LLRenderTarget* p
pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM1, 1, posSphereOriginGl.v);
// Pack min/max distance and alpha together
const glh::vec4f sphereParams(m_nMinValue, m_nMinDistance, m_nMaxValue, m_nMaxDistance);
const glh::vec4f sphereParams(m_nValueMin, m_nDistanceMin, m_nValueMax, m_nDistanceMax);
pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM2, 1, sphereParams.v);
// Pass dist extend
int eDistExtend = (int)m_eDistExtend;
pShader->uniform2f(LLShaderMgr::RLV_EFFECT_PARAM3, eDistExtend & (int)ESphereDistExtend::Min, eDistExtend & (int)ESphereDistExtend::Max);
// Pass color
const glh::vec4f sphereColor(m_Color.mV, 1.0);
pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM3, 1, sphereColor.v);
pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM4, 1, sphereColor.v);
}
void RlvSphereEffect::renderPass(LLGLSLShader* pShader) const
@ -372,15 +390,15 @@ void RlvSphereEffect::run()
gDeferredRlvProgram.bind();
setShaderUniforms(&gDeferredRlvProgram, &gPipeline.mScreen);
switch (m_nMode)
switch (m_eMode)
{
case ESphereMode::Blend:
renderPass(&gDeferredRlvProgram);
break;
case ESphereMode::Blur:
gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM4, 1.f, 0.f);
gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 1.f, 0.f);
renderPass(&gDeferredRlvProgram);
gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM4, 0.f, 1.f);
gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM5, 0.f, 1.f);
renderPass(&gDeferredRlvProgram);
break;
}

View File

@ -75,10 +75,11 @@ public:
static ERlvCmdRet onModeChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onOriginChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onColorChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onMinDistChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onMaxDistChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onMinValueChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onMaxValueChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onDistMinChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onDistMaxChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onDistExtendChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onValueMinChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
static ERlvCmdRet onValueMaxChanged(const LLUUID& idRlvObj, const boost::optional<RlvBehaviourModifierValue> newValue);
protected:
void renderPass(LLGLSLShader* pShader) const;
void setShaderUniforms(LLGLSLShader* pShader, LLRenderTarget* pRenderTarget);
@ -88,14 +89,16 @@ protected:
*/
protected:
enum class ESphereMode { Blend = 0, SoftBlur, Blur, Count };
ESphereMode m_nMode;
ESphereMode m_eMode;
enum class ESphereOrigin { Avatar = 0, Camera, Count };
ESphereOrigin m_nOrigin;
ESphereOrigin m_eOrigin;
LLColor3 m_Color;
float m_nMinDistance;
float m_nMaxDistance;
float m_nMinValue;
float m_nMaxValue;
float m_nDistanceMin;
float m_nDistanceMax;
enum class ESphereDistExtend { Max = 0x01, Min = 0x02, Both = 0x03 };
ESphereDistExtend m_eDistExtend;
float m_nValueMin;
float m_nValueMax;
};
// ====================================================================================

View File

@ -229,10 +229,11 @@ RlvBehaviourDictionary::RlvBehaviourDictionary()
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMode, typeid(int), "mode", &RlvSphereEffect::onModeChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereOrigin, typeid(int), "origin", &RlvSphereEffect::onOriginChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereColor, typeid(LLVector3), "color", &RlvSphereEffect::onColorChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMinDist, typeid(float), "mindist", &RlvSphereEffect::onMinDistChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMaxDist, typeid(float), "maxdist", &RlvSphereEffect::onMaxDistChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMinValue, typeid(float), "minvalue", &RlvSphereEffect::onMinValueChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMaxValue, typeid(float), "maxvalue", &RlvSphereEffect::onMaxValueChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereDistMin, typeid(float), "distmin", &RlvSphereEffect::onDistMinChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereDistMax, typeid(float), "distmax", &RlvSphereEffect::onDistMaxChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereDistExtend, typeid(int), "distextend", &RlvSphereEffect::onDistExtendChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereValueMin, typeid(float), "valuemin", &RlvSphereEffect::onValueMinChanged);
pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereValueMax, typeid(float), "valuemax", &RlvSphereEffect::onValueMaxChanged);
addEntry(pSetSphereBhvr);
//