Creating custom shaders for WPF applications

Example approach

This creates a greyscale shader:

  1. Create a folder for your custom shaders
  2. Create a new class to interface the shader:
Make sure you change the UriSource to match your path.

3. Create two new text files: GrayscaleEffect.ps and GrayscaleEffect.fx

4. Open the fx file in notepad and SaveAs – choose ANSI as the format

5. Add hlsl code to GrayscaleEffect.fx:

6. Set GrayscaleEffect.ps to Resource in properties

7. You need to set up the build to compile the shader on project build. Ensure you have fxc.exe on your system. If not, download the Direct X SDK Here . Then, on the project compile>BuildEvents, put the following into Pre-build event:

Obviously changing your paths accordingly. That’s it – shader available to your app!

Example implementation:

About stigzler 48 Articles
Chief crook and wattle bosher.

Be the first to comment

Leave a Reply

Your email address will not be published.


*