Shady Pixels
In my previous post I mentioned the new Zune 3.0 visualizations. I really liked them, so I decided to try and create them using WPF’s new (3.5 SP1) Effects.
A while ago I wrote about BitmapEffects, and why you should try to avoid them. Effects replace BitmapEffect with an elegant, hardware-accelerated API. An Effect is comprised of a class that derives from ShaderEffect and another file written in HLSL (High Level Shader Language), which is a C derivative. What you’re basically writing is a function that receives the coordinates of a pixel and returns a color – a pixel shader. If you want to learn how to write one, I suggest checking out Greg Schechter’s series. You should also have a look at the WPF Effects Library, which has a host of ready to use effects, and also shows a great way of using effects to create transitions.
Now, for my Zune mimic. I created two effects: Blend (which blends one element with another) and PointLight (which colorizes an element and adds two light orbs). I also added a few animations to the demo app, which made it look more like Zune. The result is quite pleasant.
![]()
Although I’m quite satisfied with the API, there are a few things that aren’t so good:
- Debugging effects is not trivial.
- Using multi-input effects on a few UIElements is cumbersome. You have to use a VisualBrush. There should be a way to apply an effect like Blend by specifying the two (or more) elements it’s supposed to work on.
- You cannot apply an effect to the background of a Visual. What I mean is that creating an effect like Glass in Vista is impossible. If I apply a BlurEffect on a semi-transparent surface, only the contents of that surface will be blurred, and not what’s visible through it.
To compile the attached project, you will need the Shader Build Task and Templates, available at codeplex.com/wpf (WPF Futures release).
Attachment: PointLightDemo.zip
Tags
.NET 4 Animation AppFabric Async Axum Blog C# ClearType Cloud CLR CodeValue Contests Deep Zoom Experiments Generics Google Ink Lectures Modeling Performance Personal Pivot Prism Programming Languages Prolog Reflector RTL Sela Silverlight The Arbel Network Themes Threading Tips Visual Studio WCF Windows 7 Windows 2003 Windows Azure Windows Forms Windows Phone Windows Vista Windows XP WPF XAML ZuneArchives
- May 2013
- February 2013
- June 2012
- May 2012
- June 2011
- November 2010
- August 2010
- July 2010
- June 2010
- March 2010
- December 2009
- November 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- November 2007
- September 2007
- June 2007
- May 2007
- February 2007
- November 2006
- October 2006
- February 2006
- August 2005
- February 2005
- August 2004
- July 2004
- June 2004
- May 2004





