Effects in .Net 3.5 SP1 for WPF

Have you heard? The guys at Redmond impressed the world once again! .Net 3.5 SP1 is now Beta…. If you didn’t already, I would suggest that you read this brilliant post from Tim Sneath to get more info on what’s new in WPF.

Today, I wanted to experiment a bit with the new Effects that were included in the SP1 Beta. These effects are the same as the BitmapEffects that were previously in WPF. One can also say that these are the replacement for the BitmapEffects. Why? Simple. BitmapEffect are slow, these are NOT! BitmapEffects are fully software rendered while the new Effects take advantage of the machine’s GPU. Well this is not exactly right there are instances where this does not apply…

  • When the graphics card being run on does not support PixelShader 2.0 or above. This is becoming more and more rare, but is definitely still out there.
  • When the WPF application is being remoted over Remote Desktop or Terminal Server or some other kind of mirror driver.
  • When the WPF application is in a mode where software rendering is required – such as rendering to a RenderTargetBitmap, or printing.
    (this was taken from this post, well copies and pasted if I might. How would I know such a thing after all :D )

Ok, so what can you do with these effects? something like this as starters….

Effects

In the sample application I used the DropShadowEffect and the BlurEffect, and then I combined the 2 together. One of the cool things with these effects is that the properties are Dependency properties i.e we can databind the properties values.

It is very easy to apply an effect to an element. All you have to do is to set the Effect property like so

<Button Content="Shadow" Width="100" Height="100">

    <Button.Effect>

        <DropShadowEffect Color="Red"

                          BlurRadius="50"

                          ShadowDepth="50"

                          Direction="30"

                          />

    </Button.Effect>

</Button>

One thing that is worth mentioning is that you cannot apply more than one effect to a UIElement. Yet we can workaround this by having a wrapper element(ex: Border) and set the other Effect on the wrapper element. Something like this

<Border Grid.Column="2" Grid.RowSpan="2" Width="100" Height="100">

    <Border.Effect>

        <BlurEffect Radius="10" />

    </Border.Effect>

    <Button Content="Both">

        <Button.Effect>

            <DropShadowEffect Color="Red"

                          BlurRadius="30"

                          ShadowDepth="30"

                          Direction="90"

                          />

        </Button.Effect>

    </Button>

</Border>

Cool stuff….

[Update]

Dr.WPF pointed out that WPF SP1 will upconvert the legacy BitmapEffects so that those effects run on the new accelerated pipeline. This will happen wherever possible. It will not happen if the effect is placed within a BitmapEffectGroup because the new pipeline supports only single effects.

For example, if a single BlurBitmapEffect has been applied to an element, SP1 will automatically use a BlurEffect on the element instead so that the blur is hardware accelerated (This upconversion will happen as long as the Radius value is between 0 and some acceptable value). Similarly, a single DropShadowBitmapEffect will be treated as a DropShadowEffect in SP1 whenever possible (This upconversion will happen as long as the Noise property is 0). Certain effects from the old pipeline will never be accelerated in the new pipeline. These include BevelBitmapEffect, OuterGlowBitmapEffect, and EmbossBitmapEffect.

Thanks Dr. We would be lost without you.

Download the Sample application I prepared and play around with these new cool features (Please note that you need .Net 3.5 SP1 installed on your machine)

I would suggest to read this series of posts to get to know effects better.

Have load of fun!

kick it on DotNetKicks.com

About these ads

4 thoughts on “Effects in .Net 3.5 SP1 for WPF

  1. Pingback: XBAPs Part 1: An introduction to this Jem « C# Disciples

  2. Pingback: XBAPs Part 1: An introduction to this Gem « C# Disciples

  3. Pingback: Playing with Shaders: Creating a water effect « C# Disciples

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s