Freigeben über


A VisualStudio BuildTask and project and item templates for writing ShaderEffects

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 www.codeplex.com/wpf.  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 Templates.zip", 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 :-) ):

clip_image001

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.

Comments

  • Anonymous
    August 11, 2008
    PingBack from http://www.easycoded.com/a-visualstudio-buildtask-and-project-and-item-templates-for-writing-shadereffects

  • Anonymous
    August 11, 2008
    awsome :) i was thiiiis close to removing this blog from my live page due to lack of updates, but now its nailed on there for a while longer :)

  • Anonymous
    August 12, 2008
    Shader Effects BuildTask and Project Templates .NET Framework 3.5 SP1 では PixelShader 2.0 を用いてポストエフェクトがかけられるようになりましたが,ユーザ定義エフェクトの作成は少しややこしい準備が必要です.この作業を簡略化するカスタムビルドタスクとプロジ

  • Anonymous
    August 31, 2008
    Hi! great work Greg! now is quite easy to work with shaders on wpf with vs :D thanks a lot! can i ask you a question about shaders? im trying to make a multipass shader for a real motion blur in WPF. im doing this linking samplers2D between effects. but i bump into a class named ImplicitInputBrush which doesnt inherits of Brush! and there is not any information about it in the all msdn! or even google! when i try to get that brush to fill something. it's throw this exception 0x88980406. So my question is, is there any way to get that Brush as a Brush? thanks thanks thanks a lot!

  • Anonymous
    September 04, 2008
    Regarding ImplicitInput. This brush only works with the new shader effect API. If you apply an effect to an element, the texture for the rasterized element is set into sampler 0 by default. You can use the ImplicitInput brush to map the element texture to input sampler registers. Makes sense?

  • Anonymous
    September 15, 2008
    Thus far in this series on Effects , we've discussed building and using Effects that have a single "texture"

  • Anonymous
    September 16, 2008
    The comment has been removed

  • Anonymous
    September 27, 2008
    In my last post , I introduced multi-input effects, where you can send in arbitrary WPF brushes that