Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Visual Studio BuildTask with Project and Item Templates

Republished from http://blogs.msdn.com/greg_schechter/archive/2008/08/11/a-visualstudio-buildtask-and-project-and-item-templates-for-writing-shadereffects.aspx

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 available for you to download, install, and use. We're distributing it as a CodePlex project under the Microsoft Public License. You can find it at the WPF Futures site. It includes a .zip file to install from and source code you can review or modify.

Presents' Editor note: You can also build your own Shader Effect step-by-step with the HLSL Shader Effect Lab that is also part of this series.

Once installed, you can edit .fx files and the corresponding C# ShaderEffect subclasses in VisualStudio. 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". It includes a README document with installation instructions.

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.

The install machine 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 the DirectX SDK is 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 its .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.

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.

The software here is provided as-is with no guarantees of updates, improvements, or fixes. You're welcomed to grab the code and modify it.

Comments: 0

You must Login to comment.

Featured Item

Page view counter