Using custom effects with pixel shaders
WPF 4 includes two special effect classes, BlurEffect
and DropShadowEffect
. These are built internally using pixel shaders, which are little programs that run on the graphics processing unit (GPU) as one of the final parts of rendering. These shaders originate from DirectX (WPF's lowest level rendering engine), so other effects can be used with the proper setup. Let's take a look at using a custom pixel shader to get special effects, otherwise very difficult or slow to achieve.
Getting ready
To compile shader files, you'll need the DirectX SDK, which can be downloaded from the DirectX portal at http://msdn.microsoft.com/en-US/directx. Click on Get the latest DirectX SDK, download the installer, and install the SDK.
How to do it...
We'll create a simple shader effect and make it available to WPF:
Create a new WPF application named
CH09.CustomEffect
.Add a folder to the project named
Effects
.Add a new text file to the newly created folder and name it
red.fx...