问题
i want to apply a shader to a bitmap (offline processing) with sharpdx. I found a sample on SharpDX homepage to apply an effect to an image with offline processing. Now i want to apply a shader.fx to it but i don't know how to do it. Can anyone help me out?
Here are the code snipset:
// Effect 1 : BitmapSource - take decoded image data and get a BitmapSource from it
var bitmapSourceEffect = new d2.Effects.BitmapSource(d2dContext);
bitmapSourceEffect.WicBitmapSource = formatConverter;
// Effect 2 : GaussianBlur - give the bitmapsource a gaussian blurred effect
var gaussianBlurEffect = new d2.Effects.GaussianBlur(d2dContext);
gaussianBlurEffect.SetInput(0, bitmapSourceEffect.Output, true);
gaussianBlurEffect.StandardDeviation = 5f;
d2dContext.BeginDraw();
d2dContext.DrawImage(gaussianBlurEffect);
d2dContext.EndDraw();
Here are the shader.fx
vec2 Warp(vec2 Tex)
{
vec2 newPos = Tex;
float c = -81.0/20.0;
float u = Tex.x * 2.0 - 1.0;
float v = Tex.y * 2.0 - 1.0;
newPos.x = c*u/((v*v) + c);
newPos.y = c*v/((u*u) + c);
newPos.x = (newPos.x + 1.0)*0.5;
newPos.y = (newPos.y + 1.0)*0.5;
return newPos;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
if (uv.x < 0.5)
{
uv.x = uv.x * 2.0;
fragColor = texture2D(iChannel0, Warp(uv));
}
else
{
uv.x = (uv.x - 0.5) * 2.0;
fragColor = texture2D(iChannel0, Warp(uv));
}
}
来源:https://stackoverflow.com/questions/31118593/how-to-apply-shader-to-an-bitmap-offline-with-sharpdx