tags:

views:

604

answers:

1

Hey,

While experimenting with pixel shaders in WPF I decided to draw some pixels onto a fullscreen image through writeable bitmaps based on the MSDN sample
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx

I used a blur shader on the image. To have a continuous effect I took the image back from the shader and used it as input on the writeable bitmap.

        RenderTargetBitmap rtb = new RenderTargetBitmap((int)width, (int)height, 96, 96.0, PixelFormats.Pbgra32);
        rtb.Render(imgBackground);

        wb = new WriteableBitmap(rtb);
        imgBackground.Source = wb;

The above code is really slow. I need something to make it faster or some way to apply the pixel shader to the writeable bitmap backbuffer instead of the image.

Thx in advance. Stuck at this problem for some time now ..

+1  A: 

RenderTargetBitmap.Render(...) is always rendered in software on the UI thread, so your pixel shader is even being ran in software.

I am unsure what "effect" you are trying to achieve, but maybe you can just set the blur effect on the imgBackground (ie, imgBackground.Effect = new BlurEffect())

Jeremiah Morrill
Jeremiah, thanks for you reply.I 'm trying to use image generated by the shader as new input.So setting the effect in C# doesn't make a difference.I need to find a way to set the effect on the writeable bitmap.
Kris
Unfortunately WPF won't let you do this efficiently (as you've found out). Even if it did, pulling the surface from the GPU to system memory is also slow (not as slow as RTB though).You may have to get creative on other ways to get a similar effect. Maybe either by creating your own pixel shader, which may not be capable because limitations with WPF pixel shaders (ie, not supporting multiple passes) or a custom shader just isn't the right fit ;). Another option is to just write your own blur algorithm and do all the blur effect yourself on the WriteableBitmap.
Jeremiah Morrill
Thanks for clearing this out !I doesn't solve my problem but now I know which direction I have to search. thx
Kris