Wednesday, April 13, 2011

XNA for the Web - Silverlight 5

Many great new things were announced during the second keynote at Microsoft's MIX11 conference. One of it was the Silverlight 5 beta which is available for download here.
The new features are just awesome and many of them were requested by the community. As usual Tim Heuer's great blog post covers all the new goodies in detail and provides videos and source code for most of them. Kudos to the Silverlight team for releasing another great version.
My blog post contains a summary of all the new features the Silverlight 5 beta ships and provides some notes about the new 3D API. The next blog post will bring a new SLARToolkit 3D demo.

Features
  • XNA 3D Graphics API
  • Improved Graphics stack – The graphics stack has been re-architected to bring over improvements from WP7, such as Independent Animations.
  • Hardware video decode for H.264 playback.
  • Multi-core background JIT support for improved startup performance.
  • Realtime Sound (low-latency Audio)
  • Variable Speed Playback (“Trick Play”)
  • XAML Binding Debugging
  • Multiple Window Support
  • Ancestor RelativeSource Binding
  • Implicit DataTemplates
  • ClickCount
  • Binding on Style Setter
  • Linked Text Containers
  • Custom Markup Extensions
  • ComboBox type ahead with text searching.
  • Full keyboard support in full-screen for trusted in-browser applications, enables richer kiosk and media viewing applications in-browser.
  • Default filename in SaveFileDialog – Specify a default filename when you launch the SaveFileDialog.
  • Unrestricted filesystem access – trusted applications can Read write to files in any directory on the filesystem.
  • More performance optimizations:
  • XAML Parser performance optimizations.
  • Network Latency optimizations.
  • Text layout performance improvements.
  • Hardware acceleration is enabled in windowless mode with Internet Explorer 9.
Find more details at the Silverlight site and read John Papa's and Pete Brown's blog posts.


XNA for the Web
One of the topmost requested features at the Silverlight Uservoice site was hardware accelerated 3D graphics. The Silverlight team listened closely and added an immediate mode, low-level,  XNA 3D API to Silverlight 5. An immediate mode API offers functionality to render graphics directly to the graphics interface without keeping a list of the objects. A retained mode API like WPF 3D on the other hand keeps an internal list of the object graph. An immediate mode API is a great choice since it provides the maximum control over the rendering and mostly results in superior performance compared to retained mode rendering.
The Silverlight 5 3D API doesn't contain all the higher-level classes one might know from the XNA Game Studio. The Content Pipeline, the SpriteBatch class and others were left out. I assume this decision was made to keep the footprint of the Silverlight runtime small. However, the team added all the needed core functionality; features like the SpriteBatch can be build on top of it by the community. My Silverlight MVP friend Bill Reiss is already working on a SpriteBatch version for Silverlight 5.
The new GPU accelerated 3D API gives us Silverlight developers the core XNA functionality with shaders and vertex rendering inside the browser! Shaders aren't easy for most non-graphics programmers, but they give us a huge flexibility and we can build various higher levels on top of the new 3D API.
You can render some pretty impressive things with the new Silverlight 5 3D API and it's possible to draw millions of triangles on the GPU without almost no CPU load.

Here's a sneak peek at the new SLARToolkit demo which also contains a simple real-time glass effect.




Silverlight Integration
The 3D API contains a control called the DrawingSurface, which is basically a rendering surface or a 3D Canvas if you will. The DrawingSurface has the Draw event which is raised for every frame to draw. The event is fired on a render thread which runs in parallel to the UI thread. This is an important concept introduced with Silverlight 5.
Inside a Draw event handler the states and shaders are set and the vertex and index buffers are passed to the GPU for rendering. The vertex and pixel shaders implement the lightning model and define how the vertices are rendered. The current Silverlight 5 3D beta only supports Shader Model 2, but this will probably change in a future release, but even with Shader Model 2 many neat lightning models and effects can be implemented. You will find some nice effects in the new SLARToolkit demo.

Check out the Silverlight 5 3D samples if you want to learn more about the new 3D API. If you're not familiar with 3D graphics concepts or just want to make your life easier, then I strongly recommend to give the 3D engine Balder a try. It's a fantastic open source engine by my good Silverlight MVP friend Einar Ingebrigtsen. You just need to write a couple lines of XAML and you're good to go. Balder has built-in model loaders to load complex 3D models and Einar provides a big sample library. He also brought the engine to a few more platforms like Windows Phone 7, OpenGL and has even a neat software rendering fallback. Read his blog post here.
Another Silverlight MVP friend of mine, Andy Beaulieu made a very cool demo using Balder and a 3D physics engine. He blogged about it and even released the 3D physics engine as open source!

The beta of the 3D API is missing some essential things like RenderTargets at the moment, but it's just a beta and more stuff might be announced at the MIX11 conference. If you would like to know more details about the new Silverlight 5 3D API and the roadmap, then you should definitely check out the MIX11 session Graphics & 3D with Silverlight 5 by the Silverlight program manager Aaron Oneal on Wednesday, April 13 3:30 pm - 4:30 pm PDT. All MIX sessions are recorded and will be available online 24 hours after each session.

Conclusion
No, Silverlight is not dead and it's clear that Microsoft is investing in it. I'm sure the new features and esp. the XNA 3D API will lead to some great applications in the future. The future is bright and we are part of it.

9 comments:

  1. Thank you for this post. Do you know if all the new 3D stuff will also be available on the Mac ?

    ReplyDelete
  2. RE: Mac

    At Mix11, speaker said that 3D support was being considered and they knew it was important to many. So, not-committed.

    ReplyDelete
  3. I'm a complete newbie at this, but with Silverlight 5, is hardware acceleration active 'out of the bag'?
    i.e. will something like SkyPlayer run with hardware acceleration automatically?

    ReplyDelete
  4. Hey Paul,
    If the SkyPlayer uses H.264 encoded video, then yes. H.264 video playback is now accelerated by the graphics card.

    ReplyDelete
  5. Thanks Rene, quick response!

    Will I need to make any changes to the setup? Or download the program again?

    Sorry, like I said, very much a newbie!

    ReplyDelete
  6. You reach all the points...It's helpful to silverlight developers to make a game for both XNA and Silverlight.

    ReplyDelete
  7. Hi René,

    Just wondering what are your thoughts on using SL's XNA for high-performance 2D graphics?

    Also, will it be supported on MacOS as well?

    ReplyDelete
  8. Hi Andrew,

    As I wrote in the blog post my buddy Bill Reiss is working on SpriteBatch which is THE API for 2D grahpics. Follow the link above to get the details.

    The SL team plans to add Mac support to the RTW version. Watch the video of Aaron's session.

    ReplyDelete
  9. hi Rene Schulte, Could you please provide me the source code of this .... m doing my university project ..... I'll do every possible change...

    I hope you understand.

    Thanks.

    ReplyDelete