In a number of places in this series on Effects, I've alluded to a VisualStudio BuildTask and project templates that ease the authoring of shader-based Effects.  We now have one up and available for you to download, install, and use.  This was written by Gerhard Schneider and me.  (Gerhard is the development lead who's team is responsible for implementing the new GPU-based Effects, among other things.)  We're distributing it as a CodePlex project under the Microsoft Public License.  You can find it at the WPF Futures site, which is under the umbrella  At that site, you'll find both a .zip file to install from, and the source code that you can peruse/modify yourself if you need to.


Once you have this installed, you can edit .fx files and the the corresponding C# ShaderEffect subclasses all in VisualStudio, and just hit F5 or rebuild from VS to compile the whole project, including compiling the .fx file and inserting the bytecode as a resource into the resultant assembly.


The build task and project templates can be found in "Shader Effects BuildTask and", and in there you'll find a README that documents what you need to do to install.

Basically what the installer does is add a BuildTask assembly to the GAC.  This BuildTask gets run for "Effect" labeled project files, and basically runs the HLSL compiler on them, turning a .fx file into a .ps file containing the shader bytecode.  That .ps file is then included in the assembly as a resource, which will get loaded into a PixelShader object.

Note that the machine that this is installed on does not need to have the DirectX SDK installed.  In this case, it will use a statically linked shader compiler to compile the .fx file into bytecode.  If there is a DirectX SDK installed on the machine, it will try to use the latest one as the compiler.

The VS project template lets you create a new Effect Library, with the right build directive in it's .csproj file, and an initial Effect subclass and .fx file.  The VS item template lets you add in new Effect subclasses and .fx files to the Effect Library assembly you're building.

One thing to keep in mind:  the created C# project references a build task that runs trusted code.  This will cause a dialog like the following to pop up when you open a project.  You should expect this and click Yes (unless of course you think my code is going to reformat your hard drive :-) ):


Important Note: the software referenced here is provided as-is, with no guarantees of updates/improvements/fixes/etc.  You're more than welcome, of course, to grab the code and modify it to suit your purposes.