<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Where did the time go? - Silverlight 3</title>
    <link>http://blog.j-maxx.net/</link>
    <description>Brain Powered</description>
    <language>en-us</language>
    <copyright>Jeff Klawiter</copyright>
    <lastBuildDate>Wed, 18 Mar 2009 23:41:54 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>Jeff.Klawiter@sierra-bravo.com</managingEditor>
    <webMaster>Jeff.Klawiter@sierra-bravo.com</webMaster>
    <item>
      <trackback:ping>http://blog.j-maxx.net/Trackback.aspx?guid=b5175d15-d866-4db3-baa1-2a969d4496b1</trackback:ping>
      <pingback:server>http://blog.j-maxx.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.j-maxx.net/PermaLink,guid,b5175d15-d866-4db3-baa1-2a969d4496b1.aspx</pingback:target>
      <dc:creator>Jeff Klawiter</dc:creator>
      <wfw:comment>http://blog.j-maxx.net/CommentView,guid,b5175d15-d866-4db3-baa1-2a969d4496b1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.j-maxx.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b5175d15-d866-4db3-baa1-2a969d4496b1</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">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.<br /><br />
I downloaded the WPF shader library from <a href="http://wpffx.codeplex.com/">http://wpffx.codeplex.com/</a> .
I only imported the ShaderEffectLibrary so far, I have not tried the transition one.<br /><br />
I simply copied the EffectFiles, ShaderSource and EffectLibrary.cs files into my project
and tried to compile.  Issues I ran into<br /><ol><li>
UIPropertyMetadata needs to be replaced with PropertyMetadata</li><li>
Color.FromScRgb needs to be replaced with Color.FromArgb and it's inputs run through
Convert.ToByte</li><li>
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)</li><li>
Getting the ps resources required a minor change to the Global static class. Basically
changing the path to do a Relative URI lookup.</li></ol>
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 <a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-hlsl-primer.aspx">http://windowsclient.net/wpf/wpf35/wpf-35sp1-hlsl-primer.aspx</a>. 
<br /><br />
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.<br /><br />
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.<br /><br /><a href="http://blog.j-maxx.net/content/binary/SlShaderEffectDemo.zip">SlShaderEffectDemo.zip</a><br /><p></p><img width="0" height="0" src="http://blog.j-maxx.net/aggbug.ashx?id=b5175d15-d866-4db3-baa1-2a969d4496b1" /></body>
      <title>Silverlight 3 Shader Effects</title>
      <guid isPermaLink="false">http://blog.j-maxx.net/PermaLink,guid,b5175d15-d866-4db3-baa1-2a969d4496b1.aspx</guid>
      <link>http://blog.j-maxx.net/2009/03/18/Silverlight3ShaderEffects.aspx</link>
      <pubDate>Wed, 18 Mar 2009 23:41:54 GMT</pubDate>
      <description>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.&lt;br&gt;
&lt;br&gt;
I downloaded the WPF shader library from &lt;a href="http://wpffx.codeplex.com/"&gt;http://wpffx.codeplex.com/&lt;/a&gt; .
I only imported the ShaderEffectLibrary so far, I have not tried the transition one.&lt;br&gt;
&lt;br&gt;
I simply copied the EffectFiles, ShaderSource and EffectLibrary.cs files into my project
and tried to compile.&amp;nbsp; Issues I ran into&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;
UIPropertyMetadata needs to be replaced with PropertyMetadata&lt;/li&gt;
&lt;li&gt;
Color.FromScRgb needs to be replaced with Color.FromArgb and it's inputs run through
Convert.ToByte&lt;/li&gt;
&lt;li&gt;
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)&lt;/li&gt;
&lt;li&gt;
Getting the ps resources required a minor change to the Global static class. Basically
changing the path to do a Relative URI lookup.&lt;/li&gt;
&lt;/ol&gt;
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 &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-hlsl-primer.aspx"&gt;http://windowsclient.net/wpf/wpf35/wpf-35sp1-hlsl-primer.aspx&lt;/a&gt;. 
&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://blog.j-maxx.net/content/binary/SlShaderEffectDemo.zip"&gt;SlShaderEffectDemo.zip&lt;/a&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.j-maxx.net/aggbug.ashx?id=b5175d15-d866-4db3-baa1-2a969d4496b1" /&gt;</description>
      <comments>http://blog.j-maxx.net/CommentView,guid,b5175d15-d866-4db3-baa1-2a969d4496b1.aspx</comments>
      <category>HLSL</category>
      <category>Silverlight 3</category>
    </item>
  </channel>
</rss>