Silverlight 5 RC–What’s new in the 3D world? - Eternal Coding - HTML5 / JavaScript / 3D development - Site Home - MSDN Blogs

Silverlight 5 RC–What’s new in the 3D world?


Silverlight 5 RC–What’s new in the 3D world?

  • Comments 14

Silverlight 5 RC is now available and you can grab it here.

If you want to know more about non 3D features, here are some interesting posts:

This release also introduces a lot of new features for XNA support in Silverlight 5:


The first thing you will note is the rename of the assemblies:

  • Microsoft.Xna.Framework.Silverlight became System.Windows.Xna.dll.
  • Audio moved from System.Windows.dll to Microsoft.Xna.Framework.dll


The device is no longer handled by the DrawEventArgs class. It is now available on GraphicsDeviceManager.Current.GraphicsDevice. So it is far easier to initialize your code because you don’t have to wait for the first draw to get the device:

  1. private void myDrawingSurface_Draw(object sender, DrawEventArgs e)
  2. {
  3.     // Render scene
  4.     scene.Draw();
  6.     // Let's go for another turn!
  7.     e.InvalidateSurface();
  8. }
  10. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  11. {
  12.     // Check if GPU is on
  13.     if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
  14.     {
  15.         MessageBox.Show("Please activate enableGPUAcceleration=true on your Silverlight plugin page.", "Warning", MessageBoxButton.OK);
  16.     }
  18.     // Create the scene
  19.     scene = new Scene(GraphicsDeviceManager.Current.GraphicsDevice);
  20. }

Effect classes

A new base class for effect was introduced. It has the same features as the Effect class in XNA.

Obviously the 5 children of this class are also supported:

So from now, you can write the following code:

  1. // Clearing screen
  2. GraphicsDeviceManager.Current.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color(0.2f, 0.2f, 0.2f, 1.0f), 1.0f, 0);
  4. basicEffect = new BasicEffect(GraphicsDeviceManager.Current.GraphicsDevice);
  5. basicEffect.EnableDefaultLighting();
  6. basicEffect.VertexColorEnabled = true;
  8. // Compute matrices
  9. Matrix world = Matrix.CreateRotationX(rotationAngle) * Matrix.CreateRotationY(rotationAngle);
  10. Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, -5.0f), Vector3.Zero, Vector3.UnitY);
  11. Matrix projection = Matrix.CreatePerspectiveFieldOfView(0.85f, aspectRatio, 0.01f, 1000.0f);
  13. // Affect parameters values
  14. basicEffect.World = world;
  15. basicEffect.View = view;
  16. basicEffect.Projection = projection;
  18. foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
  19. {
  20.     // Apply pass
  21.     pass.Apply();
  23.     // Drawing the cube
  24.     cube.Draw();
  25. }
  27. // Animate rotation
  28. rotationAngle += 0.05f;

Actually, this is really simple now to port a XNA 4.0 code to Silverlight 5.


Silverlight 5 RC now supports render target (2d as well as cube). So you can produce stellar effects such as mirrors, real-time environment maps, shadows, etc.

Like in XNA 4.0, you can easily create and affect a render target:

  1. RenderTarget2D renderTarget2D = new RenderTarget2D(GraphicsDeviceManager.Current.GraphicsDevice, 200, 200, false, SurfaceFormat.Color, DepthFormat.Depth24, 2, RenderTargetUsage.DiscardContents);
  3. GraphicsDeviceManager.Current.GraphicsDevice.SetRenderTarget(renderTarget2D);


You can activate multisample on render targets and on the main DrawingSurface. For the DrawingSurface, you must define it directly in the XAML code:

  1. <DrawingSurface Draw="OnDraw" x:Name="renderSurface">
  2.     <DrawingSurface.CompositionMode>
  3.         <OffscreenCompositionMode PreferredMultiSampleCount="2" />
  4.     </DrawingSurface.CompositionMode>
  5. </DrawingSurface>


You can note the soft edges on the roof for example.

Using the same Xaml tag (CompositionMode), you can also define the depth buffer and stencil buffer format.

  1. <DrawingSurface.CompositionMode>
  2.     <OffscreenCompositionMode PreferredMultiSampleCount="2" PreferredDepthStencilFormat="Depth24Stencil8" RenderTargetUsage="DiscardContents"/>
  3. </DrawingSurface.CompositionMode>

Math library

And last but not least, the Microsoft.Xna.Framework.Math is now included in the SDK! Vectors, Matrices and other painful mathematical concepts are now handled for you Sourire.


Finally Silverlight 5 offers a really well integrated XNA experience. You will be able to reuse directly a large part of your XNA 4.0 code. The only point which is missing is the support for the content pipeline….but…wait…. ^^

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
  • We're running into conflicts between SL 5 RC and Async CTP so be careful

    Error 9 The type 'System.Threading.Tasks.TaskCompletionSource<TResult>' exists in both 'C:\Program Files (x86)\Microsoft Visual Studio Async CTP\Samples\AsyncCtpLibrary_Silverlight.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\mscorlib.dll'

  • Merci d'avoir pris le temps de détailler les aspects 3D de SL5 RC:très utile et apprécié!

    Si j'osais, je poserai _la_ question à propos de SL5/3D: quid de son support sous MacOSX :-)?


  • Helas le Mac ne sera pas supporté par cette release

  • Merci pour cette précision.

    Si SL perd sa portabilité OSX je ne vois guère de raison de ne pas utiliser seulement WPF, qui offre une bonne intégration de DX9,

    entre autres avantages.

    Il se peut cependant que la conférence BUILD rende ces questions dépassées: il est plus que temps que MS clarifie une situation absurdement incertaine....

  • Thanks for the info on 3D for SL5 RC. I see in the blog a screenshot of the Babylon demo (right?). Is there an updated Babylon download compatible with the RC?

  • Hi Enrique,

    Yes a new version is incoming. I will upload it quickly!

  • No ShaderCompiler?

    What the heck you all done

  • Is the new version of Babylon supporting Silverlight 5 RC already available? where?

  • Not yet :) It will be available quickly :) Stay tuned!!

  • Dear  David Catuhe,I'm a silverlight devoleper in China. I want to kown when does Babylon can support Silverlight 5 RC, and I want to show a 3D case base on Babylon and Silverlight 5 RC in my new book. Waiting for your reply~

  • Do you have any information or guidance about whether it's possible to use pixel or vertex shaders to help speed up general-purpose mathematical operations?

  • You can have a look to Silverlight 5 Toolkit for support for .fx files. But as SL5 only supports shaders 2.0 it will be nearly impossible to do efficient GPGPU :(

  • Hi David, I have the Express versions of Visual Studio (Web Developer and C#). I have downloaded Silverlight and Xna. Now the Silverlight template projects appear only inside Web Developer and the Xna ones, appear only inside C#.

    Is it possible to build Xna for the web projects with the Express versions? If yes, could you give a brief guidance?

    Thank you

  • As Silverlight is installed under Web express, you need to install XNA for Web Express. I don't know if it will work but you can try to copy the project templates files of XNA from the Projecttemplates folder of C# express to Web Express projecttemplates

Page 1 of 1 (14 items)