0

I hope I do not make my first mistake with my first post.

I am writing a library for several graphical effects and filters (for example Sobel or Gauß mask). Because of the low Speed, doing this on the CPU, I wrote some shaders with the Shazzam tool.

My concret Problem is, that I am not able to use this shader in C#. In the Internet I found only advice how to apply a pixelshader as a effect in XAML directly to a element, which is not usable for my application, because this makes it impossible to apply several shaders on one Image, which is needed, for example the Canny Edge Detector.

To illustarte this issue a Little pseudo-code, which should Show, what I expect from the method.

PixelShader somePixelShader  = new PixelShader(pixelshader.ps);
somePixelShader.Input = Bitmap;
somePixelShader.Height = 200;
somePixelShader.Width = 800;

somePixelShader.Execute();
Bitmap = somePixelShader.Result;

As you see, everything should be done in C#.

Perhaps you can help me with my issue.

Simon Rühle
  • 229
  • 3
  • 12
  • 1
    what type of app are you building? WPF? SilverLight? XNA? I'm guessing it's either SL or WPF since you mention XAML, but there are still a lot of possibilities... – Josh E Jul 16 '12 at 19:43
  • I'm building a C# class library, but the only way to use Pixel shader I found was via WPF – Simon Rühle Jul 16 '12 at 21:34

2 Answers2

0

You can make a copy of the current effect output as a bitmap with RenderTargetBitmap, then submit this outputted image as the new input for the next effect, rinse, repeat.

Update : after a small (and inconclusive) test, this will not work : Can't render pixel shader to RenderTargetBitmap! Please help!

Community
  • 1
  • 1
aybe
  • 15,516
  • 9
  • 57
  • 105
  • Who can I apply the effect itself, the Basic way seems to me, that it could be a soulution, if I know who to apply the shader, I will test and answer as fast as possible – Simon Rühle Jul 16 '12 at 21:37
  • I did a test and it produced a blank image, please read my update above. – aybe Jul 18 '12 at 17:06
0

Check out these white papers for step-by-step instructions + examples on how to compile and use a pixel shader in WPF or SL.

You may also want to check out the WPF Pixel Shader Effects Library here.

Josh E
  • 7,390
  • 2
  • 32
  • 44