共用方式為


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

  • Anonymous
    May 14, 2008
    The comment has been removed

  • Anonymous
    May 14, 2008
    Awesome. Thanks so much for the sample solution as well!

  • Anonymous
    May 14, 2008
    Gopi...  are you sure you have the .NET 3.5 SP1 Beta installed?  (Links are available in the first posting from this series.)

  • Anonymous
    May 14, 2008
    oops no, i'm using Silverlight, which the Sp1 notes say not yet !!.. so.. will try after install.. Thanks, Gopi

  • Anonymous
    May 14, 2008
    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.

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

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

  • Anonymous
    May 26, 2008
    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

  • Anonymous
    June 02, 2008
    The comment has been removed

  • Anonymous
    September 16, 2008
    The comment has been removed