I'm working on maintaining a piece of legacy code that uses SharpDX for its graphical operations. Part of the code takes a saw-tooth pattern and blurs it to create a jagged-edge effect for torn paper. We were encountering an odd bug where there was a faint white line around the effect. Stepping through the code, I've found that apparently the blur operation is creating a small transparent border around the edges.
Here is the code used to define the blur Class:
public class DXEffectBlur : DXEffect
{
public DXEffectBlur(DXSurface Owner, DXImage Source0, float Sigma)
: base(Owner)
{
szPixels = Source0.SizePixels;
SharpDX.Direct2D1.Effects.GaussianBlur blur = new SharpDX.Direct2D1.Effects.GaussianBlur(surface.CurrentRender);
blur.StandardDeviation = Sigma;
blur.SetInput(0, Source0.Image, true);
blur.Optimization = GaussianBlurOptimization.Quality;
blur.BorderMode = BorderMode.Hard;
effect = blur;
}
}
The blur is invoked as blur in the following code chunk to write out the effect to the surface:
using (SurfaceSupport ss = new SurfaceSupport(surface, ReadSource, true))
using (DXEffectBlur blur = new DXEffectBlur(surface, ss.Image, Sigma))
using (DXEffectUnPremultiply unmul = new DXEffectUnPremultiply(surface, blur))
using (DXLayer layer = new DXLayer(surface, rc, null, false, ss.Mask, 1F))
{
surface.DrawImage(unmul, rc, 1F);
}
where rc is the rectangle that covers our surface and 1F is the opacity.
Is there a better way to specify the blur in SharpDX so that it doesn't make the edges semi-transparent? I'm going to keep poking at the code, but I've put a good hour into it today, and I'm unfamiliar with SharpDX, or even DirectX, so I'd be thankful for any pointers on where to look. I've already tried messing with the BorderMode, which defaults to Soft, but gets set to Hard in the blur, but Soft just makes for a wider border of transparency.
With the help of a co-worker, I found a workaround. Within the constructor, I added the following line:
Owner.InterpolationMode = DXInterpolationMode.Fast;
As can be seen above, "Owner" is the DXSurface for the effect. It gets assigned to the surface
member variable in DXResource
, an ancestor a few levels up the chain, so changing it here also changes the member variable.
Previously, the setting was HighQuality
. Using the Pixel
setting also works.