Pixel Shaders w/ Source (And a demo!)

In an earlier post, I showed some still images of Silverlight pixel shaders and how we used the awesome tool Shazzam in our development. Today I’d like to post the code and show some interesting uses of the shaders. (Live!)

Let’s start with the code for the Telescopic Blur effect. Here’s the relevant HLSL:

It takes 3 inputs. By altering the center of the zoom, you can do some fun stretching motions. As you’ll see in the demo below, it turned out to be a neat way to make text fly into view. You can also alter the amount of zoom blur. I’ll leave it up to the reader to play with this within Shazzam.

Its input is a timer value, so that it can be animated. If you compile this into a Silverlight effect, you can make the timer be a DependencyProperty, which allows the effect to be animated by Storyboard. I love XAML.

While this is a “passable” underwater effect (and I’m still working on a better one), I found an unanticipated use for it. But first, a digression.

A year or two ago, LucasArts re-released their classic game The Secret of Monkey Island for the XBox. I played this game extensively as a teenager, so of course I downloaded the new version and played through again, to see what they had done with the new capabilities of modern hardware. I wasn’t disappointed. While upgrading the look, they had stayed faithful to the design spirit of the original. And one of the most impressive effects was the Ghost Pirate LeChuck. He had a wavy, wispy quality. (As shown here.) It was fluid and animated and very impressive, and at the time I didn’t know how they did it.

Fast forward a year or two and we’re working on the underwater shader. On a whim, I applied it to a white square in front of a black background. Whoah. Now I knew. So we put together a quick ghost demo using the underwater effect and you can see it, along with the telescopic effect used as a transition, by clicking here.