How to apply shader to an Bitmap offline with SharpDX

有些话、适合烂在心里 提交于 2019-12-11 11:43:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!