A simple Effect sample project and ClickOnce application


The previous post in this series began to talk about writing custom Effects for WPF.  We looked specifically at ColorComplementEffect, an effect with no parameters.  In upcoming posts, we’ll get into the details of multi-parameter effects and other specifics.  But in the meantime, I thought it would be useful to post a sample VS project and a ClickOnce application from that project for folks just itching to get going.


The app looks like this:


image


It’s nothing fancy, mostly XAML and, in fact, the way the code and structure and UI are constructed are not conducive to hosting all effects now and forever (a more sophisticated hoster of effects would make a lot more use of metadata and reflection to allow arbitrary effects to be applied and parameters to be tweaked).  However, this definitely does the job in terms of showing how Effects are used and written.  There are two projects in the solution — one is a MyEffects library, and the other just an EffectTest application that uses Effects from MyEffects.


Note that this code and app are specific to the .NET 3.5 SP1 Beta release.  We already know of at least one breaking change in the RTM version that will require this code to be modified (just slightly).


Without further ado:



One thing to be aware of in the solution.  The compiled pixel shaders are included as resources in the MyEffects library.  I did the fxc.exe compilation outside of the project system.  As mentioned in the last post, we have a VS BuildTask in the works that will let this be part of the project system, but until then, I included the compiled bytecode directly.


Have fun!  More to come…

SimpleEffects_SP1Beta.zip

Comments (10)

  1. Gopi says:

    In Vista, when i launch… >

    Could not load type ‘System.Windows.Media.Effects.ShaderEffect’ from assembly ‘PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.  Error in markup file ‘EffectTest;component/window1.xaml’ Line 1 Position 9.

  2. RobBurke says:

    Awesome. Thanks so much for the sample solution as well!

  3. Greg Schechter says:

    Gopi…  are you sure you have the .NET 3.5 SP1 Beta installed?  (Links are available in the first posting from this series.)

  4. Gopi says:

    oops no, i’m using Silverlight, which the Sp1 notes say not yet !!.. so.. will try after install..

    Thanks,

    Gopi

  5. RobBurke says:

    Hi Greg,

    Do we have to compile the shaders with ps_2_0 or can we possibly use ps_2_a or ps_2_b or above?  

    I am bumping up against the maximum number of instructions (64) in the pixel shader for ps_2_0, when trying to use a shader to convert rgb->hsv->rgb.

  6. Greg Schechterのブログ に、.NET Framework 3.5 SP1 の GPU ベースのカスタムエフェクトのサンプルが掲載されています。HLSLのコードとWPFへのその組み込み方は

  7. 先週書いた.NET Framework 3.5 SP1 の GPU ベースの カスタムエフェクトのサンプル をちょっといじるだけで、ModelVisual3DにもMediaElementにも同じエフェクトが適用できます。

  8. bp says:

    Are these effects supposed to be running on the GPU or the CPU?

    Using my old ATi 9500Pro CPU usage jumps when applying the effects. Is that simply because it’s a really old card?

    Cheers

  9. A hot new feature in 3.5 SP1 is GPU based effect. Greg Schechter has has a series of posts on this topic.

  10. GPU-based Effects are a hot new feature in WPF for .NET 3.5 SP1. I’m going to be blogging a series of