Sign In

Navigation

On This Page

Archive

<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Categories

Blogroll

Contact

Send mail to the author(s) Email Me
MCPD
MCTS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way


Copyright ©  2010
 Creative Commons License
This work by Jeff Klawiter is, unless explicitly stated in the article,  available under the Creative Commons Attribution 3.0 United States License.

Pick a theme:
# Wednesday, March 18, 2009
by Jeff Klawiter - Wednesday, March 18, 2009 5:41:54 PM (Central Standard Time, UTC-06:00)
With the release of Silverlight 3 Beta we can now run PixelShader effects on any control. This can produce some powerful stuff as shown during the Mix 09 Keynote this morning. I delved in as fast as I could to find out how to make your own and work with them in VS.

I downloaded the WPF shader library from http://wpffx.codeplex.com/ . I only imported the ShaderEffectLibrary so far, I have not tried the transition one.

I simply copied the EffectFiles, ShaderSource and EffectLibrary.cs files into my project and tried to compile.  Issues I ran into
  1. UIPropertyMetadata needs to be replaced with PropertyMetadata
  2. Color.FromScRgb needs to be replaced with Color.FromArgb and it's inputs run through Convert.ToByte
  3. MagnifyEffect.cs and SwirlEffect.cs reference classes that do not exist in Silverlight like the Vector class. I could have got them from reflector but in sake of time I didn't (that and being able to release this code)
  4. Getting the ps resources required a minor change to the Global static class. Basically changing the path to do a Relative URI lookup.
The basics here for doing your own shader effects is included save 1 thing. You need the DirectX SDK to compile your HLSL code. You can add a new build event or do it from the commandline. This is a good tutorial on how to do it http://windowsclient.net/wpf/wpf35/wpf-35sp1-hlsl-primer.aspx.

So the basics of doing your own Pixel shader in Silverlight is damn near identical as WPF. You inherit from the ShaderEffect class, load your compiled HLSL bytecode resource and expose any properties you need to modify as dependency properties.

Attached is my ugly but working example. I couldn't find anyway to bind to properties on an effect so I had to just do it by event.

SlShaderEffectDemo.zip

Comments [2] #      HLSL | Silverlight 3  |  kick it on DotNetKicks.com Shout it
Wednesday, March 18, 2009 9:03:53 PM (Central Standard Time, UTC-06:00)
Where is the main RSS feed for this site? I'm just seeing the blog roll and the categories.
Wednesday, March 18, 2009 10:15:29 PM (Central Standard Time, UTC-06:00)
It's in the meta data. I guess I'm so used to having it in the URL bar in firefox I forgot to put an actual link in.

http://blog.j-maxx.net/SyndicationService.asmx/GetRss
Jeff Klawiter
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview