Enable to use Premultiplied alpha for blur effect renderer 58/317158/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 5 Sep 2024 02:22:41 +0000 (11:22 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 6 Sep 2024 01:35:35 +0000 (10:35 +0900)
Change-Id: Iac2846697575fdfad2beb172f1478fe540be7b54
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/controls/render-effects/blur-effect-impl.cpp
dali-toolkit/internal/controls/render-effects/render-effect-impl.cpp
dali-toolkit/internal/graphics/shaders/render-effect.frag

index 191c4a31807e3a5e16851ff92ddbb9402ea38ae9..8060b50526df853938acf43abd97c0bf5726dc3b 100644 (file)
@@ -181,6 +181,7 @@ void BlurEffectImpl::OnInitialize()
   mHorizontalBlurActor = Actor::New();
   mHorizontalBlurActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   Renderer horizontalBlurRenderer = CreateRenderer(BASIC_VERTEX_SOURCE, fragmentSource.c_str());
+  horizontalBlurRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true); // Always use pre-multiply alpha
   mHorizontalBlurActor.AddRenderer(horizontalBlurRenderer);
   mInternalRoot.Add(mHorizontalBlurActor);
 
@@ -188,6 +189,7 @@ void BlurEffectImpl::OnInitialize()
   mVerticalBlurActor = Actor::New();
   mVerticalBlurActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   Renderer verticalBlurRenderer = CreateRenderer(BASIC_VERTEX_SOURCE, fragmentSource.c_str());
+  verticalBlurRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true); // Always use pre-multiply alpha
   mVerticalBlurActor.AddRenderer(verticalBlurRenderer);
   mInternalRoot.Add(mVerticalBlurActor);
 }
index 9bf82721f903161f267789889ec029b2ca08c8f7..c38048e01bc9dd3db399c7b31b1bfc62333ef0a8 100644 (file)
@@ -81,6 +81,7 @@ void RenderEffectImpl::SetOwnerControl(Dali::Toolkit::Control control)
       if(!mRenderer)
       {
         mRenderer = CreateRenderer(SHADER_RENDER_EFFECT_VERT, SHADER_RENDER_EFFECT_FRAG);
+        mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true); // Always use pre-multiply alpha
       }
 
       ownerControl.InheritedVisibilityChangedSignal().Connect(this, &RenderEffectImpl::OnControlInheritedVisibilityChanged);
index b8a06a86b899b83f4923507cf0bb56c93e7b3be3..b84ee1ff1c4632a966fbde3789b87d35730bf70c 100644 (file)
@@ -3,6 +3,7 @@ varying highp vec2 vTexCoord;
 varying highp vec2 vOptRectSize;
 varying highp vec4 vCornerRadius;
 
+uniform lowp vec4 uColor;
 uniform highp vec3 uSize;
 uniform sampler2D sTexture;
 
@@ -31,7 +32,7 @@ float roundedBoxSDF(vec2 PixelPositionFromCenter, vec2 RectangleEdgePositionFrom
 
 void main()
 {
-  gl_FragColor = texture2D(sTexture, vTexCoord);
+  gl_FragColor = texture2D(sTexture, vTexCoord) * uColor;
   gl_FragColor.rgb = applyDithering(gl_FragColor.rgb);
 
   highp vec2 location = (vTexCoord.xy - vec2(0.5)) * uSize.xy;
@@ -53,6 +54,8 @@ void main()
     float distance = roundedBoxSDF(location, uSize.xy * 0.5, radius);
 
     float smoothedAlpha = 1.0 - smoothstep(-edgeSoftness, edgeSoftness, distance);
-    gl_FragColor.a *= smoothedAlpha;
+
+    // Premultiply alpha feature used.
+    gl_FragColor *= smoothedAlpha;
   }
 }