From db89a4646c4e1296052fcc14e43f38d371e9c6e1 Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Tue, 5 Jan 2021 23:52:23 +0100 Subject: [PATCH] Minor refactoring + add @setsphere_origin to switch between avatar and camera anchoring --- indra/llrender/llshadermgr.cpp | 2 +- indra/llrender/llshadermgr.h | 2 +- .../shaders/class1/deferred/rlvF.glsl | 21 +++--- indra/newview/rlvdefines.h | 15 +++-- indra/newview/rlveffects.cpp | 64 +++++++++++++------ indra/newview/rlveffects.h | 15 +++-- indra/newview/rlvhelper.cpp | 5 +- 7 files changed, 78 insertions(+), 46 deletions(-) diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index b442375f4c..25a9b98240 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1253,11 +1253,11 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("camPosLocal"); // [RLVa:KB] - @setsphere - mReservedUniforms.push_back("avPosLocal"); mReservedUniforms.push_back("rlvEffectMode"); mReservedUniforms.push_back("rlvEffectParam1"); mReservedUniforms.push_back("rlvEffectParam2"); mReservedUniforms.push_back("rlvEffectParam3"); + mReservedUniforms.push_back("rlvEffectParam4"); // [/RLV:KB] mReservedUniforms.push_back("gWindDir"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 50e1c99f92..724d7eca5d 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -204,11 +204,11 @@ public: WL_CAMPOSLOCAL, // [RLVa:KB] - @setsphere - RLV_AVPOSLOCAL, RLV_EFFECT_MODE, RLV_EFFECT_PARAM1, RLV_EFFECT_PARAM2, RLV_EFFECT_PARAM3, + RLV_EFFECT_PARAM4, // [/RLVa:KB] AVATAR_WIND, diff --git a/indra/newview/app_settings/shaders/class1/deferred/rlvF.glsl b/indra/newview/app_settings/shaders/class1/deferred/rlvF.glsl index 384592cbd3..3f17354569 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/rlvF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/rlvF.glsl @@ -29,11 +29,11 @@ uniform sampler2DRect depthMap; uniform mat4 inv_proj; uniform vec2 screen_res; -uniform vec4 avPosLocal; -uniform int rlvEffectMode; -uniform vec4 rlvEffectParam1; -uniform vec4 rlvEffectParam2; -uniform vec2 rlvEffectParam3; +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) vec4 getPosition_d(vec2 pos_screen, float depth) { @@ -70,15 +70,16 @@ 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.xyz); + float distance = length(fragPosLocal.xyz - avPosLocal); - vec2 sphereMinMaxDist = rlvEffectParam1.yw; - vec2 sphereMinMaxValue = rlvEffectParam1.xz; - vec3 sphereColour = rlvEffectParam2.rgb; + vec2 sphereMinMaxDist = rlvEffectParam2.yw; + vec2 sphereMinMaxValue = rlvEffectParam2.xz; + vec3 sphereColour = rlvEffectParam3.rgb; // 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) + @@ -91,7 +92,7 @@ void main() fragColor = mix(fragColor, sphereColour, effectStrength); break; case 1: // Blur - fragColor = blur13(diffuseRect, fragTC, effectStrength * rlvEffectParam3.xy); + fragColor = blur13(diffuseRect, fragTC, effectStrength * rlvEffectParam4.xy); break; } diff --git a/indra/newview/rlvdefines.h b/indra/newview/rlvdefines.h index d5c410e7ea..1736b688f0 100644 --- a/indra/newview/rlvdefines.h +++ b/indra/newview/rlvdefines.h @@ -277,16 +277,19 @@ enum ERlvBehaviourModifier enum class ERlvLocalBhvrModifier { + // @setoverlay OverlayAlpha, // Transparency level of the overlay texture (in addition to the texture's own alpha channel) OverlayTexture, // Specifies the UUID of the overlay texture OverlayTint, // The tint that's applied to the overlay texture OverlayTouch, // Determines whether the overlay texture's alpha channel will be used to allow/block world interaction - SphereMode, - SphereColor, // Colour to mix with the actual pixel colour (alpha depends non-linerally ) - SphereMaxAlpha, // Alpha of the mix colour at maximum distance - SphereMaxDist, // Distance at which the blending stops ; or colour = mix(colour, sphere_colour, max_alpha) - SphereMinAlpha, // Alpha of the mix colour at minimum distance - SphereMinDist, // Distance at which the gradual blending starts; or colour = mix(colour, sphere_colour, min_alpha) + // @setsphere + 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 Unknown, }; diff --git a/indra/newview/rlveffects.cpp b/indra/newview/rlveffects.cpp index 247414014b..5c11bcba84 100644 --- a/indra/newview/rlveffects.cpp +++ b/indra/newview/rlveffects.cpp @@ -181,37 +181,41 @@ void RlvOverlayEffect::run() // const int c_SphereDefaultMode = 0; -const float c_SphereDefaultAlpha = 1.0f; -const float c_SphereDefaultDistance = 0.0f; +const int c_SphereDefaultOrigin = 0; const float c_SphereDefaultColor[3] = { 0.0f, 0.0f, 0.0f }; +const float c_SphereDefaultDistance = 0.0f; +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_Color(LLColor3(c_SphereDefaultColor)) , m_nMinDistance(c_SphereDefaultDistance), m_nMaxDistance(c_SphereDefaultDistance) , m_nMinValue(c_SphereDefaultAlpha), m_nMaxValue(c_SphereDefaultAlpha) { if (RlvObject* pRlvObj = gRlvHandler.getObject(idRlvObj)) { - int nMode; - if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMode, nMode)) - m_nMode = (ESphereMode)nMode; + int nNumber; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMode, nNumber)) + m_nMode = (ESphereMode)nNumber; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereOrigin, nNumber)) + m_nOrigin = (ESphereOrigin)nNumber; LLVector3 vecColor; if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereColor, vecColor)) m_Color = LLColor3(vecColor.mV); - float nValue; - if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMinAlpha, nValue)) - m_nMinValue = nValue; - if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMaxAlpha, nValue)) - m_nMaxValue = nValue; + float nFloat; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMinDist, nFloat)) + m_nMinDistance = nFloat; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMaxDist, nFloat)) + m_nMaxDistance = nFloat; - if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMinDist, nValue)) - m_nMinDistance = nValue; - if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMaxDist, nValue)) - m_nMaxDistance = nValue; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMinValue, nFloat)) + m_nMinValue = nFloat; + if (pRlvObj->getModifierValue(ERlvLocalBhvrModifier::SphereMaxValue, nFloat)) + m_nMaxValue = nFloat; } } @@ -229,6 +233,16 @@ ERlvCmdRet RlvSphereEffect::onModeChanged(const LLUUID& idRlvObj, const boost::o return RLV_RET_SUCCESS; } +// static +ERlvCmdRet RlvSphereEffect::onOriginChanged(const LLUUID& idRlvObj, const boost::optional newValue) +{ + if (RlvSphereEffect* pEffect = dynamic_cast(LLVfxManager::instance().getEffect(idRlvObj))) + { + pEffect->m_nOrigin = (ESphereOrigin)((newValue) ? boost::get(newValue.value()) : c_SphereDefaultOrigin); + } + return RLV_RET_SUCCESS; +} + // static ERlvCmdRet RlvSphereEffect::onColorChanged(const LLUUID& idRlvObj, const boost::optional newValue) { @@ -286,19 +300,29 @@ void RlvSphereEffect::setShaderUniforms(LLGLSLShader* pShader, LLRenderTarget* p pShader->uniform1i(LLShaderMgr::RLV_EFFECT_MODE, llclamp((int)m_nMode, 0, (int)ESphereMode::Count)); // Pass the sphere origin to the shader - const LLVector4 posSphereOrigin(isAgentAvatarValid() ? gAgentAvatarp->getRenderPosition() : gAgent.getPositionAgent(), 1.0f); + LLVector4 posSphereOrigin; + switch (m_nOrigin) + { + case ESphereOrigin::Camera: + posSphereOrigin.setVec(LLViewerCamera::instance().getOrigin(), 1.0f); + break; + case ESphereOrigin::Avatar: + default: + posSphereOrigin.setVec((isAgentAvatarValid()) ? gAgentAvatarp->getRenderPosition() : gAgent.getPositionAgent(), 1.0f); + break; + } glh::vec4f posSphereOriginGl(posSphereOrigin.mV); const glh::matrix4f& mvMatrix = gGL.getModelviewMatrix(); mvMatrix.mult_matrix_vec(posSphereOriginGl); - pShader->uniform4fv(LLShaderMgr::RLV_AVPOSLOCAL, 1, posSphereOriginGl.v); + 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); - pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM1, 1, sphereParams.v); + pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM2, 1, sphereParams.v); // Pass color const glh::vec4f sphereColor(m_Color.mV, 1.0); - pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM2, 1, sphereColor.v); + pShader->uniform4fv(LLShaderMgr::RLV_EFFECT_PARAM3, 1, sphereColor.v); } void RlvSphereEffect::renderPass(LLGLSLShader* pShader) const @@ -354,9 +378,9 @@ void RlvSphereEffect::run() renderPass(&gDeferredRlvProgram); break; case ESphereMode::Blur: - gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM3, 1.f, 0.f); + gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM4, 1.f, 0.f); renderPass(&gDeferredRlvProgram); - gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM3, 0.f, 1.f); + gDeferredRlvProgram.uniform2f(LLShaderMgr::RLV_EFFECT_PARAM4, 0.f, 1.f); renderPass(&gDeferredRlvProgram); break; } diff --git a/indra/newview/rlveffects.h b/indra/newview/rlveffects.h index f9336e8ae3..09e5a5b8c7 100644 --- a/indra/newview/rlveffects.h +++ b/indra/newview/rlveffects.h @@ -73,6 +73,7 @@ public: public: void run() override; static ERlvCmdRet onModeChanged(const LLUUID& idRlvObj, const boost::optional newValue); + static ERlvCmdRet onOriginChanged(const LLUUID& idRlvObj, const boost::optional newValue); static ERlvCmdRet onColorChanged(const LLUUID& idRlvObj, const boost::optional newValue); static ERlvCmdRet onMinDistChanged(const LLUUID& idRlvObj, const boost::optional newValue); static ERlvCmdRet onMaxDistChanged(const LLUUID& idRlvObj, const boost::optional newValue); @@ -87,12 +88,14 @@ protected: */ protected: enum class ESphereMode { Blend = 0, SoftBlur, Blur, Count }; - ESphereMode m_nMode; - LLColor3 m_Color; - float m_nMinValue; - float m_nMaxValue; - float m_nMinDistance; - float m_nMaxDistance; + ESphereMode m_nMode; + enum class ESphereOrigin { Avatar = 0, Camera, Count }; + ESphereOrigin m_nOrigin; + LLColor3 m_Color; + float m_nMinDistance; + float m_nMaxDistance; + float m_nMinValue; + float m_nMaxValue; }; // ==================================================================================== diff --git a/indra/newview/rlvhelper.cpp b/indra/newview/rlvhelper.cpp index f5b8921037..324c774c25 100644 --- a/indra/newview/rlvhelper.cpp +++ b/indra/newview/rlvhelper.cpp @@ -227,11 +227,12 @@ RlvBehaviourDictionary::RlvBehaviourDictionary() // Sphere RlvBehaviourInfo* pSetSphereBhvr = new RlvBehaviourProcessor("setsphere", RlvBehaviourInfo::BHVR_EXPERIMENTAL); 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::SphereMinAlpha, typeid(float), "minalpha", &RlvSphereEffect::onMinValueChanged); - pSetSphereBhvr->addModifier(ERlvLocalBhvrModifier::SphereMaxAlpha, typeid(float), "maxalpha", &RlvSphereEffect::onMaxValueChanged); 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); addEntry(pSetSphereBhvr); //