BackgroundBlurEffect blurEffect = BackgroundBlurEffect::New();
DALI_TEST_CHECK(blurEffect);
- BackgroundBlurEffect blurEffect2 = BackgroundBlurEffect::New(0.5f, 10.0f, 10.0f);
+ BackgroundBlurEffect blurEffect2 = BackgroundBlurEffect::New(0.5f, 10.0f);
DALI_TEST_CHECK(blurEffect2);
END_TEST;
try
{
- BackgroundBlurEffect blurEffect = BackgroundBlurEffect::New(-0.5f, 10.0f, 10.0f);
- BackgroundBlurEffect blurEffect2 = BackgroundBlurEffect::New(10.0f, 10.0f, 10.0f);
+ BackgroundBlurEffect blurEffect = BackgroundBlurEffect::New(-0.5f, 10.0f);
+ BackgroundBlurEffect blurEffect2 = BackgroundBlurEffect::New(10.0f, 10.0f);
DALI_TEST_CHECK(!blurEffect && !blurEffect2);
}
catch(Dali::DaliException& e)
Integration::Scene scene = application.GetScene();
Control control = Control::New();
control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ control.SetProperty(Actor::Property::SIZE, Vector2(3.0f, 3.0f));
scene.Add(control);
control.SetRenderEffect(BackgroundBlurEffect::New());
blackDimmerMap.Insert(Toolkit::Visual::Property::OPACITY, 0.2f);
blackDimmerMap.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, 30.0f);
- RenderEffect effect = BackgroundBlurEffect::New(0.4f, 40, 10.0f);
+ RenderEffect effect = BackgroundBlurEffect::New(0.4f, 40);
Control control = Control::New();
DALI_TEST_CHECK(control.GetRendererCount() == 0u);
namespace
{
// Default values
-static constexpr float BLUR_EFFECT_DOWNSCALE_FACTOR = 0.4f;
-static constexpr uint32_t BLUR_EFFECT_PIXEL_RADIUS = 5u;
-static constexpr float BLUR_EFFECT_BELL_CURVE_WIDTH = 1.5f;
-static constexpr int32_t BLUR_EFFECT_ORDER_INDEX = 101;
-static constexpr float BLUR_EFFECT_DIVIDE_ZERO_EPSILON = 0.001f;
+static constexpr float BLUR_EFFECT_DOWNSCALE_FACTOR = 0.4f;
+static constexpr uint32_t BLUR_EFFECT_PIXEL_RADIUS = 5u;
+static constexpr int32_t BLUR_EFFECT_ORDER_INDEX = 101;
} // namespace
namespace Dali
{
namespace Internal
{
-// mMultiplierForFraction and mDenominator are for CalculateGaussianWeight().
-// The original equation,
-// (1.0f / sqrt(2.0f * Math::PI * mBellCurveWidth)) * exp(-(localOffset * localOffset) * (1.0f / (2.0f * mBellCurveWidth * mBellCurveWidth)));
-// is simplified as below:
-// mDenominator * exp(-(localOffset * localOffset) * mMultiplierForFraction);
-
BlurEffectImpl::BlurEffectImpl(bool isBackground)
: RenderEffectImpl(),
mInternalRoot(Actor::New()),
mDownscaleFactor(BLUR_EFFECT_DOWNSCALE_FACTOR),
mPixelRadius(BLUR_EFFECT_PIXEL_RADIUS),
- mBellCurveWidth(BLUR_EFFECT_BELL_CURVE_WIDTH),
- mMultiplierForFraction(1.0f / (2.0f * mBellCurveWidth * mBellCurveWidth)),
- mDenominator(1.0f / sqrt(2.0f * Math::PI * mBellCurveWidth)),
+ mBellCurveWidth(0.001f),
mIsActivated(false),
mIsBackground(isBackground)
{
}
-BlurEffectImpl::BlurEffectImpl(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth, bool isBackground)
+BlurEffectImpl::BlurEffectImpl(float downscaleFactor, uint32_t blurRadius, bool isBackground)
: RenderEffectImpl(),
mInternalRoot(Actor::New()),
mDownscaleFactor(downscaleFactor),
mPixelRadius((blurRadius >> 2) + 1),
- mBellCurveWidth(std::max(bellCurveWidth, BLUR_EFFECT_DIVIDE_ZERO_EPSILON)),
- mMultiplierForFraction(1.0f / (2.0f * mBellCurveWidth * mBellCurveWidth)),
- mDenominator(1.0f / sqrt(2.0f * Math::PI * mBellCurveWidth)),
+ mBellCurveWidth(0.001f),
mIsActivated(false),
mIsBackground(isBackground)
{
return handle;
}
-BlurEffectImplPtr BlurEffectImpl::New(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth, bool isBackground)
+BlurEffectImplPtr BlurEffectImpl::New(float downscaleFactor, uint32_t blurRadius, bool isBackground)
{
- BlurEffectImplPtr handle = new BlurEffectImpl(downscaleFactor, blurRadius, bellCurveWidth, isBackground);
+ BlurEffectImplPtr handle = new BlurEffectImpl(downscaleFactor, blurRadius, isBackground);
handle->Initialize();
return handle;
}
fragmentStringStream << SHADER_BLUR_EFFECT_FRAG;
std::string fragmentSource(fragmentStringStream.str());
+ float sigma = 0.5f;
+ {
+ float epsilon = 1e-2f / (mPixelRadius * 2);
+ while((CalculateGaussianWeight((mPixelRadius * 2) - 1, sigma) < epsilon) && (sigma < 50.0f))
+ {
+ sigma += 1.0f;
+ }
+ }
+ mBellCurveWidth = sigma;
+
//////////////////////////////////////////////////////
// Create actors
mInternalRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
mInternalRoot.Add(mVerticalBlurActor);
}
-void BlurEffectImpl::Activate(Toolkit::Control ownerControl)
+void BlurEffectImpl::Activate()
{
- DALI_ASSERT_ALWAYS(ownerControl && "Given empty owner control");
-
if(mIsActivated)
{
- if(ownerControl == GetOwnerControl())
- {
- return;
- }
- else
- {
- Deactivate();
- }
+ return;
}
- SetOwnerControl(ownerControl);
- mIsActivated = true;
+ mIsActivated = true;
+ Toolkit::Control ownerControl = GetOwnerControl();
+ DALI_ASSERT_ALWAYS(ownerControl && "Set the owner of RenderEffect before you activate.");
// Get input texture size
Vector2 size = GetTargetSize();
taskList.RemoveTask(mHorizontalBlurTask);
taskList.RemoveTask(mVerticalBlurTask);
taskList.RemoveTask(mSourceRenderTask);
-
- ClearOwnerControl();
}
void BlurEffectImpl::SetShaderConstants(float downsampledWidth, float downsampledHeight)
unsigned int halfSize = mPixelRadius * 2;
std::vector<float> halfSideKernel(halfSize);
- halfSideKernel[0] = CalculateGaussianWeight(0.0f);
+ halfSideKernel[0] = CalculateGaussianWeight(0.0f, mBellCurveWidth);
float totalWeights = halfSideKernel[0];
for(unsigned int i = 1; i < halfSize; i++)
{
- float w = CalculateGaussianWeight(i);
+ float w = CalculateGaussianWeight(i, mBellCurveWidth);
halfSideKernel[i] = w;
totalWeights += w * 2.0f;
}
*
* downscaleFactor = 0.4f
* pixelRadius = 5u
- * bellCurveWidth = 1.5f
*
* This blur algorithm is used for both foreground and background blurs.
*
*
* @param[in] downscaleFactor This value should reside in the range [0.0, 1.0].
* @param[in] blurRadius The radius of Gaussian kernel.
- * @param[in] bellCurveWidth Blur intensity.
* @param[in] isBackground True when blurring background, False otherwise
* @return A handle to a newly allocated Dali resource
*/
- static BlurEffectImplPtr New(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth, bool isBackground);
+ static BlurEffectImplPtr New(float downscaleFactor, uint32_t blurRadius, bool isBackground);
/**
* @brief Activates blur effect
- * @param[in] ownerControl The control to apply effect
*/
- void Activate(Toolkit::Control ownerControl) override;
+ void Activate() override;
/**
* @brief Dectivates blur effect
* @brief Creates an uninitialized blur effect implementation
* @param[in] downscaleFactor This value should reside in the range [0.0, 1.0].
* @param[in] blurRadius The radius of Gaussian kernel.
- * @param[in] bellCurveWidth Blur intensity.
* @param[in] isBackground True when blurring background, False otherwise
*/
- BlurEffectImpl(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth, bool isBackground);
+ BlurEffectImpl(float downscaleFactor, uint32_t blurRadius, bool isBackground);
/**
* @brief Destructor
* @brief Calculates gaussian weight
* @param[in] localOffset Input to the function
*/
- inline float CalculateGaussianWeight(float localOffset) const
+ inline float CalculateGaussianWeight(float localOffset, float sigma) const
{
- return mDenominator * exp(-(localOffset * localOffset) * mMultiplierForFraction);
+ return (1.0f / sqrt(2.0f * Math::PI * sigma)) * exp(-(localOffset * localOffset) * (1.0f / (2.0f * sigma * sigma)));
}
/**
float mDownscaleFactor;
uint32_t mPixelRadius;
float mBellCurveWidth;
- float mMultiplierForFraction;
- float mDenominator;
bool mIsActivated : 1;
bool mIsBackground : 1;
void RenderEffectImpl::SetOwnerControl(Dali::Toolkit::Control control)
{
- if(control)
+ if(control && (control != mOwnerControl))
{
mOwnerControl = control;
void RenderEffectImpl::OnSizeSet(PropertyNotification& source)
{
- mTargetSize = mOwnerControl.GetProperty<Vector2>(Actor::Property::SIZE);
- Deactivate();
- Activate(mOwnerControl);
+ if(mOwnerControl)
+ {
+ mTargetSize = mOwnerControl.GetProperty<Vector2>(Actor::Property::SIZE);
+ Deactivate();
+ Activate();
+ }
}
Renderer RenderEffectImpl::GetTargetRenderer() const
public:
/**
* @brief Activates effect on ownerControl
- * @param[in] control The owner control to apply RenderEffect.
*/
- virtual void Activate(Toolkit::Control ownerControl) = 0;
+ virtual void Activate() = 0;
/**
* @brief Deactivates effect
*/
virtual void Deactivate() = 0;
+ /**
+ * @brief Sets owner Control. Applies effect on the owner.
+ * @param[in] control The owner control to apply RenderEffect.
+ */
+ void SetOwnerControl(Toolkit::Control control);
+
+ /**
+ * @brief Clears owner Control.
+ */
+ void ClearOwnerControl();
+
protected:
/**
* @copydoc Dali::Toolkit::RenderEffect::RenderEffect
*/
Vector2 GetTargetSize() const;
- /**
- * @brief Sets owner Control. Applies effect on the owner.
- * @param[in] control The owner control to apply RenderEffect.
- */
- void SetOwnerControl(Toolkit::Control control);
-
- /**
- * @brief Clears owner Control.
- */
- void ClearOwnerControl();
-
/**
* @brief Get Owner control.
* @return mOwnerControl
return length(max(abs(PixelPositionFromCenter)
- RectangleEdgePositionFromCenter
+ Radius
- ,0.0))
+ , 0.0))
- Radius;
}
{
gl_FragColor = texture2D(sTexture, vTexCoord);
- float edgeSoftness = 1.0;
- float distance = roundedBoxSDF(vFragCoord.xy - (uSize.xy/2.0), uSize.xy/2.0, getCurrentRadius());
+ float radius = getCurrentRadius();
+ float edgeSoftness = min(1.0, radius);
+ float distance = roundedBoxSDF(vFragCoord.xy - (uSize.xy/2.0), uSize.xy/2.0, radius);
- float smoothedAlpha = 1.0 - smoothstep(0.0, edgeSoftness * 2.0, distance);
+ float smoothedAlpha = 1.0 - smoothstep(-edgeSoftness, edgeSoftness, distance);
gl_FragColor.a *= smoothedAlpha;
gl_FragColor.rgb = applyDithering(gl_FragColor.rgb);
DALI_ASSERT_ALWAYS(object && "Not a valid RenderEffect set.");
Dali::Toolkit::Control ownerControl(GetOwner());
- object->Activate(ownerControl);
+ object->SetOwnerControl(ownerControl);
+ object->Activate();
}
}
if(object)
{
object->Deactivate();
+ object->ClearOwnerControl();
}
mImpl->mRenderEffect.Reset();
}
return BackgroundBlurEffect(internal.Get());
}
-BackgroundBlurEffect BackgroundBlurEffect::New(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth)
+BackgroundBlurEffect BackgroundBlurEffect::New(float downscaleFactor, uint32_t blurRadius)
{
- Internal::BlurEffectImplPtr internal = Internal::BlurEffectImpl::New(downscaleFactor, blurRadius, bellCurveWidth, true);
+ Internal::BlurEffectImplPtr internal = Internal::BlurEffectImpl::New(downscaleFactor, blurRadius, true);
return BackgroundBlurEffect(internal.Get());
}
-}// namespace Toolkit
-}// namespace Dali
+} // namespace Toolkit
+} // namespace Dali
*
* downscaleFactor = 0.4f
* pixelRadius = 5u
- * bellCurveWidth = 1.5f
*
* @SINCE_2_3.28
* @return A handle to a newly allocated Dali resource
* @brief Creates an initialized BackgroundBlurEffect.
* @param[in] downscaleFactor This value should reside in the range [0.0, 1.0].
* @param[in] blurRadius The radius of Gaussian kernel.
- * @param[in] bellCurveWidth Blur intensity.
* @SINCE_2_3.28
* @return A handle to a newly allocated Dali resource
*/
- static BackgroundBlurEffect New(float downscaleFactor, uint32_t blurRadius, float bellCurveWidth);
+ static BackgroundBlurEffect New(float downscaleFactor, uint32_t blurRadius);
/**
* @brief Creates an uninitialized blur effect.